Rscyn4windows

From LinuxServerTech

Jump to: navigation, search


Setting up rsync for Windows machine

There are two ways to set up rsync on the Windows machine. The first assumes you will manually run the backup script, in which case a simple batch file and cwRsync will be all you need. The second is more complex and gives you automated backups which will e-mail a gzip'd attachment on completion. The second requires Active State Perl and a script written by Brandon Zehm which does a very good job of e-mailing things from Windoze. In the following documentation, these are known as the manual backup and the automated backup respectively.


  1. for manual backup, log in as the user who will do the backup. For automated backup, log in as an administrator. Ensure you have good passwords.
  2. Download and install cwRsync: cwRsync Installer. If you want that automated backup, also download and install * Active State Perl for your platform.
  3. Get the scripts:
    1. For manual backup, Batch File Example from the linux server tech server (text file, and you may have to right click and do a Save Link As). Or, simply go to The original site. Rename this to backup.bat and place on desktop.
    2. For automated backup Perl scripts for Windows Backup. Create a directory (I use c:\program files\backup) and unzip the two files into it. You can also get Brandon Zehms full package, which includes documentation and a Windows executable, from either his site or our server.
  4. you can delete all installers at this time.
  5. Create some environmental variables for the current user. Right mouse click on My Computer. Select Properties | Advanced | Environmental Variables.
    1. add C:\PROGRAM FILES\CWRSYNC\bin to the beginning of the Path variable )put a semi-colon between it and the current contents of the path)
    2. Add variable CWRSYNCHOME, with a value of C:\PROGRAM FILES\CWRSYNC
    3. Add variable HOME, with value of C:\Documents and Settings\Administrator\ (or whatever your username is).
  6. Set up cwRsync
    1. create public/private keypair
      1. Open command prompt
      2. 'cd "C:\\Program Files\\cwRsync\\bin"'
      3. "ssh-keygen"
      4. Generate key. For automated backup, set the password to nothing, ie simply hit the return key when asked for a password. A password is much better on a manual backup, though it requires the user to manually type in the password whenever a backup is started.
      5. Send file .ssh/id_rsa.pub and computer name to backup server admin
  7. do a test ssh connection to backup server (it will fail)
  8. For manual backup, edit backup.bat. You should customize the last line in the file, changing the items in all caps
    1. change the word PORTNUMBER to the actual port number you are using.
    2. change the servername BACKUP.EXAMPLE.COM' to the server name of your backup server
    3. change the phrase FULL PATH ON SERVER to reflect where the backup should be stored. This is server dependant, ie defined by the installation of the backup scripts on the server. On a default install, it is /home/backups/my name where my name is the name the server is set up to receive from, ie the client computer name.
  9. For automated backup, edit the file backup.pl and modify the variables at the beginning of the file to reflect your setup.
  10. run a test backup
  11. remove the flag --dry-run to do a real backup
  12. manual backup configuration done. automated backup configuration continues.
  13. Create a schedule for backup
    1. To open Scheduled Tasks, click Start | All Programs | Accessories | System Tools | Scheduled Tasks | Add Scheduled Task
    2. Choose Browse to find backup.pl, and point your scheduled backup to that.

Note: DOS has a very limited amount of space for the command buffer. As such, you can not extend the command line out to over 255 character (I believe). Thus, the whole rsync command, start to finish, must fit into that line length. If you want to back up multiple directories, it is better to have multiple commands (though that will mean the user has to enter the public key passphrase multiple times).