[School of Physics - Optics Group]

Installing ssh and rsync on a Windows machine: minimalist approach

This page provides a brief outline of how to get rsync running on a Windows system. This is for the simplest self-contained system without a full Cygwin installation. If you want Cygwin as well, please install Cygwin with openssh and rsync: cygwin.

Binaries

rsync_minimal.zip ZIP of basic package (rsync, ssh, cygwin1.dll)
rsync_minimal.tgz tar.gz of basic package (rsync, ssh, cygwin1.dll)
binaries directory

Source

Installation (Windows 95/98/NT4/2k/XP)

To use rsync, you first have to have ssh running. Don't even think about using rsh, and you probably don't want to rely on the built-in rsync transport.
  1. Unpack rsync_minimal or rsync_full, e.g. as c:\rsync.

  2. Edit the rsetup.bat file. This is a simple batch file that defines your username and home directory and path; modify the appropriate two lines.

  3. Open a DOS or NT command window and go to the appropriate directoy, e.g. cd \rsync

  4. Set the path etc. by running rsetup.


Running rsync

  1. Try rsync:
    where remote is the name of a remote host (e.g. a Linux box, or optics).
    This will save the c:\rsync directory and files to machine remote, at backupdir under your home directory on remote.


  2. For a full drive, e.g. D: try:
    This will save all of D:\* to remote:backupdir/mypc/d/*.

    Note 1: rsync will only create directories one deep. So in the example above, it would create remote:backupdir/mypc/d if remote:backupdir/mypc already exists, but not if only remote:backupdir exists (i.e. without mypc). Note 2: These examples use a directory relative to your home directory on remote. You can also use absolute directories, e.g. remote:/rsync/data2/blogs.

    WARNING!

    Be careful of the --delete option. Read the rsync man page for information. It can be catastrophic!


  3. Try the example batch file to back up a whole drive, drivec.bat. Edit this to set the appropriate remote hostname and remote directory location. Note the directory notation, e.g. /cygdrive/c for drive C:\.

    You can just execute this batch files to mirror your drive. For example, make a shortcut to it from an icon on your desktop, and then just double-click on the shortcut and your whole drive will be mirrored exactly.


  4. Other things to try:

WARNING!

Be careful of the --delete option. Read the rsync man page for information. It can be catastrophic!

Setting up ssh keys

Normally you will have to enter your password every time. However, you can generate privacy keys for ssh such that you won't have to enter your password. This is not secure, and if someone gets the identity key on yorur PC, they can log on to the remote host as you, and wreak havoc. There is a mechanism for protecting against this, but for the moment I don't have time to explain. Hence, use this at your own risk.
  1. Generate your security keys by running ssh-keygen:
    You will be asked Enter file in which to save the key (/rsync/.ssh/identity):, just hit Enter.

    WARNING: This creates a ssh key without a passphrase. That means that anyone can use your Win95/98 machine to connect to any of the hosts that you set up, without having to type a password ever (because Win95/98 don't have real passwords). If anyone else has access to your PC, then use ssh-keygen and enter a passphrase when prompted.


  2. Add \rsync\.ssh\identity.pub to the end of your ~/.ssh/authorized_keys file on the system you want to send your files to. Let's assume this is a machine called remote.

    Copy identity.pub to remote with a command like:
    where you need to replace myusername with your username.

    Then log in to remote, and:

    WARNING: Once this is done, anyone that has a copy of your private key, \rsync\.ssh\identity (not your public key, identity.pub) can log in to remote without a password. So, make sure you don't let anyone read this file. In particular, make sure that if you "share" your drive, you have it set so that a password is needed for both read and write.

  3. In the DOS or CMD window, run ssh:
    You will be prompted to ask if you want to add remote to the authorized hosts, answer is "yes" (all three letters). You should then be connected to remote. You can use it like a telnet session (e.g. try ls, and so on).


Recovering files

You can recover files by logging on to remote, and copying the files, or by finding remote in your Network Neighbourhood, or using rsync itself. For example: will list the files in remote:/rsync/data1/d. You can recover one with something like: where the . can be replaced with any local destination.

Automating rsync

This is most easily done with the Windows Task Scheduler. If you have an old Windows, you can get Task Scheduler by downloading the free Internet Explorer (version 4 or later). To add a scheduled task:
  1. click on My Computer and look at the bottom. You should see a folder named Scheduled Tasks
  2. click on Scheduled Tasks
  3. click on Add Scheduled Task
  4. follow the menus; when offered a list of programs to run, select Browse.. and find a batch file such as c:\rsync\drivec.bat
  5. select appropriate times and so on

Running multiple rsyncs simultaneously

Steve Brown discovered that you can only run one rsync at a time, unless you use the -P option for ssh.

Excluding directories

Including and excluding files and directories is well described in the rsync man page. For some good help on this stuff, look at this message by David Bolen.

It can all be very confusing, and two things are not terribly clear. First of all, the basic idea. To exclude various files and directories, you can create a file listing them, and execute rsync with the appropriate option, for example: Let's assume the exclude.txt file looks like: To understand how this works, you should first of all read the man page, and remember:
  1. rsync would compare the source filename "usera" to "+ /usera/". That is, it doesn't compare "/users/usera". The head of the file tree is "/users".
  2. rsync doesn't compare all filenames with the list. That is, it doesn't recursively go into subdirectories once it thinks a directory has been excluded. So in the example above, the "+ /userf" tells rsync to match that subdirectory but not the files and subdirectories in it.
  3. Note that the "- /userb/" and "- /userd/" patterns are redundant; these would be excluded anyway by the final "- /*".

Merging filesets (e.g. laptop+desktop)

This is still experimental. The instructions given here are inefficient in terms of disk use, but safe.

Before you start, it's a good idea to look at the how the files are stored on both machines. For example, if on your laptop you have d:\personal\photos and your desktop has d:\mystuff\photos, then the merged fileset will have both, even if "photos" are the same in both cases. Also, rsync is case sensitive, so if a file is Mydir on one drive and mydir on the other, your merged set will include both. A little effort at homologising your directory structures beforehand can save you lots of time and disk space.

Let's assume you want to merge two filesets, laptop drive D and desktop drive D.
  1. First, make mirrors of the two computers you want to merge, to a server, e.g. a computer called remote:
  2. Now make a copy of one of these on remote. For example, copy the laptop to a new area which we'll call merge:
  3. Now merge that with the other (i.e. desktop) using rsync: Note the -u option. This says update only so that if a file already exists and is newer, don't overwrite it. Also, the -b option means that old files are backed up (a ~ is added to the backup filename).
  4. Just to be really paranoid, you can do the reverse and see if both merged sets are the same. While still logged on to remote:
  5. At this point you have two hopefully identical merged filesets. You should carefully go through and see if they're what you think they should be. Do search for those files that were backed up (e.g. find /rsync/data1/joeblog/merge -name "*~"). If you're happy with what has happened, you can do it "in real life", for example using rsync to do the merge on your desktop or on your laptop, using host remote as the source. Here's how you might want to do it (I haven't tried it yet!). From your laptop: and from your desktop:

Created: 5 January 2000
Updated: 21 April 2001
Maintainer: Robert Scholten, School of Physics, Email:  r.scholten@physics.unimelb.edu.au
Authorised by: Robert Scholten, School of Physics, Email:  r.scholten@physics.unimelb.edu.au
This page, its contents and style, are the responsibility of the author and do not represent the views, policies or opinions of The University of Melbourne.