tags:

views:

908

answers:

2

I have a server where I store data from Mac A and Mac B.

I use rsync to keep the files updated between my Macs.

I run the following code unsuccessfully

#!/bin/zsh

#    to copy files from my server to my folder
rsync -Pav $Masi:~/private/ ~/Dropbox/Courses/math/

#    to  copy files from my folder to my server
rsync -Pav ~/Dropbox/Courses/math $Masi:~/private/

I get the following error message

ssh: connect to host  port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: unexplained error (code 255) at io.c(600) [receiver=3.0.5]
ssh: connect to host  port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.5]

I have ssh keys in place so the connection should work, since I can use scp without problems.

How can you use rsync between my server and one of my Macs?

+1  A: 

Check "$Masi". Is that the hostname you are trying to reach?

Try the following command to debug it:

rsync -e 'ssh -v' -Pav $Masi:~/private/ ~/Dropbox/Courses/math/
Casey
@Casey: $Masi is system var with my login name and ip address to the server in the form: [email protected]. Your command seems to work: I get the following output: http://dpaste.com/40225/ . It seems that the option "-e 'ssh -v'" must be used.
Masi
@Casey: What does the option "-e 'ssh -v" do? I know that -v means verbosely and -e to specify a remote shell, but that does tell me much in this case.
Masi
+1  A: 

I used to do a lot of this. Just ran a test, a few suggestions.

  1. Spell out your entire user@host pattern
  2. Run the ssh connection sans the rsync first, you may need to first approve your fingerprint
  3. You do not seem to pass a flag to protect extended attributes, this can yield broken files on OS X. If you do not need resource forks, you are OK, but most of the time you do need them.

My test case:

$rsync -Pav ~/Desktop/ [email protected]:~/rsyc-test

In that case, all the files within ~/Desktop were copied to the remote host, in my home dir. Since the directory 'rsyc-test' did not exist, it was made for me. I had a .app on my Desktop, it made it over, surprisingly, it works. Even some .webloc files made it and appear to work, though I do not trust it.

I would strongly suggest adding in the -E flag

  -E, --extended-attributes
         Apple specific option  to  copy  extended  attributes,  resource
         forks,  and  ACLs.   Requires at least Mac OS X 10.4 or suitably
         patched rsync.

I ran a new test, moved a Interarchy bookmark to my desktop, I know for a fact these break if they are copied sans resource forks. Running without the -E versus with the -E, there is a difference of 152 bytes in xfered data. The first file on the remote machine did not work, the second transfered file did work.

I can not help but notice in your example one of your paths is ~/Dropbox so this may all not matter, since DropBox, the app, does not at all support resource forks currently, though I hear there are plans to in the future.

You also are not sending in the --delete flag, if your end goal is a mirror of your data, you are not getting that, if your end goal is backups that continually grows, keeping everything that was ever on the source, the lack of --delete is good.

Other notes:
You can exclude those silly .DS_Store files --exclude '.DS_Store'

You can also set rsync up in a way to be a true mirror, so you would not need to run your other command, see the man page for details.

My final working command to shove the Desktop of my laptop to a remote machine:

$rsync -PEav --delete --exclude '.DS_Store' ~/Desktop/ [email protected]:~/rsycn-test