DIY Online Incremental Backups

Cardboard box photo by Philgarlic
Every web or graphic designer needs a way to backup their files and keep them off-site in case of disaster. Last month I wrote a post about online incremental backups using Mozy. But if you’re like me, you may want to try doing this yourself.
Today we’re going to tackle a DIY project—making online, incremental backups and storing them on your website (or more accurately, on your web host’s server). For security reasons, we’ll be placing the backups outside of the browseable directory structure.
This tutorial is tailored to Windows users and is based on the tutorial found on ExaVault’s website. But instead of using their pay service, we’ll be using the extra storage space on your web host account.
The general principals are the same if you’re running Mac OS X or Linux, but the command syntax is different. For tutorials on how to set up Rsync on the Mac and Linux, take a gander at the following tutorials:
Requirements
In order to complete this DIY project, you are going to need the following:
- The desire to get your hands dirty
- Windows (95 & up will do)
- cwRsync
- Web Host that allows you plenty of storage and transfer bandwidth
- Access to SSH (Secure Shell) - Note: You may have to specifically ask your host to enable SSH access. Most hosts have it turned off by default.
Still with me? Grab your safety glasses and let’s get to work.
For Windows users, you will need to get cwRsync (the download link is in the right sidebar on their site).
Basically, cwRsync creates a Linux environment on Windows so you can run Rsync (a program that comes with Linux and Mac OS X.
Step 1 - Install cwRsync
- Download cwRsync from IteF!x
- Unzip cwRsync_2.1.5_Installer.zip and run the installer (the default settings should be fine)
Step 2 - Create a Security Key (SSH)
We need to make a secure connection between the computer you want to backup and your web host, so we need to create an SSH key.
1. Open the Command Prompt
2. Add cwRsync to your Windows path so you can run it:
path = %PATH%;c:\program files\cwRsync\bin
3. Create a directory to put store your backup config files. Create a directory in your C drive and name it backup ( c:\backup )
4. Create the SSH key.
ssh-keygen -f /cygdrive/c/backup/ssh_key -t rsa -N ''
‘/cygdrive/c/backup/ssh_key’ is where cwRsync is going to save the SSH key. ‘/cygdrive/c/’ is basically your C: drive.
Step 3 - Upload Your Key To Your Web Host
In the following commands, substitute username@domain.com with your account username (usually your account name given you by your web host) and your domain name.
Type the following command; all on one line:
rsync -e ssh /cygdrive/c/backup/ssh_key.pub username@domain.com:ssh_keys/key1.pub
Since the host can’t be verified, it will ask you if you want to connect to the server. Type yes and type in your password (for your web host account) when asked. If it doesn’t say anything else, then it was a success.
If it gives you an error, check and make sure you substituted your username/domain name correctly in the above command.
Step 4 - Activate Your Key
Activate the key you created:
ssh username@domain.com addkeys
Enter your password when prompted.
This copies your public key (key1.pub) to the authorized_keys directory in your backup directory.
Note: If this step fails, you can simply make a copy of the key1.pub file and place it in the authorized_keys directory yourself and it should work.
That’s pretty much it for setting up the connection between your computer and your web host’s server. Now let’s run a test to make sure everything’s working.
Step 5 - Run a Test Backup
This is an important step to take before trying to backup your important files. We want to make sure it works properly.
In Command Prompt, type (again, substitute your details):
rsync -avz -e "ssh -i /cygdrive/c/backup/ssh_key" "Desktop" username@domain.com:backup-test
This tells Rsync to backup all the files on your Desktop and upload them to /backup-test on your web host.
Rsync should create the backup-test directory for you. But depending on your web host’s setup, you may have to create the directory yourself.
Note too, that we’re storing the backup in a directory outside the site structure. This is for security reasons—we obviously don’t want people to be able to reach your backup folders from their browser.
Step 6 - Check the Backup
Since we can’t browse to our directory from our browser, use either FTP or SFTP to view the /backup-test folder. Make sure the files from your desktop are there. If so, you’re good to go for making your first real backup.
You can go ahead and delete your backup-test directory if your test backup worked.
Step 7 - Back It Up Already
Decide what folders you want to backup. Note that cwRsync makes a Linux environment on your Windows system. That said, cwRsync wasn’t designed to backup Windows system files. I haven’t personally tested it, but there are probably permissions issue that won’t let you backup system files that are in use by Windows.
I have a main directory that holds all my clients’ project and production files in subdirectories (/Production Files). So this is the folder I’ll backup.
Make a Backup Script
We will need to make a backup script that can be run from the Command Prompt. This will feed the commands to Rsync so we don’t have to type it all by hand every time.
You can download a sample batch file from ExaVault’s website.
The very last line in the data-backup.bat file is what you will need to change.
Example:
rsync -avz --delete -e ssh "/cygdrive/c/My Documents/Production Files/" myusername@mywebsite:mainbackup
Data-backup.bat contains instructions to help you make edits. This file should go in your c:\backup directory.
Run the backup the first time to test it:
c:\backup\data-backup.bat
After typing your password in, it should start uploading files. If you have a lot of information, depending on your upload speed, this may take a while to complete.
The next time you run the batch file, it will be incremental and only upload the changed bits.
Multiple Directories
You can backup a directory and all it’s subdirectories will be backed up. However, there’s something to note when backing up more than one main directory that I discovered.
To backup more than one main directory, I recommend making a separate .bat file for each main directory you want backed up.
The reason is that if you add a second command to data-backup.bat, once the first backup command is finished, you will be prompted for your password again. If you’re not at your computer at the time, your host will timeout and you will have to run the whole command again.
I also recommend sending each main directory that you backup to it’s own separate folder on your web host.
For instance, say you want to back up the directories c:\production-files\ and also e:\studio-projects\. Backup production-files to backup-1/ and studio-projects to backup-2/.
If you backup both main directories to the same folder, the commands in each batch file will undo the other. Each batch file will look for the files it’s supposed to be backing up. When you run the next .bat file, it will see the files/folder from the other backup and ’sync’ (ie delete) them since they are not part of the current backup. I know this sounds confusing, but trust me, it’s annoying to see an hour’s worth of uploading be wiped out only to be redone the next time you run the other batch file.
Once you have everything working, you can create shortcuts to the .bat files on your Desktop so you only have to double-click each one to run them.
Conclusion
This is definitely not as easy as using Mozy for online incremental backups, but hey, it works and it’s nice to have it right on your own server. This technique can also be used to backup to another computer across a network. It’s also a great redundancy backup plan for just-in-case.
Are you currently using, or have you used cwRsync or Rsync in the past? Do you use something else I’d love to hear your thoughts on this—leave a comment.

3 Comments to 'DIY Online Incremental Backups'
November 11th, 2008
Thanks for the recommendation Philgarlic.This is a very useful blog and I bookmark this post.Some times we can not make back ups and take it very easily and that create a huge problem .
November 11th, 2008
I backup my files and emails with a very easy to use software called Titan Backup, the destination is a 500gb WD harddisk, but the company stated that an online feature is under work also. Give it a free trial here.
I also got my hands on a 30% discount coupon from them, during the order process enter this coupon:NEOB-M5VL
November 10th, 2008
[...] Today we’re going to tackle a DIY project—making online , incremental backups and storing them on your website (or more accurately, on your web host’s server). For security reasons, we’ll be placing the backups outside of the browseable .. Original post [...]
Leave a comment
Note: All links in the comments are set to 'nofollow'. Search engines will not follow or index those links.