rsync --dry-run (-n): Preview Before Deploy
rsync -n performs a trial run that lists every file it would transfer or delete without making any changes.
Before any --delete deploy, a dry run is the cheapest insurance in CI. It catches trailing-slash mistakes and unexpected deletions.
What it does
-n / --dry-run goes through all the motions, computes the file list and the actions, and prints them, but never opens files for writing or deletes anything. Pair it with -v or -i so the output is meaningful. Note that the byte counts in a dry run are estimates, not exact transfer sizes.
Common usage
# Preview a mirroring deploy, including deletions
rsync -avn --delete dist/ user@host:/var/www/app/
# Itemized preview for a compact diff
rsync -ain --delete dist/ user@host:/var/www/app/Reading the output
| Line prefix | Meaning |
|---|---|
| >f+++++++++ | A new file would be transferred |
| >f.st...... | An existing file changes (size/time) |
| cd+++++++++ | A directory would be created |
| deleting path/ | This file would be removed (with --delete) |
| *deleting | Same, shown when --delete is active |
In CI
A useful pattern: run a dry run, grep its output for "deleting", and fail the job if the count is unexpectedly high. This catches the empty-build case where a broken step would otherwise mirror an empty dist/ and wipe the live site.
Common errors in CI
A dry run can still error on connection or permission problems (it connects for real), so a clean dry run also validates SSH and known_hosts. If the dry run prints "deleting" for files you meant to keep, fix your --exclude / protect rules before the real run.