rsync's dangerous flags don't fail. They do a different job and exit 0.

rsync's dangerous flags don't fail. They do a different job and exit 0.

●2 ●38 ●102
calendar_today • schedule1 min read

The trap with rsync is that its dangerous flag combinations don't fail — they complete a different operation than the one you intended, and exit 0. --delete makes the destination match the source, so a mistyped or freshly moved source directory means rsync removes everything at the destination and reports success. Your cron log shows a clean run while the backup empties itself. A trailing slash changes the meaning too: /data/ syncs the directory's contents, while /data copies the directory itself into the destination — and on a mirror job, that difference decides what gets compared and what gets deleted.

The defense is previewing every destructive sync before running it live:

rsync -av --delete --dry-run /srv/www/ user@backup:/srv/backup/www/

Read the deleting … lines it prints; only when that list matches your expectations do you remove --dry-run. Note also that excludes take one pattern per flag — --exclude='*.log' --exclude='.git' — because a comma-separated list inside a single flag silently matches nothing.

If you'd rather compose the command with those guardrails enforced — a red warning when --delete is enabled without a dry run, per-pattern quoted excludes, and a live preview of the finished command — I built a visual rsync command builder with delete-flag guardrails that runs entirely in the browser.


I bundled the scripts I copy onto every new server, plus 10 bonus ones, into the Production Bash Toolkit. 30-day refund if it isn't useful.

Want more #linux & #bash deep dives?

Join 6,093+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

How to Back Up and Restore Self-Hosted n8n

floxolab - Oct 12

What Security Teams Want From AI Agents Before They Let Them Act Alone

Tom Smithverified - Nov 18

AI Agents for Business: What They Actually Do (and 3 Ways to Use Them)

floxolab - Nov 3

A deploy guard that passes with no token

BashSnippets - Nov 24

Bash exit codes 0-255: what they mean and how to write the handler

BashSnippets - May 6
chevron_left
3.8k Points • 142 Badges
North America • bashsnippets.xyz
79Posts
38Comments
14Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!