#!/bin/bash cat > /dev/shm/rotate_inject << EOC /var/log/${0##*/} { rotate 31 compress missingok } EOC logrotate -fs /dev/shm/rotate_inject.state /dev/shm/rotate_inject rm -f /dev/shm/rotate_inject /dev/shm/rotate_inject.state set -e mountpoint=${1:-/media/backup} backupdir=$mountpoint/backup archives=$mountpoint/archives incremental=30 PATH=/usr/sbin:/usr/bin:/sbin:/bin test -d $mountpoint/ grep -qw $mountpoint /proc/mounts test -d $archives || mkdir -p $archives for i in $(seq $incremental -1 1); do if test -e $archives/${backupdir##*/}.$i; then mv $archives/${backupdir##*/}.$i $archives/${backupdir##*/}.$((i+1)) fi done rsync_opt=('-rlvzx' '--times' '--delete' '--omit-link-times') if test -d $backupdir; then mv $backupdir $archives/${backupdir##*/}.1 # if test $(date +%u) -ne 1; then # real copy every monday rsync_opt+=("--link-dest=$archives/${backupdir##*/}.1") # fi fi rm -fr $archives/${backupdir##*/}.$((incremental+1)) filelist=$(mktemp --dry-run /dev/shm/XXXXXXXX) cat > $filelist << EOL /home/sms/bot /home/sms/bot.conf /home/sms/missed-calls /home/sms/missed-calls.conf /home/imapfilter/.imapfilter/config.lua /home/imapfilter/authorized.lua /home/imapfilter/contact@paris12.pcf.fr.lua /home/imapfilter/printscript.model /home/synapse/homeserver.yaml /root/inject /root/iptables.rules /root/iptables.norules /var/www/grav/user/themes/pcf-12 /var/www/nextcloud/config/config.php EOL rsync ${rsync_opt[@]} --files-from=$filelist / $backupdir/ >> /var/log/${0##*/} 2>&1 rm $filelist rsync ${rsync_opt[@]} --exclude="/etc/ssh/ssh_host_*" /etc $backupdir/ >> /var/log/${0##*/} 2>&1 rsync ${rsync_opt[@]} --exclude="plugins" --exclude="themes" /var/www/grav/user $backupdir/var/www/grav/ >> /var/log/${0##*/} 2>&1 mkdir -p $backupdir/databases mysqldump -u owncloud_usr --password=$(awk -F"'" '/dbpassword/{print $4}' /var/www/nextcloud/config/config.php) --skip-comments owncloud > $backupdir/databases/owncloud.db mysqldump -u sms --password=$(< /home/sms/secret.sms) --skip-comments sms > $backupdir/databases/sms.db #echo -en ".output $backupdir/databases/synapse.db\n.dump\n.quit\n" | sqlite3 /home/synapse/homeserver.db #echo -en ".output $backupdir/databases/synapse.schema\n.schema\n.quit\n" | sqlite3 /home/synapse/homeserver.db exit 0