Monday, 1 March 2010

Copying a Folder to and from Windows with rsync

Suppose you’ve got a NAS, or *nix box which has an rsync daemon running on it.

You’ve also got the convenient cwrsync bundle installed on your Windows box.

Now you want to be able to copy all the files in a folder on the windows box, say:

C:\foo\my spaced path\things

to and from the rsync module on your server.

To copy from the server to Windows

"c:\Program Files (x86)\cwRsync\bin\rsync.exe" -v -r -c rsync://@server/module /cygdrive/c/foo/"my spaced path"/things

This assumes the default installation path for cwrsync, you should drop the “ (x86)” if you’re not running on a 64-bit version of Windows.

The parameters include

  • -v for verbose
  • -c to always test file checksums rather than timestamps. If you’re happy that the timestamps are reliable, replace it with a –t to use (and copy) the timestamps.
  • -r for recursive.

The path on the Windows box has been munged to cygwin’s standards to look like a *nix path. 

  • The slashes all go forwards
  • The /cygdrive/c is the equivalent of “C:”
  • Any directory names that have spaces need a quote around their name, not around the path as a whole.

The path to the server specifies the rsync protocol, and the server name and module (like a share name in Windows/Samba/CIFS). I’ve not shown any user or password specification.

To copy from Windows to the server

"c:\Program Files (x86)\cwRsync\bin\rsync.exe" -v -c -r --no-perms --chmod=ugo=rwX /cygdrive/c/foo/"my spaced path"/things/ rsync://@server/module

Note the trailing slash after the Windows folder name. Without that, you’ll get a subfolder called “things” created under the module on your server.

I added the no-perms and chmod parameters because otherwise the ACLs that rsync placed on the copied files gave no rights to anyone.