Friday, March 13, 2009

Incremental Backup with rsync

There are few reasons I don't want to use dd for full backup:
- My HD is having 250GB data and I don't want to do daily backup for it
- My data do not change so frequently
- I don't want to burden my server with 250GB of daily thrashing just for backup only

To do incremental backup, we can make use of rsync:
rsync -azvr /mnt/localbind root@mystorages:/mybackup/

To simplify the life, just use single partition for each physical disks, and bind them in the fstab.

#!/bin/bash

TIMESTAMP=`date +%Y%m%d_%H%M%S`

mount -o bind,ro / /mnt/localbind
mount -o remount,rw /backup/mainbackup

nice -n 19 rsync -azvrb --suffix=.rsync_$TIMESTAMP /mnt/localbind/ /backup/mainbackup/
echo "Backup performed on $TIMESTAMP" >>/backup/backup.log
sync

umount /mnt/localbind
mount -o remount,ro /backup/mainbackup