Data movement¶
Copying files with scp¶
Copying files between different UNIX-like systems can be done with the scp
command. This command which stands for Secure Copy Protocol, allows you to
transfer files between a local host and a remote host or between two remote
hosts. The basic syntax of the scp command is the following
scp <origin-path> <destination-path>
scp <origin-path> [user@]host:<destination-path>
scp [user@]host:<origin-path> <destination-path>
where <origin-path> is the path to the file you want to copy to the
destination defined by <destination-path>.
The command to copy a file from a local machine to a remote host is
and correspondingly the syntax to copy files from a remote machine to a local machine is
Copying files with rsync¶
The rsync tool, which stands for Remote Sync, is a remote and local file
synchronization tool. It has the advantage of minimizing the amount of data
copied by only moving the portions of files that have changed. The advantages
over scp are
- it allows synchronization,
scpwould copy and transfer everything, whilersyncwill only copy and transfer the modifications - better for the transfer of large files as
rsyncwill save progress, so if the transfer is interrupted it can be resumed at the same point
The basic syntax of the rsync command is the following
rsync <options> <origin-path> <destination-path>
rsync <options> <origin-path> [user@]host:<destination-path>
rsync <options> [user@]host:<origin-path> <destination-path>
Below are some useful options to use with rsync:
- archive mode with the
-aor--archiveoption. This option tellsrsyncto syncs directories recursively, transfer special and block devices, preserve symbolic links, access permissions and time stamps - compresses the data with the
-zor--compressoption. With this optionrsyncwill compress the data as it is sent to the destination machine. - to keep the partially transferred files, use the
--partialoption. It is useful when transferring large files over slow or unstable network connections. - if your goal is to achieve mirroring use the
--deleteoption. When this option is used,rsyncdeletes extraneous files from the destination location.