-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.sh
47 lines (43 loc) · 1.18 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Dumb script that copies /etc/<appname> from this list of applications to a backup directory,
# and then compresses that directory into ignore.trash
appnames=("apache" "mysql" "httpd" "lighttpd" "nginx")
backupdir="backups.d"
mkdir $backupdir
chown root:root $backupdir
chmod 700 $backupdir
echo "writing backups to $backupdir"
for app in "${appnames[@]}"; do
echo "Checking for $app"
# Handle any special cases for directories you want beyond here.
# Otherwise, this script will just copy /etc/<appname> to the backup directory if it exists.
case $app in
"apache")
if [ -d /etc/apache ]; then
echo "Apache found. Copying over /var/www additionally"
if [-d /var/www]; then
cp -r /var/www $backupdir/
fi
cp -r /etc/$app $backupdir/
fi
;;
"mysql")
if [ -d /etc/mysql ]; then
echo "MySQL found. Copying /var/lib/mysql additionally."
if [-d /var/lib/mysql ]; then
cp -r /var/lib/mysql $backupdir
fi
cp -r /etc/$app $backupdir/
fi
;;
*)
if [ -d /etc/$app ]; then
echo "$app" found.
cp -r /etc/$app $backupdir/
fi
;;
esac
done;
tar -cf ignore.trash $backupdir
chown root:root ignore.trash
chmod 700 ignore.trash