Written by
akendo
on
3 minutes reading
with tags: bash console cp debian gentoo gernal howto linux scp system
3 minutes reading
with tags: bash console cp debian gentoo gernal howto linux scp system
rsync - the better scp
Regard this Post, i make this post. First: scp is great. But i recomand to use rsync instead. It has replace for me also the cp and scp command. Why? Simple rsync is more powerful. I allows me dry runs, then it's very efficient. File moves should be easy and save. That is what rsync does! It's some tool that need a little bit use. rsync is simply for backups, but that is almost the same coping around like the cp/scp.Some examples
Start with a dry run:rsync -nv somefile user@server:/path/to/copy
This will connect as user to server. Then show what he will copying, That is very useful to check when your running recusive. A / makes a lots of different in the path showing.
rsync -rnv somefolder user@server:/path/to/copy/
somefolder/a
rsync -rnv somefolder/ user@server:/path/to/copy/
./a
Problems with scp
You have a big file you want to push to your vServer, you don't want fill up all of your bandwidth so you set a set a limit of for bw. Your using scp -l, so we setting a limit of 150 kB/sscp -l 150 somefile user@server:/path/to/save
I got some wired problem with the scp limiter. Sometimes it works, sometimes it didn't. Why?
That is the version with rsync
rsync --bwlimit 150 somefile user@server:/path/to/save
It's basically the same, but it worked reliable on rsync.
But when the copy process stops before your done (lost connection for example) you have to start over again. . The solution is using inplace option in rsync:
inplace copy:
rsync is able to copy a file on inplace. This very important you are able to suspend a copy process.
rsync --inplace somefile user@server:/path/to/save
(Lost Connection)
rsync --inplace somefile user@server:/path/to/save
Keeping the rights, scp will copy and place with the default umask of the system user. rsync allow you to keep the right permission with -a option
ls -l somefile
-rw-r--r-- 1 akendo akendo 347 4. Dez 16:21 somefile
scp -a somefile user@server:/path/to/save
user@server: ls -l somefile
-rw-r----- 1 user user 347 Mar 7 00:19 somefile
rsync -a somefile user@server:/path/to/save
user@server: ls -l somefile
-rw-r--r-- 1 akendo akendo 347 4. Dez 16:21 somefile
As you can see, lose the User/Groups , Time Stamp will be lost with scp. In rsync this will remain the same.
Using Humanreadable
rsync -vh somefile user@server:/path/to/copy
somefile
sent 2.02K bytes received 112 bytes 1.42K bytes/sec
total size is 964.25M speedup is 452912.60 (DRY RUN)
Some nice looking example, to clone a folder:
rsync -rauvh /file user@server:/path/to/save
This will copy the folder "file" to "/path/to/save" on the host server as user.
In some other post i show the best way of using it as a backup method.
Feel free to add comments or improve this post.