'How does `scp` differ from `rsync`?
An article about setting up Ghost blogging says to use scp
to copy from my local machine to a remote server:
scp -r ghost-0.3 root@*your-server-ip*:~/
However, Railscast 339: Chef Solo Basics uses scp
to copy in the opposite direction (from the remote server to the local machine):
scp -r [email protected]:/var/chef .
In the same Railscast, when the author wants to copy files to the remote server (same direction as the first example), he uses rsync
:
rsync -r . [email protected]:/var/chef
Why use the rsync
command if scp
will copy in both directions? How does scp
differ from rsync
?
Solution 1:[1]
rysnc can be useful to run on slow and unreliable connections. So if your download aborts in the middle of a large file rysnc will be able to continue from where it left off when invoked again.
Use rsync -vP username@host:/path/to/file .
The -P option preserves partially downloaded files and also shows progress.
As usual check man rsync
Solution 2:[2]
Difference b/w scp and rsync on different parameter
1. Performance over latency
scp
: scp is relatively less optimise and speedrsync
: rsync is comparatively more optimise and speed
2. Interruption handling
scp
: scp command line tool cannot resume aborted downloads from lost network connectionsrsync
: If the above rsync session itself gets interrupted, you can resume it as many time as you want by typing the same command. rsync will automatically restart the transfer where it left off.
http://ask.xmodulo.com/resume-large-scp-file-transfer-linux.html
3. Command Example
scp
$ scp source_file_path destination_file_path
rsync
$ cd /path/to/directory/of/partially_downloaded_file
$ rsync -P --rsh=ssh [email protected]:bigdata.tgz ./bigdata.tgz
The -P
option is the same as --partial --progress
, allowing rsync to work with partially downloaded files. The --rsh=ssh
option tells rsync to use ssh as a remote shell.
4. Security :
scp is more secure. You have to use rsync --rsh=ssh
to make it as secure as scp.
man document to know more :
Solution 3:[3]
One major feature of rsync
over scp
(beside the delta algorithm and encryption if used w/ ssh) is that it automatically verifies if the transferred file has been transferred correctly. Scp will not do that, which occasionally might result in corruption when transferring larger files. So in general rsync is a copy with guarantee.
Centos manpages mention this the end of the --checksum
option description:
Note that rsync always verifies that each transferred file was correctly reconstructed on the receiving side by checking a whole-file checksum that is generated as the file is transferred, but that automatic after-the-transfer verification has nothing to do with this option’s before-the-transfer “Does this file need to be updated?” check.
Solution 4:[4]
There's a distinction to me that scp
is always encrypted with ssh (secure shell), while rsync
isn't necessarily encrypted. More specifically, rsync
doesn't perform any encryption by itself; it's still capable of using other mechanisms (ssh for example) to perform encryption.
In addition to security, encryption also has a major impact on your transfer speed, as well as the CPU overhead. (My experience is that rsync
can be significantly faster than scp
.)
Check out this post for when rsync
has encryption on.
Solution 5:[5]
scp is best for one file.
OR a combination of tar
& compression for smaller data sets
like source code trees with small resources (ie: images, sqlite etc).
Yet, when you begin dealing with larger volumes say:
- media folders (40 GB)
- database backups (28 GB)
- mp3 libraries (100 GB)
It becomes impractical to build a zip/tar.gz file to transfer with scp at this point do to the physical limits of the hosted server.
As an exercise, you can do some gymnastics like piping tar
into ssh
and redirecting the results into a remote file. (saving the need to build
a swap or temporary clone aka zip or tar.gz)
However,
rsync simplify's this process and allows you to transfer data without consuming any additional disc space.
Also,
Continuous (cron?) updates use minimal changes vs full cloned copies speed up large data migrations over time.
tl;dr scp
== small scale (with room to build compressed files on the same drive) rsync
== large scale (with the necessity to backup large data and no room left)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sid Kshatriya |
Solution 2 | Michael P |
Solution 3 | |
Solution 4 | |
Solution 5 | copremesis |