rsync
Overview
rsync synchronizes files and directories locally or over SSH. It transfers only differences, preserves attributes, and is the standard tool for backups and deploys.
Syntax
rsync [options] SOURCE... DESTTrailing slashes matter: src/ copies contents; src copies the directory itself.
Common Options
| Option | Description |
|---|---|
-a |
Archive: -rlptgoD |
-v |
Verbose |
-z |
Compress during transfer |
-P |
--partial --progress |
-n / --dry-run |
Simulate |
-e ssh |
Remote shell |
--delete |
Remove dest files not in source |
--exclude=PAT |
Exclude |
-x |
One filesystem |
--bwlimit=RATE |
Throttle |
Safety
--delete can wipe destination files. Always -n first. Know whether trailing / is intended.
Examples with Explanations
Local copy
rsync -aHAX --info=progress2 /src/project/ /backup/project/Dry-run remote backup
rsync -anv -e ssh /var/www/ user@server:/backups/www/
rsync -av -e ssh /var/www/ user@server:/backups/www/Mirror with delete
rsync -a --delete --exclude '.git' ./site/ user@server:/var/www/site/Resume-friendly large copy
rsync -aP large.iso user@server:/data/Pull from remote
rsync -av user@server:/var/log/app/ ./logs/