#!/bin/bash # # Rsync everything except a few system directories and the backup directory # itself. This is designed to be linked into the cron.daily directory # to run automatically every night. # # Backup files being replaced to a unique new backup directory for this # date. # # Log the output # exec > /var/log/backup.log 2>&1 # set -x # # Make PATH safe # PATH="/bin:/usr/bin:/sbin:/usr/sbin" cd / export PATH # df # EX="/root/cronscripts/rsync-exclude" # # Make sure the backup directories exist and create new backup dir for this # date for any files replaced in latest to be moved into (a separate job can # remove old ones when we start to fill the backup disk). # if [ ! -d /backup/zooty ] then mount LABEL=BACKUP /backup fi if [ ! -d /backup/zooty ] then echo Cannot seem to mount the backup drive, quitting exit 2 fi LATEST=/backup/zooty/latest PREV=/backup/zooty/cb-`date -u +%Y-%m-%d-%H-%M-%S` [ -d $PREV ] || mkdir -p $PREV [ -d $LATEST ] || mkdir -p $LATEST # # Let's do the backup now, getting a list of exclusions from the # rsync-exclude perl script which builds the list dynamically # $EX | /usr/bin/time rsync -v --exclude-from=- -a -S --no-D --delete --delete-excluded -b --backup-dir=$PREV / $LATEST # # My truecrypt secure image file doesn't get its timestamp changed by # truecrypt. Back it up into the same tree structure as the previous rsync, # but based on checksum not timestamp (so we really make a backup when # it has changed). # /usr/bin/time rsync -v -a -c -S --no-D --delete -b --backup-dir=$PREV/zooty /zooty/secure.tc $LATEST/zooty/secure.tc # df sync umount /backup