Back to the command reference

rsync

NetworkAdvanced In real Linux

Sync files efficiently (only what changed)

Name: rsync = remote sync

This command needs a real Linux system; you can practise it in real Linux mode.

Description

rsync synchronises files locally or with remote hosts. Its strength is incremental transfer: only changed files, even only changed parts of files, are sent, so repeat syncs are fast. Used for backups, deployments and mirrors.

Mind the trailing slash: src/ syncs the directory's contents, src the directory itself.

Syntax

rsync [OPTION]... SOURCE DEST

Common options

-a / --archiveArchive: recursive, keep permissions and times
-r / --recursiveCopy directories recursively (part of -a)
-v / --verboseVerbose
-z / --compressCompress during transfer
-h / --human-readableShow sizes with K, M and so on
-PShow progress and keep partly sent files (to resume)
--progressShow progress for each file
-n / --dry-runDry run
--deleteDelete extra files on the destination
--exclude PATTERNSkip files matching PATTERN, e.g. --exclude=".git"
--include PATTERNWith --exclude: send these anyway
-u / --updateDo not overwrite files that are newer on the destination
-c / --checksumDecide by checksum rather than size and time (slower, more exact)
-e / --rsh COMMANDThe remote shell, e.g. -e "ssh -p 2222"
--bwlimit RATELimit the bandwidth, e.g. --bwlimit=1m

Examples

  • $ rsync -avz site/ backup01:/srv/backup/site/

    Sync a directory to backup01; only changes are sent

    Explain
  • $ rsync -av --delete src/ backup/

    Make backup an exact mirror of src

    Explain
  • $ rsync -avn src/ backup/

    Dry run first

    Explain

Related