[Awesome Remote] rsync -- a fast, versatile, remote (and local) file-copying tool

rsync

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

Rsync finds files that need to be transferred using a lqquick checkrq algorithm (by default) that looks for files that have changed in size or in last-modified time. Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file’s data does not need to be updated.

Some of the additional features of rsync are:

  • support for copying links, devices, owners, groups, and permissions

  • exclude and exclude-from options similar to GNU tar

  • a CVS exclude mode for ignoring the same files that CVS would ignore

  • can use any transparent remote shell, including ssh or rsh

  • does not require super-user privileges

  • pipelining of file transfers to minimize latency costs

  • support for anonymous or authenticated rsync daemons (ideal for mirroring)

Synopsis

1
2
3
4
5
6
7
8
9
Local:  rsync [OPTION...] SRC... [DEST]
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

Usages with just one SRC arg and no DEST arg will list the source files instead of copying.

Usages

Keep Sync

Keep Keep SRC and DEST in sync

1
$ rsync -aPrvz --delete SRC DEST

Use SSH custom port

Use SSH custom port 22222.

1
$ rsync -e 'ssh -p 22222' SRC DEST

Options Summary

Here is a commmon summary of the options available in rsync. Please refer to the detailed description below for a complete description.

  • -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)

  • -b, --backup make backups (see --suffix & --backup-dir)

  • -c, --checksum skip based on checksum, not mod-time & size

  • –delete delete extraneous files from dest dirs

  • -e, --rsh=COMMAND specify the remote shell to use

  • –exclude=PATTERN exclude files matching PATTERN

  • –exclude-from=FILE read exclude patterns from FILE

  • -h, --human-readable output numbers in a human-readable format

  • –include=PATTERN don’t exclude files matching PATTERN

  • –include-from=FILE read include patterns from FILE

  • –link-dest=DIR hardlink to files in DIR when unchanged

  • -n, --dry-run perform a trial run with no changes made

  • -p, --perms preserve permissions

  • –progress show progress during transfer

  • -r, --recursive recurse into directories

  • –remove-source-files sender removes synchronized files (non-dir)

  • –suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)

  • -u, --update skip files that are newer on the receiver

  • -v, --verbose increase verbosity

  • -z, --compress compress file data during the transfer

See Options Summary | rsync(1) - Linux man page - https://linux.die.net/man/1/rsync to learn more.

References

[1] rsync(1) - Linux man page - https://linux.die.net/man/1/rsync

[2] 10 Practical Examples of Rsync Command in Linux - https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/