Skip to content

Sync Windows Directories with Linux

Prompt
Using cwRsync on Windows and rsync on Linux you can seamlessly mirror directories on two or more computers. In my case, because of iTunes and an iPod, I’m forced to keep a copy of my library on a desktop computer and on my media server. Yes, I’m aware of mt-daapd and I already have it working; unfortunately that’s not a solution in this case.

What you’ll need:

  • cwRsync, download and install on your Windows computer.
  • rsync, install and make sure it’s running on your linux box
  1. Open a command prompt Start -> Run -> cmd
  2. Add cwRsync to your windows ‘path’ so that you can run it. Just type this at the command line: path = %PATH%;c:\program files\cwRsync\bin
  3. Create the Key ssh-keygen -f /cygdrive/c/ssh_key -t rsa -N '' (please note; this creates your keys in the C: directory)
  4. Copy your public key to the server: rsync -e ssh /cygdrive/c/ssh_key.pub username@serverAddress:~/.ssh/authorized_keys You’ll need to enter your username and password
  5. Copy your public key into your ssh authorized_keys file: ssh username@serverAddress cat ssh_key.pub >> .ssh/authorized_keys
  6. Test your backup: rsync -avz -e "ssh -i /cygdrive/c/ssh_key" "Desktop" username@serverAddress:folderName This should copy everything on your desktop to the directory named folderName on the server
  7. Download and edit the sample batch file
  8. Once you’ve edited the sample batch file store it temporarily in the C: directory and run the batch file manually c:\data-backup.bat
  9. Set your batch file to run automatically: Go to Start -> Control Panel -> Scheduled Tasks and click ‘Add a Scheduled Task’. Next -> Browse. Set the schedule and enter your account password to allow the software to run.

I’m successfully using the sample batch file to mirror a music directory on my media server with a desktop computer.

While music is the subject of our conversation; give Chris And The Other Girls a listen. They’re less popular than they deserve to be. I particularly like track 01 Let Go, download it here.

Okay, looks like there’s a freely available open source, GUI wrapper for rsync. Give it a try and let me know what you think. Download and documentation can be found here

Update:
Awesome/Useful comments be sure to read them.
Sorry if you’re comments don’t show up for a while due to spam I have to curate.

If you’re having problems with Windows 7 being unable to create a .ssh directory (see Richard’s problem below). It looks like has a work around.

11 Comments

  1. Paul wrote:

    Hey, very nice article!

    Wednesday, April 4, 2007 at 2:34 pm | Permalink
  2. Alvin wrote:

    You skipped a VERY key step, makes the directions impossible to perform as is.

    Windows does not have SCP and you don’t include any clue where this comes from.

    Friday, April 6, 2007 at 12:51 am | Permalink
  3. admin wrote:

    Thanks Alvin, I didn’t want to write over any authorized key files one might already have in the .ssh directory on the server. I’ve updated this how-to. Now your “ssh_key.pub” should be copied over to the server as “authorized_keys” in the .ssh directory.

    Please let me know if you have any other problems.

    Friday, April 6, 2007 at 9:21 am | Permalink
  4. Stephan Bayer wrote:

    This is awesome. Thanks for sharing.

    Step 5 is redundant though. You just need step 4.

    Also if you are running Windows Server or something you have to be careful of the Program files directory in the batch file:

    SET CWRSYNCHOME=C:\Program Files (x86)\cwRsync\

    Friday, June 12, 2009 at 10:30 am | Permalink
  5. ilissan wrote:

    Nice tut, thanks!
    IMPORTANT to know that in the Batch example file if you are running it from scheduled task you should change home directory from
    SET HOME=%HOMEDRIVE%%HOMEPATH%
    to
    SET HOME TO %USERPROFILE%
    in order to point to the correct path.

    Thursday, January 28, 2010 at 5:56 am | Permalink
  6. ilissan wrote:

    correction:

    SET HOME=%USERPROFILE%

    Thursday, January 28, 2010 at 5:57 am | Permalink
  7. abenderx wrote:

    Great article – I am having one issue someone might know about here. When I run multiple rsync commands in the same batch file, I get a paasword prompt on the second rsync and onwards. Would the ssh session from the previous line be impacting the key call somehow??

    Tuesday, August 10, 2010 at 12:23 pm | Permalink
  8. abenderx wrote:

    DOH forget it – typo on the remote account O.o I should have waited before I commented lol.

    Tuesday, August 10, 2010 at 12:30 pm | Permalink
  9. Evgeny wrote:

    THANKS!!!

    Tuesday, February 22, 2011 at 4:18 am | Permalink
  10. Richard Minutillo wrote:

    This was very helpful, but running rsync under Windows7 I get something like this:

    Could not create directory ‘/home/me/.ssh’.
    The authenticity of host ‘myhost’ can’t be established.
    RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
    Are you sure you want to continue connecting (yes/no)? yes
    Failed to add the host to the list of known hosts (/home/me/.ssh/known_hosts).

    So Windows7 prevents the creation of any directory whose name starts with the period character. The rsync command itself works once I enter ‘yes’ at the prompts which are coming from ssh, but I cannot execute the command unattended.

    The host is in fact a known host to my windows system, since I can connect with Putty and Filezilla, it’s just that command line ssh cannot create its directory named .ssh. Is there a syntax that will allow me to substtute PuTTY for ssh?

    Sunday, February 27, 2011 at 1:07 pm | Permalink
  11. Richard Minutillo wrote:

    Got ssh to work: created the .ssh directory from the command line. No problem.

    Sunday, February 27, 2011 at 1:48 pm | Permalink

3 Trackbacks/Pingbacks

  1. Backup your Mac or PC to DreamHost on Wednesday, April 4, 2007 at 2:02 pm

    [...] In Tech explains how to do the same on Windows with cwRsync (a package of Rsync and [...]

  2. [...] In Tech explains how to do the same on Windows with cwRsync (a package of Rsync and [...]

  3. Opaco » Blog Archive » Disco remoto co Mac en Dreamhost on Sunday, April 8, 2007 at 4:28 pm

    [...] E se alguén quere facer a proba desde o windows, que bote unha ollada acó. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*