Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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

rsync -av /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 av (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.

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.

share|improve this answer
    
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
    
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

You're looking for a tar pipe.

share|improve this answer

You can use scp to copy a directory from one server to the other. First ssh into the source server and issue the following command:

scp -r /some/local/path username@destination:/some/remote/path

To remove the source directory:

rm -r /some/local/path

share|improve this answer
    
This is almost successfully executing, but on my SSH port is 222, how can I assign port? –  HWTech Aug 25 '10 at 14:38
    
scp -P 666 -r /some/local/path username@destination:/some/remote/path –  krissi Aug 25 '10 at 14:40
    
@HWTech: scp -P 222 -r /some/local/path username@destination:/some/remote/path –  jscott Aug 25 '10 at 14:45

I wrote an well working answer in another question. It uses SSH-Agent to move a mysql dump: http://serverfault.com/questions/163305/fastest-way-to-move-multiple-databases-to-a-new-server/163320#163320

Combine this with the answer of jscott

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.