September 1, 2010

  

Backup Our Windows Machine Using cwRsync

Post image for Backup Our Windows Machine Using cwRsync

0 comments

in Linux and the Families,Others,Windows

As I was not very confidence with my laptop’s hard disk reliability, and i don’t want to loose any of my data, I’ve considered to backup my data on my laptop to my LINUX server. This should be done by some methods i.e FTP, Samba Share etc. I’ve decided to use a powerful unix tool called ‘rsync‘.

rsync synchronizes your local and offsite filesystems by transferring only the changed portions of files. After your initial upload, each subsequent upload will be very fast, as only the differences in the files are sent.

For Windows OS, we can use cwRsync which is a free distribution of the rsync utility that is optimized for quick and easy installation in Microsoft Windows.

You can download cwRsync here, however we recommend checking for the newest version here. Be sure to look underneath the “cwRsync” project.

Once you have downloaded this installation file, run it. You should select the defaults the installer gives you, including the default installation path of:

C:\Program Files\cwRsync

I will STRONGLY recommend installing the program in the default location.

To avoid being prompted with password each time the rsync backup run, we need to create, and upload, an SSH public key.

It is VERY IMPORTANT that the user who creates the key is the SAME user as the one who runs the automated backup.

In my case, I’ve logged in as my Domain user and perform the following steps:

  • Run Command Prompt, I’m sure you know how to run Command Prompt in your Windows OS.
  • In this command prompt, type:
    cd "c:\program files\cwrsync\bin"

    and hit enter. Then type:

    ssh-keygen -t rsa -N ''

    and hit enter.
    (Note that the line ends with TWO single quote characters, one after another)

  • We will be asked to “enter file in which to save the key” – just hit enter to accept the default that is given.
  • Now, upload the newly created key to your rsync.net filesystem with this command:
    rsync -av "/cygdrive/c/Users/MyDomainUser/.ssh/id_rsa.pub" MyLinuxUser@MyLinuxServerIP-or-Hostname:.ssh/authorized_keys

    (Insert our own user ID in place of “MyLinuxUser” as well and the correct IP Address or hostname in place of “MyLinuxServerIP-or-Hostname”. Remember, my Windows OS is Windows 7, and the path for “id_rsa.pub” will be different with other version of Windows OS).

  • When we run this rsync command, we will be asked to confirm the first connection – enter “yes”, and when prompted for our password, enter our password for the LINUX Server.
  • Our RSA public key is now uploaded to our LINUX filesystem, and any further logins over ssh that this Windows user (in this case, my domain user) performs will not require a password.


Now we need to decide what to back up. In my case I would like to backup all of my D: Drive.

Open the rsync script by going to the start menu, choosing Programs, then choosing cwRsync, then choosing “1. Batch Example”. When you select this, the script will open in a text editor.

Leave the file exactly as it is – the settings in place are very important. You are simply going to add one or more rsync commands to the end of it, one for each folder or file you want to back up.

I’ve added a single line as below:

rsync -avr --chmod u+rwx -e "ssh -i c:\Users\MyDomainUser\.ssh\id_rsa" "/cygdrive/d/" MyLinuxUser@MyLinuxServerIP-or-Hostname:Backup/

You can see how the source directory:

D:

is entered as

/cygdrive/d/

this transformation is required for all Windows source folders.

we can add as many rsync lines to the end of this script as we like – one for each folder we wish to back up.

Once the rsync lines have been added to the script, we should save the file and exit the editor.


Now, let’s schedule the backup, which is done through Task Scheduler, which is included in Windows.

Open Task Scheduler and add c:\program files\cwrsync\cwrsync.cmd to run in your schedule, name it as you like and change how often the task will be performed. And also, you can define the start time, windows login to run the task etc. I’m very confidence you know how to do it exactly or check here for clearer information.

Remember, it is extremely important that we test our backup. We are testing not only that the backup works properly and transfers the files we think it will, but also that it will properly log into our Linux Server filesystem without prompting you for a password.

The first test, making sure the automated backup is not prompted for a password, is performed simply by running the backup our self. From the start menu, choose Run, and type in the location of our backup script:

c:\progra~1\cwrsync\cwrsync.cmd

We should see the backup run in the command prompt that appears, and it should complete without asking you for a password.

After we have completed a successful backup, and periodically as time goes on, we should then log into our Linux server browse our filesystem.

No related posts.



Previous post:

Next post: