Wednesday, May 16, 2012

Incremental backup using RSYNC

This backup script was done in one of our machines where an external usb hard drive is attached locally. My former officemate Ian Dexter helped me get this script done, many thanks to him. So without further adieu:
Open up your favorite editor, I used vi for this.
BAKDIR=`date +%A`
OPTS="-av --force --ignore-errors --delete --backup --backup-dir=$BAKHOME/$BAKDIR"
# Start
 date > $LOGDIR/backup.$BAKDIR.log
# Cleanup
 [ -d $TMPDIR ] || mkdir $TMPDIR
 rm -rf $TMPDIR
# Backup
 $RSYNC $OPTS $SRCDIR $BAKHOME/current >> $LOGDIR/backup.$BAKDIR.log
exit 0
# Save the file as or whatever name you prefer.

Now edit root’s crontab and run this script daily, choose an off-peak hour for this.
You now have a backup copy of all the files/directories under the /home from Monday to Sunday.

No comments:

Post a Comment