S/dailyman

RSYNC(1)filesNo. 001

rsync

Copy only what changed, locally or over SSH

Description

rsync compares source and destination and transfers just the differences, so a repeat run of a large copy takes seconds. It also preserves permissions and timestamps, and it can pick up an interrupted transfer where it stopped.

Examples

  1. Mirror a build directory to a server

    rsync -avz --delete ./dist/ deploy@example.com:/var/www/site/
    -a
    Archive mode. Recurses and keeps permissions, timestamps, symlinks, owner and group.
    -v
    Lists each file as it's transferred.
    -z
    Compresses data in transit, which helps over slow links.
    --delete
    Removes files from the destination that no longer exist in the source.

    The trailing slash on ./dist/ matters. It copies the contents of the directory, while ./dist would create site/dist.

  2. See what would happen before committing to it

    rsync -avz --delete --dry-run ./dist/ deploy@example.com:/var/www/site/
    -avz
    Archive mode, verbose and compressed, as above.
    --delete
    Includes planned deletions in the report.
    --dry-run
    Reports what would change without touching anything. -n is the short form.
  3. Resume a big download and watch its progress

    rsync -a --partial --info=progress2 backup@example.com:/data/dump.sql.gz .
    -a
    Archive mode.
    --partial
    Keeps a partly transferred file, so the next run continues it instead of starting over.
    --info=progress2
    Shows one overall progress line for the whole transfer rather than one per file.

Tip

Always do a --dry-run first when --delete is involved. One wrong path can empty a directory.