14

Let say that I have 2 machines:

  • local (centos)
  • remote on IP: 123.123.123.123 ssh port 456 (ubuntu server)

and I want to synchronize my remote folder /home/wolfy/py with my local folder /home/cavo/python.

Can this be done with rsync? Can you give me an example?

Wolfy
  • 7,790
  • 12
  • 35
  • 43

2 Answers2

18

Try this:

rsync -ave 'ssh -p 456' /home/cavo/python/ wolfy@123.123.123.123:/home/wolfy/py/ 

Note that the trailing slashes on the paths are very important, they signal that you are syncing a directory to a directory. The -e switch helps rsync know it is going to be using ssh transport, and while we are specifying the transport we also tell ssh what port it's going to have to use to talk to the remote site. Then the username and remote host ip are specified as part of the target.

Caleb
  • 565
  • 11
  • 19
  • works perfectly :) thanks for a detailed explain! – Wolfy Aug 02 '11 at 08:31
  • 1
    Trailing slash is only important on the source, not on destination. – enzotib Aug 02 '11 at 09:22
  • 3
    I'm confused, doesn't this copy from local to remote? According to http://stackoverflow.com/a/9090859/277267 it's the other way around. – Daniel F May 12 '17 at 14:18
  • @DanielF Yes it does. I suspect that's what the OP meant by his question. Note his use of "with" and the unconventional wording. If you really want to sync a remote dir _to_ a local one you can reverse the arguments. Source first then target. – Caleb May 12 '17 at 14:27
  • @Caleb Yes, but title says "from remote to local". – Daniel F May 12 '17 at 14:29
  • @DanielF note the OP commented above to say this worked as expected. The issue was how to tell rsync about the ssh parameters not which direction to sync. The question us unclearly worded but it doesn't matter which is local vs remote, source path comes first and target second. They can even both be remote. – Caleb May 12 '17 at 14:36
0

For those of us that like the verbose solution.

sudo rsync --ignore-existing --recursive username@domain:/location/to/files/ files/

Remember you always have a man with you.

$ man rsync
Rick
  • 269
  • 3
  • 7