Originally published at PamHardy.net. You can comment here or there.
So, I've been wanting to back up my personal files for some time now -- at least since this year's World Backup Day, which was March 31st, but probably even since before that. I have a lot of files that are irreplaceable -- mostly photos.
What do you do when you have irreplaceable files and you want to make sure that you don't lose them? Well, ideally, you want to back them up. But backing them up to an external drive attached to your PC or even another computer in the same house isn't good enough. What happens if your entire house burns down or you are victim of a tornado? Then your original files AND the backup files are gone.
The solution is to make sure that you have at least one backup off-site, preferably in a different state. There are many paid online backup services that will do this for you. However, I already have unlimited online hosting available via my web host. It didn't make sense to pay for online storage when I already have online storage readily available. But how could I set up an automated backup system to back up my personal files to my web host automatically, so that I would not have to do so manually?
I first tried a SVN repository. This did not end up working for me. I never got it set up so that it would back up automatically. In addition, the repository required vigilant maintenance. If I deleted a file or renamed a folder in the wrong way, the repository would complain and have to be fixed. This was too much micro management for me, so I searched for a better solution.
I finally found it -- automated backup with the Windows program cwRsync. cwRsync is the Windows version of the Unix program Rsync. Rsync is a lot like SVN - they both synchronize your local and off-site files, only backing up the files that have changed recently. So the initial backup of all of your files may take quite a lot of time, but the subsequent backups after that will take much less time, only backing up the files that have changed.
Below, I'll describe how to set this up.
First, you need to download cwRsync. You can find the latest version of cwRsync here. Click on the most recent version. On the next page, click on the file named cwRsync_x.x.x_Installer.zip (where x.x.x is the version number) to download cwRsync.
Install cwRsync by unzipping cwRsync_x.x.x_Installer.zip and running the executable once it is unzipped. Install cwRsync in the default location. Take note of whether this location is C:\Program Files\cwRsync or C:\Program Files (x86)\cwRsync. You will need this information later.
If cwRsync did install in C:\Program Files (x86)\cwRsync, do the following. (If cwRsync installed in C:\Program Files\cwRsync, you can ignore this part!) Open up C:\Program Files (x86)\cwRsync in Windows Explorer. Right click on cwrsync.cmd and left click Edit. Change
Configuring Your Local Computer for cwRsync
You need to create an SSH public/private key pair so that your automated backups can occur without you being prompted for a password. When you create the keys, make sure you are logged in as the same Windows user as the one who will be running the automated backups.
In order to create this key pair, do the following:
First, open Windows Explorer and navigate to your C:\Program Files\cwRsync folder (or C:\Program Files (x86)\cwRsync, if that's where Windows installed cwRsync for you). In the cwRsync folder, create the folder home\[user]. For clarification, you will need to create a folder named "home" inside of the cwRsync folder. Then, inside of your new folder "home," create a folder whose folder name is identical to the username on which you are currently running Windows. This may be the Administrator user, or it may be another username. If your username is Administrator, create a folder named Administrator inside of this new "home" folder. The end result will be that you have a new folder C:\Program Files\cwRsync\home\[user].
Once you have created that folder, if you are running Windows XP, click the Windows Start button, and choose "run". In the run dialog box, type "cmd" and hit enter. The command prompt window will open.
If you are running Windows 7 or Vista, click the Windows Start button and type "cmd" in the search box. Hit enter. The command prompt window will open.
In this command prompt, type:
cd "c:\program files\cwrsync\bin"
and hit enter. Note that if cwRsync installed to C:\Program Files (x86)\cwRsync instead of C:\Program Files\cwRsync you will need to modify the above text accordingly.
ssh-keygen -t rsa -N ''
and hit enter. Note that the above line ends in two single quotes, one right after the other.
You will be asked to "enter file in which to save the key." Hit enter to accept the default that is given.
Your SSH public/private key pair has now been created.
Now, create a folder on your C drive to house a copy of your private key. This folder's name should contain no spaces. You can call it whatever you want, just make sure to make a note of what it is called. Once you have created this folder on your C drive, copy the file C:\Program Files\cwRsync\home\[username]\.ssh\id_rsa to that new folder. (Substitute Program Files (x86) if your cwRsync install is in that folder.)
Configuring Your Remote Server (Web Host) for cwRsync
On your remote server, create a folder named .ssh . Next, upload the file C:\Program Files\cwRsync\home\[username]\.ssh\id_rsa.pub to the remote .ssh folder. (Substitute Program Files (x86) if your cwRsync install is in that folder.) On the remote server, rename id_rsa.pub to authorized_keys.
Remove write access to this file. If you are using the FTP client FileZilla, right click on the authorized_keys file and left click File permissions... . Uncheck write permissions for Group and Public. The numeric value for this CHMOD permission is 644.
Also, make sure that the .ssh folder does not have write permissions for Group and Public. Right click on the .ssh folder and click File Permissions. Uncheck the write permissions for Group and Public. The numeric value for this CHMOD permission is 755.
Testing Upload With cwRsync
Now it is time to test uploading with cwRsync. First, create a test folder on your local C drive named temp. Place a test file in here as well (can be any file, but I recommend a small text file).
On your remote server, create a test folder named test.
Open up C:\Program Files\cwRsync in Windows Explorer on your local computer (substitute Program Files (x86) if necessary). Right click on cwrsync.cmd and left click Edit. Add the following line to the end of the file:
rsync -av --chmod u+rwx -e "ssh -i /cygdrive/c/[name-of-folder-containing-private-key]/id_rsa" /cygdrive/c/temp [your-remote-username]@[your-remote-subdomain].[your-remote-domain].com:/test/
In the above example, you will need to substitute the name of the folder containing your private key, your remote username, and your remote web domain, as noted.
Save the cwrsync.cmd and close the text editor.
Now, in Windows Explorer, double click on the cwrsync.cmd file to run it. A command prompt window will appear, and it may ask you for your remote web host's password. Enter your password and hit enter.
At this point, your test file in your test folder on C should be uploaded to your remote web host. FTP into your remote web host and check the remote test folder to be sure.
If running cwrsync.cmd prompted you for a password, run it a second time by double clicking on cwrsync.cmd to make sure that it does not prompt you for a password the second time around.
If your test file successfully uploaded to the test folder on your remote server, and you were not prompted for a password, congrats! cwRsync has been successfully tested and is working properly. If not, you have some troubleshooting to do.
Setting Up A Backup with cwRsync
Once you are able to successfully back up a test folder to your remote host, you are ready to set up your "real" back up.
Open up C:\Program Files\cwRsync in Windows Explorer on your local computer (substitute Program Files (x86) if necessary). Right click on cwrsync.cmd and left click Edit. Modify the rsync code above as follows:
rsync -av --chmod u+rwx -e "ssh -i /cygdrive/c/[name-of-folder-containing-private-key]/id_rsa" /cygdrive/c/[path-of-folder-to-backup] [your-remote-username]@[your-remote-subdomain].[your-remote-domain].com:/test/
We are only modifying one part of this code -- the path to the folder that you want to back up. The syntax for this will always begin with /cygdrive/[drive-letter]. Do not worry about the fact that the folder cygdrive does not exist on your local machine. That's just how the syntax for rsync works.
So, let's say you wanted to backup your My Documents folder. Your rsync code would probably look something like this:
rsync -av --chmod u+rwx -e "ssh -i /cygdrive/c/[name-of-folder-containing-private-key]/id_rsa" /cygdrive/c/users/[your-local-username]/Documents [your-remote-username]@[your-remote-subdomain].[your-remote-domain].com:/test/
Once you're happy with your rsync line, save the cwrsync.cmd and close the text editor.
In Windows Explorer, double click on the cwrsync.cmd file to run it. Your backup will now commence. Depending on the size of the folder that you are backing up, this could take quite awhile.
Automate Daily Backups with Windows Task Scheduler
Once you have verified that your initial backup was successful, it is time to schedule automated daily backups that require no future action on your part.
Windows XP Instructions:
Open Windows Task Scheduler by clicking on the Start Menu and navigating to Programs, Accessories, System Tools, Scheduled Tasks.
Scheduled Tasks will open. Double click "Add Scheduled Task."
On the first screen, click Next.
On the second screen, it asks you to "click the program you want windows to run". Do not choose a program from the list. Instead, click Browse.
Click the Browse button and navigate to C:\Program Files\cwRsync\cwrsync.cmd.
On the third screen, it asks you to "type a name for this task." Create a name for this task, such as "Automated Daily Backup."
On this third screen it also asks you how often to perform the task. Choose daily.
On the fourth screen, it asks you to choose a start time. For time of day, I recommend running your backup in the middle of the night, when it is unlikely you will be using your computer, such as 2:30 AM.
On the fifth screen, it asks you to "Enter the name and password of a user." This is the Windows login that the backup will run under. It is important that you choose the same Windows login that you used to create your SSH key, above. The username is entered in the form computername\username -- for example, computer01\administrator. Make sure to enter your Windows password.
On the sixth and final screen, click Finish. Your automated daily backup has now been scheduled!
Windows 7 Instructions:
Open Windows Task Scheduler by clicking on the Start Menu and navigating to Programs, Accessories, System Tools, Task Scheduler.
Task Scheduler will open. Click "Create Basic Task."
Create a name for this task, such as "Automated Daily Backup." Click Next.
For Task Trigger, keep Daily selected and click Next.
For the start date, choose tomorrow's date. For time of day, I recommend running your backup in the middle of the night, when it is unlikely you will be using your computer, such as 2:30 AM. Click Next.
For Action, keep "Start a program" selected and click Next.
Click the Browse button and navigate to C:\Program Files\cwRsync\cwrsync.cmd (or C:\Program Files (x86)\cwRsync\cwrsync.cmd, if this is where cwRsync is installed). Click Open and then click Next.
Click Finish. Your automated daily backup has now been scheduled!
I wrote these instructions because I had trouble with the instructions I found online. They seemed simple enough, but for various reasons, they weren't working for me. I did some trial and error and the above instructions are what ended up working for me. Your mileage may vary. I used the following resources to aide me in setting up cwRsync:
Backup Your Personal Computer to Dreamhost with Rsync
The rsync Tool In Windows
cygWin connect by SSH using RSA key; ssh.exe couldn't create /home/user/.ssh