Remote Linux server to remote linux server dir copy. How? [closed]
What is the best way to copy a directory (with sub-dirs and files) from one remote Linux server to another remote Linux server? I have connected to both using SSH client (like Putty). I have root access to both.
Solution 1:
There are two ways I usually do this, both use ssh:
scp -r sourcedir/ [email protected]:/dest/dir/
or, the more robust and faster (in terms of transfer speed) method:
rsync -auv -e ssh --progress sourcedir/ [email protected]:/dest/dir/
Read the man pages for each command if you want more details about how they work.
Solution 2:
I would modify a previously suggested reply:
rsync -avlzp /path/to/sfolder [email protected]:/path/to/remote/dfolder
as follows:
-a (for archive) implies -rlptgoD so the l and p above are superfluous. I also like to include -H, which copies hard links. It is not part of -a by default because it's expensive. So now we have this:
rsync -aHvz /path/to/sfolder [email protected]:/path/to/remote/dfolder
You also have to be careful about trailing slashes. You probably want
rsync -aHvz /path/to/sfolder/ [email protected]:/path/to/remote/dfolder
if the desire is for the contents of the source "sfolder" to appear in the destination "dfolder". Without the trailing slash, an "sfolder" subdirectory would be created in the destination "dfolder".
Solution 3:
rsync -avlzp /path/to/folder [email protected]:/path/to/remote/folder
Solution 4:
scp -r <directory> <username>@<targethost>:<targetdir>
Solution 5:
Log in to one machine
$ scp -r /path/to/top/directory user@server:/path/to/copy