Backing up Windows to computer with SSH
Working on the computer department, UNIT, of the University of Linköping taught me many things, but one of the most important was the following:
To create backup of your data!
There were numerous disasters averted by having backups, I tell ya! When I started working there, there were hardly any backups at all. When I left the place, we had a backup robot.
A backup robot is perhaps not the best solution for your home needs, but there are other solutions you can use. Since I run Windows at home and have access to a Linux-server, I chose the following solution:
Rsync over SSH
Rsync is a program to remotely synchronise files between two computers. SSH stands for Secure SHell and is a protocol which specifies how to connect to another computer with a crypted connection, which also allows you to transfer data, such as files, without having others listen to your traffic, especially people who might have malicious intentions.
Step 1: To help me with this task I installed cwRsync, which is a package that contains Cygwin and Rsync software. Cygwin is a UNIX-like enviroment for Windows, which allows you to run UNIX-like programs, such as Rsync. cwRsync comes with an installer, so you proceed installing it as any other windows program.
Step 2: I created a file that contains the directories I wished to backup from my computer. I named it standard_backup.cmd, which I placed in the cwRsync installation directory, and it looks like this:
@ECHO OFF
REM A cmd-file to create backup of my files! /Mika, 2006-01-08SET CWRSYNCHOME=C:\PROGRAM\CWRSYNC
SET CYGWIN=nontsec
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
set HOME=C:\Program\cwRsync\bin
REM set CYGWIN=binmode tty
REM set TERM=ansi
set USERNAME=mika
set RSYNC_RSH=ssh.exersync -e ssh -av –delete –rsync-path=/usr/bin/rsync “/cygdrive/C/Program/cwRsync” mika@remotehost:backup/
rsync -e ssh -av –delete –exclude=Bilder –rsync-path=/usr/bin/rsync “/cygdrive/D/Filarkiv” mika@remotehost:backup/
This assumes that cwRsync is installed in C:\Program and that your name on your remote host is mika
You can easily change those parameters.
The rsync parameters are quite easy. -e stands for what program it should use to connect to the remote host, ssh in this case (this comes in the cwRsync-package). -av stands for archive and verbose, which means I want it to make a copy of my current directory structure on my computer and to display information about the sync-process when I execute it. –delete says it should delete the files on the remotehost which have been removed on my computer. –exclude is very handy to exclude directories/files with certain words. I exclude my images-library since it’s too big. I backup that via DVD-RW instead. –rsync-path is where the rsync-program is located on your .
After that you specify the directory to backup. The notation for this is /cygdrive/”disk letter”/path. As last parameter you specify the remote directory, using SSH-notation which is username@remotehost:remotepath.
Step 3: If you don’t want to enter your password on the remotehost everytime you do a backup, I recommend to create a public-key that you copy to your remotehost. This you do by fireing up yor cmd-window and going to your cwRsync-directory: cd C:\Program\cwRsync\bin\. While there, you execute the following:
ssh-keygen -q -b 1024 -t dsa -f identity -N ”
This will create a file called identity and a file called identity.pub. I created a directory called .ssh in the cwRsync/bin-directory and put these files into it (needed for ssh to correctly find them). The content of identity.pub you have to copy to a file on your remotehost called .ssh/know_hosts.
Then you need to establish the first connection to your remotehost via SSH to get the host approved:
- Fire up a cmd-window
- Go to the C:\Program\cwRsync\bin-directory
- Execute: ssh username@remotehost
- Answer yes to the question that pops up about allowing connection to that host.
If everything is set up ok you should now be logged onto your remotehost.
Step 4: Create your first backup. Do this by:
- Fire up a cmd-window
- Go to the C:\Program\cwRsync-directory
- Execute the standard_backup.cmd file
This should start the backup of your files!
If you’re like me, lazy, you will find it tedious to fire up the cmd-window and change directory to the cwRsync-directory. I searched for good solutions for this, and the one I found was to create a shortcut of the cwRsync-directory on my desktop and then install the Windows XP PowerToy named CmdHere. This allows you to right click on the shortcut on your desktop and choose ‘Open Command Window Here’, which saves you the trouble of changing directory
Hope someone finds this whole approach, or some of the information in it, useful
Technorati Tags: cwRsync, Rsync, SSH, Backup
Hannes wrote,
Tutorials are always nice. I’m considering setting up something similar.
August 30th 2006 at 09:04 (9:04 am) — Using
Firefox 1.5.0.5 on
Ubuntu Linux
Mika Perälä wrote,
Hey hey! Glad if it comes to use!
September 6th 2006 at 23:02 (11:02 pm) — Using
Firefox 1.5.0.6 on
Windows XP
Hannes wrote,
Yeah, backups are nice. I am thinking of being even more 1337 and use SVN for content versioning some files as well. Might be a bit overkill though
September 7th 2006 at 23:18 (11:18 pm) — Using
Firefox 1.5.0.5 on
Ubuntu Linux
Mika Perälä wrote,
Depends on if you really need it
Then it’s not overkill. But most of the time it’s just a fun thing to do 
September 11th 2006 at 13:21 (1:21 pm) — Using
Firefox 1.5.0.6 on
Windows XP
Hannes wrote,
Yes, as someone on a Ubuntuforums said “I think I enjoy and spend more time configuring my computer than actually working with it”
September 11th 2006 at 16:22 (4:22 pm) — Using
Firefox 1.5.0.5 on
Ubuntu Linux
Caroline wrote,
You are such nerds.
September 11th 2006 at 20:25 (8:25 pm) — Using
Firefox 1.5.0.6 on
Windows XP
Sean wrote,
This nerd is very glad that the other nerd took the time to be such a nerd…
What a different World it would be without nerds like us?
February 19th 2007 at 18:54 (6:54 pm) — Using
Internet Explorer 7.0 on
Windows XP
Mika Perälä wrote,
Hehe
Glad you had use of it!
Indeed! What would the world be… no computer games. No advanced mind games. No nerdiness. Nope, can’t have a world like that!
February 20th 2007 at 00:46 (12:46 am) — Using
Firefox 2.0.0.1 on
Windows XP
Caroline wrote,
Not only no mind games…also no Mind Matters.
February 20th 2007 at 10:19 (10:19 am) — Using
Firefox 1.5.0.9 on
Ubuntu Linux
Mika Perälä wrote,
So true, so true!
February 20th 2007 at 12:24 (12:24 pm) — Using
Firefox 2.0.0.1 on
Windows XP