Monday 19 November 2007

Incremental backup of a windows folder on a linux server

Here is a simple way of incrementally storing a backup of data on a windows machine to a linux server. This is inspired by the Time Machine on the Mac and the description on http://blog.interlinked.org/tutorials/rsync_time_machine.html of how to do the same on any *nix. The The small script uses a rsync port to windows called cwrsync. I have set up a ssh keypair to ease the operation.
Paste this into a .bat-file:

echo on
Set CURRENTDATE='%date%-%time%'
Set REMOTESERVER=server
Set REMOTEPATH=/home/user/rsyncbackup
Set LOCALPATH=/cygdrive/e/Documents
rsync -azP --delete --link-dest=%REMOTEPATH%/current %LOCALPATH% %REMOTESERVER%:%REMOTEPATH%/%CURRENTDATE%
ssh %REMOTESERVER% "rm %REMOTEPATH%/current && ln -s %CURRENTDATE% %REMOTEPATH%/current"
PAUSE

Change the REMOTEPATH and LOCALPATH to something that suits you. Once correctly set up you can remove the PAUSE and state "echo off" to silently run this at set intervals.