Thursday, March 23, 2006

Incremental Backup Using Rsync

In one of my previous post have written about DR Plans, Further to that I am Just
adding the Incremental Backup using Rsync.

In a nutshell heres the overview of the scenario :

1) We have a bunch of users on a Mail Server, called mail1,which runs Red Hat Enterprise 3.
we need to backup the daily mails of users stored in /var/qmail/users/

2) We have a second linux machine, backup, with good IP connectivity to mail1.

Backups are desired every day during the night when the load is low.

The backups should be incremental - minimising storage requirements by only keeping 'diffs' from one backup to the next.

Rsync executed in mail1 as follows :

/usr/local/bin/rsync -a --update --delete /var/qmail/users/ backup:/backups/home.0

This causes /backups/home.0 on backup to be updated to reflect the set of directories and files under /var/qmail/users/ on mail1. The update process will recurse down each branch of the directory tree under /var/qmail/users/ on mail1and:
  • delete entries under backup:/backups/home.0 that no longer exist under mail1:/var//qmail/users/
  • add entries to backup:/backups/home.0 that have appeared under mail1:/var/qmail/users/
  • update entries in backup:/backups/home.0 that have changed under mail1:/var/qmail/users
(The source directory is specified as "/var/qmail/users/" with a trailing slash to ensure rsync synchronises the sub-directories of /var/qmail/users/, rather than /var/qmail/users itself. If the trailing slash had been omitted rsync would create /backups/home.0/var/qmail/users/gja rather than /backups/home.0/gja, etc... on backup.)

Note : Rysnc needs root permission to execute the above command.

add the rsync command to cron jobs

#crontab -e

15 3 * * * root /bin/csh /root/bin/ daily

In have added the rync line that I have mentioned above.

The above command will be excuted a 03:15 am in the night.

Since storing your backup on a Network server its advisable to have a SSH-keygen so that it does not ask for a password while backing up.

Look here for password less logins.

No comments: