How to regularly backup Windows XP to Ubuntu, using rsync

Back in September I revived my Mini-ITX box to serve as a backup server. I set up BackupPC, ran it once, it seemed to work, and then ignored it for weeks. When I checked back, it hadn’t run successfully since. Ugh, I want backups to just work!

A few nights ago I decided to try again, this time dropping the constraint of not installing software on my laptop. Turns out I already had the building block I needed: rsync, installed in the form of Cygwin.

I began with these Rsync for Windows instructions, and everything went smoothly until the very end—rsync on Windows wasn’t connecting to rsync on Ubuntu. My gut told me rsync’s port 873 isn’t open on Ubuntu, but I had no idea how to open ports anymore. Luckily I found How to start rsync daemon at boot in the Ubuntu forums which told me exactly what I needed to know.

Partly as an aide to my memory, and partly to help anyone out there who might be struggling with the same project (unless everyone except me is already backing up their computers) I decided to summarize the process without all the false starts and dead ends it took me to figure it all out. For more information, the rsync man page is useful, as well as the results in Google for windows rsync.

Set up rsync server on Ubuntu

  1. Run sudo apt-get install rsync (it’s probably already installed)
  2. Create a file named rsyncd.conf in /etc
    1. sudo nano /etc/rsyncd.conf
    2. Add the following to rsyncd.conf, replacing all instances of username with your Ubuntu username:
          path = /home/username/backup           
          comment = Backup                                      
          uid = username
          gid = username
          read only = false
          auth users = username
          secrets file = /etc/rsyncd.secrets
    3. sudo chmod 644 /etc/rsyncd.conf
  3. Create a file named rsyncd.secrets in /etc
    1. sudo nano /etc/rsyncd.secrets
    2. Add the following to rsyncd.secrets, replacing username with your username and password with a password of your choosing:
    3. sudo chmod 600 /etc/rsyncd.secrets
  4. Open rsync port by editing /etc/default/rsync and setting
  5. Restart rsync
    sudo /etc/init.d/rsync restart

Set up rsync client on Windows

  1. Install Cygwin, making sure Editors > nano and Net > rsync are selected
  2. Add C:\cygwin\bin; to the Windows PATH statement
    1. Right-click on My Computer and select Properties
    2. Switch to the Advanced tab and click the Environment Variables button at the bottom
    3. Find the “Path” or “PATH” variable in the System variables list at the bottom and click Edit
    4. Add C:\cygwin\bin; to the beginning of the list
  3. Create secret file to store password in Cygwin
    1. Start Cygwin Bash Shell
    2. Create secret file in the filesystem root and enter only the password in rsyncd.secrets above, with no spaces or line breaks
      nano /secret
    3. chmod 600 /secret
    4. chown Administrator:SYSTEM /secret
  4. Create bat file to run rsync
    1. Open Notepad and enter the following command, replacing User Name with your Windows User Name directory, username with your Ubuntu username, and ipaddress with the IP address of your Ubuntu server (e.g.
      C:\cygwin\bin\rsync.exe -qrtz --password-file=c:\cygwin\secret --delete "/cygdrive/c/Documents and Settings/User Name" username@ipaddress::usernamebackup

      As you may have guessed, the "/cygdrive/c/Documents and Settings/User Name" command line option designates where to start backing up from. As currently configured, this will backup your Windows home directory (Desktop, My Documents, etc). If you want to backup your whole hard drive, change that option to "/cygdrive/c".

    2. Save the file as C:\rsync.bat

Create scheduled task to run C:\rsync.bat once a day

  1. Create scheduled task
    1. Goto Start > Programs > Accessories > System Tools > Scheduled Tasks
    2. From the File menu, select New > Scheduled Task
    3. Name this task “rsync backup”
    4. Right-click on the task and select properties
    5. Enter C:\rsync.bat in the Run field
    6. Switch to the Schedule tab and select the time you want the backup to run every day and click Ok
  2. Test the scheduled task
    1. Create a folder called C:\data and put a few photo files in it
    2. Edit C:\rsync.bat and change "/cygdrive/c/Documents and Settings/User Name" to "/cygdrive/c/data"
    3. Add the command pause on a new line at the bottom of C:\rsync.bat and save the file
    4. Right-click on the “rsync backup” scheduled task and select “Run”—A command window should popup and with either errors or the list of files being transfered. If there are errors, troubleshoot them.
    5. Once the scheduled task and C:\rsync.bat appear to be working correctly, change "/cygdrive/c/data" back to "/cygdrive/c/Documents and Settings/User Name" and remove the pause command
    6. Finally, edit the scheduled task properties and change “Run as:” to NT AUTHORITY\SYSTEM—this will ensure that the process runs in the background, without popping up a command prompt window

Run your first backup

Run C:\rsync.bat from the command line before going to bed. Backing up 35GB over a wireless-g connection took me over 8 hours. Subsequent backups take less than a minute. Behold the beauty of rsync.

Update: for information on how to backup Ubuntu to Ubuntu (or Linux to Linux really) using rsync with passphraseless keys, check out Playing with rsync on Ubuntu. For information on backing up Ubuntu to an external hard drive, check out How to rsync your Ubuntu home directory to an external hard drive.

Feel free to if you found this useful.