Using Rsync for Incremental Backups

I wrote a Rexx script that configures a Incremental backup set to a central backup server with 7 day increments. Actually, I set it for 30 days and have a script that deletes any older directories. If anyone is interested in the setup I'll post the directions and the Rexx script that I'm using.

An incremental backup preserves data by creating multiple copies that are based on the differences in those data: a successive copy of the data contains only that portion which has changed since the preceding copy has been created. [Wikipedia, 1]





Incremental

Since making a full copy of a large filesystem can be a time-consuming and expensive process, it is common to make full backups only once a week or once a month, and store only changes on the other days. These are called "incremental" backups, and are supported by the venerable old dump and tar utilities, along with many others.

However, you don't have to use tape as your backup medium; it is both possible and vastly more efficient to perform incremental backups with rsync.

The most basic form of incremental backup involves only those files that have changed since the last backup. Since changes are typically slow, incremental backup is much smaller and quicker than a full backup. For instance, following a full backup on Friday, a Monday backup will contain only those files that changed since Friday. A Tuesday backup will contains only those files that changed since Monday, and so on. A full restoration of data will naturally be slower, since all increments must be restored. Should any one of the copies created fail, including the first (full), restoration will be incomplete.[Wikipedia, 2]





The REXX scripts below have been adapted straight from the example on the Rsync website for use on OS/2 systems. If you're using Linux, then the direct example for Linux is on the Rsync homepage. I'm not a programmer, so I had to look up every word for the correct syntax. Any additional help would be great, please email me your setup or post examples below with the comment box.

I have an old computer acting as a file server for my movies and my BackAgain/2 system backup files. So, I decided to set it up as a Rsync server too. 


Rsync Server Setup

On the eComStation or OS/2 machine that will act as the server I have created a directory e:\backups\weekly

Download rsync from Paul Smedleys' site at http://smedley.info/os2ports/rsync.html and extract the file "rsync.exe" to the c:\MPTN\BIN\ directory -- make sure you have these \VAR\TEMP\ and \VAR\LOG directories.

In the c:\MPTN\ETC\ directory created a file called 'rsyncd.conf' containing the text:

max connections = 6
transfer logging = yes
read only = false
timeout=600

lock file = /var/temp/rsyncd.lock
log file = /var/log/rsyncd.log
pid file = /var/temp/rsyncd.pid
motd file = /mptn/etc/rsyncd.motd

[backups]
hosts allow = 192.168.2.101
comment = backup storage area
path = /backups/weekly
read only = false
list = yes
gid = root
uid = root


On the server side the rsync daemon is started simply with rsync --daemon via the startup.cmd file or startup folder. Now we can start up the rsync daemon process to test.

Open a command prompt and execute the following command:

rsync --daemon  --no-detach

To test that the daemon is up and running properly open another command prompt, and execute the command:

rsync localhost::

The response should look like this:

[C:\]rsync localhost::
backups              backup storage area

[C:\]

The server is ready to accept data.


Pushing the client data to the Rsync server

On the client side I already had a directory named e:\backups for BackAgain/2, so I copied the Rsync files and the script below to that directory. For my example here I'll run a backup of my e:\Data directories and push the data over the network to the rsync server by executing the script below from the e:\backups client directory.

Make sure to change the 'BackupDir' and 'Bserver' variables to fit your setup. And remove the pull Yes/No and pause statements if you want to run it unattended..


/*  rexx-program generating a backup to a central backup server with 7 day incremental, using rsync.exe  Author: Greggory D Shaw, USA, June 2011 */

/* The following entry is needed in rsyncd.conf on the rsync server:
  [backups]
        path = e:/backups/weekly
*/

say ""
say "This program creates a backup to a central backup server with 7 day increments. Continue? y/n"
say ""
pull YesNo
if \ ((YesNo = "Y") | (YesNo = "y") | (YesNo = "J") | (YesNo = "j")) then exit

Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
Call SysLoadFuncs

CurrentDir = directory()

/* directory to backup */
BackupDir = ' e:/Data '

/* optional bandwidth limitation add this to Opts below ' --bwlimit=8 ' */

/* excludes file - this contains a wildcard pattern per line of files to exclude
Excludes=$HOME/cron/excludes
*/

/* the name of the backup machine */
Bserver= 192.168.2.100

/* get the name of the day; use it for current backup directory */
BackupDate=Date('W')
BackupFile=Date('S')
ServerDir='backups/'

/* Options */
Opts = ' -v --progress --stats --xattrs --force --ignore-errors --delete-excluded --delete --backup --backup-dir=/'

/* now the actual transfer */

rsync || Opts || BackupDate || "/" || BackupFile || "/" || " -a" || BackupDir || Bserver ||"::" || ServerDir || "Current"

say "Successful backup of program objects"

"pause"
exit;


After running this, my server's E:\backups directory now contains the sub-directory 'weekly' with copies of my 'Data' directory.  Each time a backup is run, the changes are placed in a directory named in standard format, a sortable date format (yyyymmdd). Example: a backup on Monday => weekly\monday\20110614\data\ directory would be created.  The exact directory layout in shown in the picture below.




Now there isn't a way to delete directories with Rsync as far as I know with incremental backups, so I wrote a Rexx script to manage the backups on the server side. You can download them here, and make sure to unzip them only into the e:\backups\weekly directory. 

The DELBACKUPS.CMD is the only one that needs to be executed and it calls the other two rexx scripts (killtree and rxdates). Also, DELBACKUPS has a couple of variables that you may want to adjust.  It's set to keep incremental backups for the last 14 days and scan for older directories over the last 30 days. This is the first Rexx script that I wrote, so that's why things were done a certain way (me not knowing what I was doing).  So, if anyone wants to rewrite the three files into one, that's fine with me. 

Also, I'm looking for Cron/2 with networking support.  The version on Hobbes does not include the Networking version. It would be nice to have a rsync server automatically backup using Cron/2 -- please send me a copy if you have it.

Disclaimer and warning: the above works for me, but has had little testing.  And security should definitively be added on the server side - which I haven't had the time to look at yet.


References
Rsync homepage: examples:
http://rsync.samba.org/examples.html

Wikipedia.org home page:
http://en.wikipedia.org/wiki/Incremental_backup