Roll-your-own online backup with RSync
RSync is an open source program that provides incremental file transfer for both local and remote files. RSync comes pre-installed on most unix and linux based systems (including Mac OS X) but distributions are available for most popular operating systems including Microsoft Windows (e.g. cwrsync).
This article will focus on how to setup a personal backup using one of the suddenly ubiquitous shared hosting companies like DreamHost, LunarPages or BlueHost. If you already have a account with one of these companies it won’t cost you anything to start backing up your data to a remote server. If you don’t already have an account and want to setup online backup you have two choices:
- Forget RSync, save yourself some trouble - sign up with one of the online backup services like Mozy which is priced nearly identically to a shared hosting account.
- Buy a hosting account and forge ahead - if you’re reading this you probably want to get your hands a little dirty and a shared hosting account lets you do all sorts of neat things like host your own domain, web apps, etc.
Note that you will need a user account on your server with SSH (somtimes called Shell) access permission. This is offered by most but not all shared hosting services.
Now that you have all the pre-requisites let’s outline the setup process.
- Set up key-based authentication. We do this so you don’t have to enter your password every time your backup runs.
- Write a backup script.
- Automate the execution of your backup script.
Not too bad right? At this point the instructions fork into Windows and Mac OS X branches. Because Windows users outnumber Mac users they get a write up first. I promise the Mac write up is coming soon.
Windows Rsync Backup Instructions
Again, you’ll need to download and install cwrsync.
1. Set up key-based authentication
Use PuTTY to login to your account via SSH. If you don’t have PuTTY you can get it here for free. After you’ve logged in, run these commands:
mkdir ~/.ssh cd ~/.ssh touch authorized_keys chmod go-w $HOME $HOME/.ssh $HOME/.ssh/authorized_keys
Next open up a command prompt on your local computer. (Start -> Run -> cmd) When it opens paste this command into it:
ssh-keygen -t rsa
Hit enter every time you are prompted to accept the default values. (three times)
The next step is the trickiest part of the process but it’s not too bad. You need to copy your newly minted public key to your remote hosting account. We are going to use rsync for the first time to do it, how exciting! Replace the <username> and <yourdomain.com> with your hosting account username and domain and run the command below.
rsync -avrz –progress "/cygdrive/c/Documents and Settings/Administrator/.ssh/id_rsa.pub" <username>@<yourdomain.com>:/home/<username>/.ssh/authorized_keys
If you get an error when you run this command, double check your paths. Maybe your Windows username isn’t ‘Administrator’ or maybe your shared host doesn’t put your files in /home/<username>/
When you get it to work you’re all set up to securely transfer files to your hosting account without a password. Congratulations! Time for step 2.
2. Write your backup script
Below is the command for backing up a local folder.
rsync -avrz –progress “/cygdrive/c/foldertobackup" <username>@<yourdomain.com>:/home/<username>/backup
So by now you are hopefully beginning to figure out how this works.
CwRsync comes with a sample script to demonstrate what a backup script should look like. Open C:\Program Files\cwRsync\cwrsync.cmd in your favorite text editor (notepad works fine) and add a line using the command above as the formula for each folder you’d like to backup. e.g.
rsync -avrz –progress “/cygdrive/c/Documents and Settings/Administrator/My Documents" <username>@<yourdomain.com>:/home/<username>/backup rsync -avrz –progress “/cygdrive/c/Documents and Settings/Administrator/Desktop" <username>@<yourdomain.com>:/home/<username>/backup
3. Automate the execution of your backup script
Luckily this step is built into Windows so we’re done with the command line. Hooray! Click Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks
Double click “Add Scheduled Task” to launch the wizard. When it asks you which program you’d like to run click browse and find the backup script you just made @ C:\Program Files\cwRsync\cwrsync.cmd
Give the task a name, choose your backup interval and you’re done! Hopefully you sleep a little better at night knowing that your data is safe and sound.

July 20th, 2008 at 5:50 pm
I recently received an email from Judy who wrote to tell me about her experience using BlueHost to backup some personal files. Evidently their staff is actively looking for personal backups and contacting customers to inform them that they are in violation of BlueHost’s terms of service.
From BlueHost’s terms of service:
“Backup Storage
Bluehost Web Hosting intends to offer services to host web sites, not store data. Using an account as an online storage space for archiving electronic files is prohibited.”
What constitutes a ‘web site’ is not spelled out. Judy said that BlueHost’s criterion for TOS violation is whether or not there are links to the hosted files. If this is truly their criterion, you could install a php file manager like PHP File Manager to avoid violating their terms.