12

I have SSH access to the both servers, one of them is empty. How can I move site directory from old server to new server via SSH connection?

PS: On both servers is unix

ajile
  • 243
  • 2
  • 3
  • 7

3 Answers3

16

My favorite is rsync. It is smart enough to copy only what has to be copied (i.e. changed or new).

rsync -avz /source/path user@desthost:/destination/path/

Note the final / at the end to ask rsync to copy inside that path (not over it).
rsync takes care of managing the ssh connection for you. The avz (typical) options ask rsync to use the archive (tar) mode, in order to copy recursively, and keep as much as possible date and user values. The v option is verbose to show you what is currently happening. The z option will zip (compress) the transfer to hopefully save time and bandwidth.

rsync is very powerful and is used by most professionals, however you may want to test it first using non valuable data to ensure the path and options match the requirements.

If you need to use rsync via SSH on a non-standard port like 2222, you can use the following command (see this article):

rsync -avz -e 'ssh -p 2222' /source/path user@desthost:/destination/path/
abd3721
  • 103
  • 3
Déjà vu
  • 5,408
  • 9
  • 32
  • 52
  • I think rsync is a better solution than ssh for the reason that ring0 has given, i.e it only copies what needs to be copied. So if you need to do this more than once rsync will give you an advantage over straight scp. – Jason Tan Aug 25 '10 at 15:22
  • 1
    rsync is definitly the tool. But about the trailing slash: this is important for the source not for the destination: rsync -a /src/ /dest copies everything under src in dest, rsync -a /src /dest copies src and everything under it to dest/src/. – Oscar Aug 25 '10 at 16:02
0

You're looking for a tar pipe.

Ignacio Vazquez-Abrams
  • 45,019
  • 5
  • 78
  • 84
0

I wrote an well working answer in another question. It uses SSH-Agent to move a mysql dump: Fastest way to move multiple databases to a new server

Combine this with the answer of jscott

krissi
  • 3,317
  • 1
  • 18
  • 22