How to regularly backup Windows XP to Ubuntu, using rsync

February 21, 2008 | By: UbuntuLinuxHelp | 3 Comments
Posted in How to..., Installation

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

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:
      [usernamebackup]
      
          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:
      username:password
    3. sudo chmod 600 /etc/rsyncd.secrets
  4. Open rsync port by editing /etc/default/rsync and setting
    RSYNC_ENABLE=true
  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. 192.168.0.100):
      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.

This post is licensed under a Creative Commons Attribution 2.5 License.

If you like this post, why not share it?
  • StumbleUpon
  • del.icio.us
  • Digg
  • Google Bookmarks
  • Reddit
  • Mixx
  • Yahoo! Bookmarks
  • blogmarks
  • Twitter

Related posts:

  1. How to Regularly Backup Ubuntu Using rsync
  2. Automate Your Web Site Backup!
  3. Automatic FTP Backup System – A Very Simple Solution
  4. Windows User? Do You Wubi?
  5. How to install Ubuntu Studio in Windows using VirtualBox – A Complete Walkthrough


Comments

3 Comments so far

  1. bish bish on May 13, 2009 2:21 am

    As always, the only good backup is the one you can restore. What’s your experience been when restoring the recommended “/cygdrive/c” archive?

  2. UbuntuLinuxHelp UbuntuLinuxHelp on May 14, 2009 7:12 am

    @bish – I’ve never had to restore from automated backups – yet. Over time, I’ve become a bit obsessed with backup redundancy. If something happens, I have three different backup systems that all use different methods. The easiest system I always go to first (when I need to restore a file) is my external NAS device. It simply creates copies of files (no compression, incremental or anything like that) – That’s why it’s so easy. I blogged about that unit (D-Link DNS-321) on BloggerSavvy.com: Saving Your Data When Disaster Strikes. (At that time there was still data on a Windows based box, which was the one that crashed as a result of hardware failure)

  3. Constantine Tsardounis Constantine Tsardounis on December 10, 2009 11:50 am

    Hello to all!…

    I tried everything to the letter and when I am running rsync.bat I am receving

    @ERROR: chroot failed
    rsync error: error starting client-server protocol (code 5) at /home/lapo/packaging/rsync-3.0.4-1/src/rsync-3.0.4/main.c(1504) [sender=3.0.4]

    Any ideas? thank you very much!

Name (required)

Email (required)

Website

Speak your mind