rsync Guide 2 min read by syncopio Team

The rsync Trailing Slash Trap: One Character That Wipes Your Data

The #1 rsync mistake: a trailing slash plus --delete can erase your entire backup. Learn the difference between /path and /path/ before it's too late.

If rsync has a single footgun, this is it. One character — a trailing / — changes what gets copied. Combine that with --delete, and you can wipe your destination clean.

I’ve seen this happen in production twice. Both times the admin knew exactly what trailing slashes did — they just forgot which convention their last script used.

The difference

Without trailing slash — copies the directory itself:

rsync -av /srv/data /backup/
# Result: /backup/data/file1.txt, /backup/data/file2.txt

With trailing slash — copies the contents:

rsync -av /srv/data/ /backup/
# Result: /backup/file1.txt, /backup/file2.txt

Both are fine. The danger is switching without noticing.

Where it gets dangerous

Say your backup already has files from a previous run with the no-slash form:

/backup/data/file1.txt
/backup/data/file2.txt

Now you run the with-slash version plus --delete:

rsync -av --delete /srv/data/ /backup/

Data loss

rsync sees /backup/data/ as an “extra” directory that doesn’t exist in the source contents. With --delete, it removes the entire /backup/data/ tree — your previous backup is gone.

Safe habits

  1. Pick one convention and stick with it. Most admins prefer the trailing slash (copy contents). Just be consistent.
  2. Always dry-run before --delete. Run rsync -avn --delete /srv/data/ /backup/ first. No exceptions. Make it muscle memory.
  3. Use --backup-dir as a safety net. Adding --backup-dir=/backup/.rsync-deleted/ saves anything --delete would remove, so you can recover from mistakes.
  4. Make it an alias. Add this to your .bashrc so dry-run is the default:
alias rsyncd='rsync -avn --delete'
# Usage: rsyncd /srv/data/ /backup/   (shows what WOULD happen)

Tip

If you use --delete without --dry-run first, you will eventually lose data. Not if. When.

For 30 more rsync commands organized by use case, see the complete rsync guide. And if trailing slashes are the kind of footgun that makes you want a GUI, rclone and Robocopy handle the source/destination distinction differently.

Ready to simplify your migrations?

See how syncopio can save you hours on every migration project.

Request a Demo