Last reviewed: October 2026. Commands below use rsync’s upstream option definitions. The small local dry-run, copy and restore example was checked with rsync 3.2.3 on an isolated Linux fixture; it is not a test of a particular Debian production system.
rsync is useful when you need to copy a directory again, see proposed changes, and verify a restore. The slash at the end of a source directory matters: source/ copies its contents into the destination, while source creates an extra directory level.
Install and inspect the tool
sudo apt update
sudo apt install rsync
rsync --version
Check the installed version on both ends of a remote transfer. For option details, use man rsync or the upstream rsync manual.
Run a small backup and restore drill
These commands create only test files under a directory in your home folder. Choose an empty path you control:
mkdir -p ~/rsync-demo/source ~/rsync-demo/backup ~/rsync-demo/restore
printf 'alpha\n' > ~/rsync-demo/source/note.txt
printf 'bravo\n' > ~/rsync-demo/source/config.ini
rsync -aivn ~/rsync-demo/source/ ~/rsync-demo/backup/
rsync -aiv ~/rsync-demo/source/ ~/rsync-demo/backup/
rsync -aiv ~/rsync-demo/backup/ ~/rsync-demo/restore/
-n is a dry run, -i itemizes changes, -v lists activity and -a enables archive mode. Review the dry run before making the copy. The destination should receive note.txt and config.ini, not another source directory.
Verify the restored file contents:
(cd ~/rsync-demo/source && sha256sum note.txt config.ini)
(cd ~/rsync-demo/restore && sha256sum note.txt config.ini)
The two pairs of hashes should match. In the local fixture, both files copied and restored with matching SHA-256 values. The example does not cover ownership, ACLs, extended attributes or an interrupted transfer.
Adapt the pattern to a real backup
rsync -aivn /srv/app/data/ /mnt/backup/app-data/
rsync -aiv /srv/app/data/ /mnt/backup/app-data/
Replace both paths with your actual source and mounted backup destination. Confirm the destination filesystem is mounted before running the real command; otherwise files may land on the root filesystem. Archive mode preserves common permissions, timestamps, ownership and symlinks as far as the account and destination filesystem allow. It does not, by itself, preserve ACLs, extended attributes or hard-link relationships; review -A, -X and -H if those matter to your restore.
This command copies changed content but does not make historical versions. A deleted or corrupted source file can eventually be reflected in a synchronized destination. Use retention and a separate restore drill for an actual backup policy; the surviving backup and recovery overview covers the wider planning questions.
Remote transfer over SSH
rsync -aivn /srv/app/data/ user@example-host:/srv/backup/app-data/
rsync -aiv /srv/app/data/ user@example-host:/srv/backup/app-data/
For a nondefault SSH port, add -e 'ssh -p 2222'. The remote account needs write access to the destination, and rsync must be available on the remote system. Use --exclude='*.tmp' only after checking that it excludes exactly what you intend. -z enables transfer compression, which may help on a slow link but can waste CPU for already compressed data.
Deletion and interrupted transfers
--delete removes destination files that are absent from the source within the synchronized tree. It can turn a path mistake into data loss. If you need a mirror, inspect an itemized dry run with the exact final paths and exclusions before adding it to the real command. Keep an independent retained backup rather than relying on a mirror alone.
--partial can retain an incomplete transfer for resumption; review the upstream manual for the related --partial-dir behavior before using it in automation. A restarted transfer still needs verification. For a one-off copy, scp may be simpler; it also supports compression with -C in the OpenSSH scp manual. Rsync’s advantage here is repeatable synchronization and change preview, not a blanket speed guarantee.


