... | ... |
@@ -1,58 +1,77 @@ |
1 | 1 |
#!/bin/bash |
2 | 2 |
|
3 |
-mountpoint=/backup |
|
3 |
+cat > /dev/shm/rotate_inject << EOC |
|
4 |
+/var/log/${0##*/} { |
|
5 |
+ rotate 31 |
|
6 |
+ compress |
|
7 |
+ missingok |
|
8 |
+} |
|
9 |
+EOC |
|
10 |
+logrotate -fs /dev/shm/rotate_inject.state /dev/shm/rotate_inject |
|
11 |
+rm -f /dev/shm/rotate_inject /dev/shm/rotate_inject.state |
|
4 | 12 |
|
5 |
-alreadymounted=1 |
|
6 |
-badmodload=2 |
|
7 |
-notmounted=3 |
|
8 |
-umountfailure=4 |
|
9 |
-unloadfailure=5 |
|
13 |
+set -e |
|
10 | 14 |
|
11 |
-owncloudpath=/var/www/owncloud |
|
12 |
-datapath=$owncloudpath/data |
|
13 |
-configpath=$owncloudpath/config |
|
14 |
-dbname=owncloud |
|
15 |
+mountpoint=${1:-/media/backup} |
|
16 |
+backupdir=$mountpoint/backup |
|
17 |
+archives=$mountpoint/archives |
|
18 |
+incremental=30 |
|
15 | 19 |
|
16 | 20 |
PATH=/usr/sbin:/usr/bin:/sbin:/bin |
17 | 21 |
|
18 |
-test -d $mountpoint || mkdir $mountpoint |
|
22 |
+test -d $mountpoint/ |
|
23 |
+grep -qw $mountpoint /proc/mounts |
|
19 | 24 |
|
20 |
-if grep -q $mountpoint /proc/mounts; then |
|
21 |
- echo "$mountpoint déjà monté, arrêt" |
|
22 |
- exit $alreadymounted |
|
23 |
-fi |
|
25 |
+test -d $archives || mkdir -p $archives |
|
24 | 26 |
|
25 |
-if ! test -d /sys/module/vboxsf; then |
|
26 |
- if ! modprobe vboxsf; then |
|
27 |
- echo "module vboxsf non chargé correctement, abandon" |
|
28 |
- exit $badmodload |
|
27 |
+for i in $(seq $incremental -1 1); do |
|
28 |
+ if test -e $archives/${backupdir##*/}.$i; then |
|
29 |
+ mv $archives/${backupdir##*/}.$i $archives/${backupdir##*/}.$((i+1)) |
|
29 | 30 |
fi |
30 |
-fi |
|
31 |
+done |
|
31 | 32 |
|
32 |
-if ! mount -t vboxsf -o uid=www-data,gid=www-data backup $mountpoint; then |
|
33 |
- echo "impossible de monter $mountpoint" |
|
34 |
- exit $notmounted |
|
33 |
+rsync_opt=('-rlvzx' '--times' '--delete' '--omit-link-times') |
|
34 |
+if test -d $backupdir; then |
|
35 |
+ mv $backupdir $archives/${backupdir##*/}.1 |
|
36 |
+# if test $(date +%u) -ne 1; then # real copy every monday |
|
37 |
+ rsync_opt+=("--link-dest=$archives/${backupdir##*/}.1") |
|
38 |
+# fi |
|
35 | 39 |
fi |
36 | 40 |
|
37 |
-rsync -Avax $configpath $mountpoint/ > /var/log/${0##*/} 2>&1 |
|
38 |
-rsync -Avax --exclude="/etc/ssh/ssh_host_*" /etc $mountpoint/ >> /var/log/${0##*/} 2>&1 |
|
39 |
-rsync -Avax --exclude=lost+found --exclude="data/owncloud.log*" $datapath $mountpoint/ >> /var/log/${0##*/} 2>&1 |
|
40 |
-mysqldump -u owncloud_usr --password=$(awk -F"'" '/dbpassword/{print $4}' $configpath/config.php) $dbname > $mountpoint/${dbname}.db |
|
41 |
-mysqldump -u sms --password=$(< /home/sms/secret.sms) sms > $mountpoint/sms.db |
|
42 |
-mysqldump -u prosody --password=$(< /home/sms/secret.prosody) prosody > $mountpoint/prosody.db |
|
43 |
-cp -f /home/sms/bot /root/inject $mountpoint |
|
41 |
+rm -fr $archives/${backupdir##*/}.$((incremental+1)) |
|
44 | 42 |
|
45 |
-touch $mountpoint/step1 |
|
43 |
+filelist=$(mktemp --dry-run /dev/shm/XXXXXXXX) |
|
44 |
+cat > $filelist << EOL |
|
45 |
+/home/sms/bot |
|
46 |
+/home/sms/bot.conf |
|
47 |
+/home/sms/missed-calls |
|
48 |
+/home/sms/missed-calls.conf |
|
49 |
+/home/imapfilter/.imapfilter/config.lua |
|
50 |
+/home/imapfilter/authorized.lua |
|
51 |
+/home/imapfilter/contact@paris12.pcf.fr.lua |
|
52 |
+/home/imapfilter/printscript.model |
|
53 |
+/home/synapse/homeserver.yaml |
|
54 |
+/root/inject |
|
55 |
+/root/iptables.rules |
|
56 |
+/root/iptables.norules |
|
57 |
+/var/www/grav/user/themes/pcf-12 |
|
58 |
+/var/www/nextcloud/config/config.php |
|
59 |
+EOL |
|
60 |
+rsync ${rsync_opt[@]} --files-from=$filelist / $backupdir/ >> /var/log/${0##*/} 2>&1 |
|
61 |
+rm $filelist |
|
46 | 62 |
|
47 |
-if ! umount $mountpoint; then |
|
48 |
- echo "impossible de démonter $mountpoint:" |
|
49 |
- lsof $mountpoint |
|
50 |
- exit $umountfailure |
|
51 |
-fi |
|
63 |
+rsync ${rsync_opt[@]} --exclude="/etc/ssh/ssh_host_*" /etc $backupdir/ >> /var/log/${0##*/} 2>&1 |
|
52 | 64 |
|
53 |
-if ! modprobe -r vboxsf; then |
|
54 |
- echo "échec du déchargement du module vboxsf" |
|
55 |
- exit $unloadfailure |
|
56 |
-fi |
|
65 |
+rsync ${rsync_opt[@]} --exclude="plugins" --exclude="themes" /var/www/grav/user $backupdir/var/www/grav/ >> /var/log/${0##*/} 2>&1 |
|
66 |
+ |
|
67 |
+mkdir -p $backupdir/databases |
|
68 |
+ |
|
69 |
+mysqldump -u owncloud_usr --password=$(awk -F"'" '/dbpassword/{print $4}' /var/www/nextcloud/config/config.php) --skip-comments owncloud > $backupdir/databases/owncloud.db |
|
70 |
+ |
|
71 |
+mysqldump -u sms --password=$(< /home/sms/secret.sms) --skip-comments sms > $backupdir/databases/sms.db |
|
72 |
+ |
|
73 |
+#echo -en ".output $backupdir/databases/synapse.db\n.dump\n.quit\n" | sqlite3 /home/synapse/homeserver.db |
|
74 |
+ |
|
75 |
+#echo -en ".output $backupdir/databases/synapse.schema\n.schema\n.quit\n" | sqlite3 /home/synapse/homeserver.db |
|
57 | 76 |
|
58 | 77 |
exit 0 |