Installing and Running Rsync

Download a rsync client

  • You need to run a rsync client on your other computer. If you are running a unix style operating system (such as on a Mac), then simply build rsync on your own computer. Otherwise I recommend CWrSync, a simple command line utility which can be downloaded from SourceForge. DeltaCopy is an easy to use rsync GUI for Windows, although I was unable to configure the GUI to talk to the rsync server using any port other than 873; DeltaCopy is a slightly smaller download, but it included rsync 2.6.6 as opposed to 2.6.9 at the time of writing and does not handle SSH communications.
    Both of these actually run rsync using CygWin to provide the Linux environment under Windows, so install whichever you prefer and then we can start testing your setup. As I said before, I recommend CWrSync.

Testing your installation

  • On your server…
    • Ensure that there are some sample files in the directory specified in your configuration file. (/ftp/pub/rsyncd in our example)
    • Add /usr/mylocal to the path on your server, so edit the file /.bashrc (pico /.bashrc) so that the export of PATH reads

      export PATH=”/usr/mylocal/bin:$PATH:/usr/local/apache/bin”

    • Run the rsync server from the command line for the purposes of testing. Simply type rsync –daemon
      You may need to add the –no-detach option. This option instructs rsync to not detach itself and become a background process when running as a daemon and is required when running as a service on Cygwin. It may also be useful when rsync is supervised by a program such as daemontools or AIX’s System Resource Controller. –no-detach is also recommended when rsync is run under a debugger. This option has no effect if rsync is run from inetd or sshd.
  • At the client end… (On your Mac/PC)
    • Open a command prompt on your PC (Start, Run, cmd.exe)
    • Change to the directory where you installed rsync – for CWrSync (cd C:\Program Files\cwRsync\bin) or DeltaCopy (cd C:\Program Files\DeltaCopy) on your PC.
    • Use the command rsync mydomain.com:: –port=8730 to connect to your rsync server. You should be presented with a list of valid modules similar to the one shown below.
      Welcome to RollingR's RSync Test Area.

      Any files downloaded are at your own risk.

      rsyncd_module My Very Own Rsync Server. This area is ReadOnly


      If you do not want a certain module to be displayed, then change “list = yes” to “list = no” in its section of the configuration file on the server.

    • Now that we have established communications, lets try to synchronise the files on your server to your local drive. The format of the command is rsync -options source destination.
      In order to maintain its Unix compatibility, CygWin and rsync use the format cygdrive/drive_letter instead of drive_letter and a colon when referring to the hard drive on a Window’s PC, so the example below will synchronise the rsyncd_module on mydomain.com to C:\rsync on my PC.
      rsync -auvzbP rsync_user@mydomain.com::rsyncd_module /cygdrive/c/rsync --port=8730

      What this means:
      -a same as --archive archive mode; same as -rlptgoD (no -H)
      -r same as --recursive recurse into directories
      -l same as --links copy symlinks as symlinks
      -p same as --perms preserve permissions
      -t same as --times preserve times
      -g same as --group preserve group
      -o same as --owner preserve owner (super-user only)
      -D same as --devices preserve device files (super-user only)
      --specials preserve special files

      -u same as --update skip files that are newer on the receiver
      -v same as --verbose increase verbosity
      -z same as --compress compress file data during the transfer
      -b same as --backup preexisting destination files are renamed as each file is transferred or deleted. Default is to add ~
      -P same as --partial keep partially transferred files
      --progress show progress during transfer

    • If you do not want to have to enter the rsyncd password, then create a text file (eg mypass.txt) with your password in it and add –password-file=”mypass.txt” to the command line
    • If you want to use encrypted communications when using rsync, then you will need to create a key pair.
      • If you downloaded cwRsync, then type ssh-keygen -t dsa at the command prompt
        Your PC will then generate a key pair. Save the files in the default location (/cygdrive/c/Documents and Settings/YourLogin/.ssh/id_dsa) when asked.
      • Enter a blank passphrase as we need this to run unattended (otherwise you will be prompted for another password everytime rsync connects to your server)
      • Keep a note of the fingerprint – you never know when you will need it.
      • Transfer the public key (C:\Documents and Settings\YourLogin\.ssh\id_dsa.pub) from your PC to /.ssh/authorized_keys on your server. If authorized_keys already exists, then you will need to add your key to the end of the file. NOTE: /.ssh is a hidden directory! Also, it is IMPERATIVE that each key in your authorized_keys file occupies a single line
      • Change the access rights for authorized_keys to read only by executing the command chmod 0400 /.ssh/authorized_keys on your server
      • NOTE:If you are using “-e ssh” then you CANNOT connect using the rsync daemon. Make sure that your command only has a single colon in it instead of the double colon.