Automated local file backups using cwrsync (Windows)

So last night, one of my drives failed and I lost 3 hours worth of work. The drive itself is okay but the file table got corrupted. After a few attempts at fixing it, I decided to just reformat the thing. Granted, it had already showed signs of failing in the past and yet I simply chose to ignore it. This time around, I searched for a simple yet effective backup solution and stumbled on cwrsync. In this post, I will show you how to make automated backups of your files from one local hard drive to another.

Important note: Normally, my choice would be to backup files to a remote computer... but due to bandwidth issues, I am left with local backups between hard drives. It's better than nothing I suppose ;)

cwRsync

cwRsync is simply rsync for windows. Rsync uses the Rsync algorithm which provides a very fast method for bringing remote files into sync. In a nutshell, instead of overwriting existing files, it will simply copy over files which have changed.

Backing it up

  1. Download and install cwRsync. The free edition will suffice as we only need the cli tool rsync.exe.

  2. Add rsync.exe to our System PATH Environment variable. By default, rsync.exe should be located at C:\Program Files (x86)\cwRsync\bin. Reboot afterwards. System Environment variables

  3. Open cmd and and type in rsync.exe to check if our system finds it. rsync cmd

  4. In my case, I needed to backup D:\Projects to G:\Backup. The complete command for this is: rsync cmd projects

    rsync -aHzv --chmod=ugo=rwX /cygdrive/d/Projects/ /cygdrive/g/Backup

    Quick Explanation:

    -a archive mode
    -H preserve hard-links
    -z compress
    --chmod=ugo=rwX add apropriate permissions

    Note: cwrsync does not support the regular windows drive notation D:\ or G:\ be sure to use the equivalent /cygdrive/d/--path-- or /cygdrive/g/--path--

Scheduling

The whole thing won't be called automated unless we have to open the command-line everytime we want to backup our files. In order to automate, we'll simply use good ol' Windows Task Scheduler:

  1. Open up your text editor and type in (replace the rsync command as needed):

    @echo off
    rsync -aHzv --chmod=ugo=rwX /cygdrive/d/Projects/ /cygdrive/g/Backup

  2. Save the file somewhere as rsyncBackup.bat. Remember this location.

  3. Open up Start > Administrative Tools > Task Scheduler. On Windows 8, press Windows Key + W and search for it there.Windows Task Scheduler Location

  4. Create a New Task and schedule rsyncBackup.bat execution accordingly: General Settings Actions Triggers

    Tip: Try to schedule it at a time when your computer is idle.

...and there you have it!

Bonus: rysnc has a feature which allows you to make incremental backups of your files. Should you need this, you may read about it in the docs. Keyword option is --backup.