One slash, two backup layouts: rsync projects vs projects/

One slash, two backup layouts: rsync projects vs projects/

●2 ●39 ●103
calendar_today • schedule1 min read

Two rsync commands one character apart both exit 0 and put the same file in different places. I ran them side by side in a scratch directory, rsync 3.5.0, with one file at projects/app/main.sh:

$ rsync -a projects backup-a/
$ find backup-a -type f
backup-a/projects/app/main.sh
$ rsync -a projects/ backup-b/
$ find backup-b -type f
backup-b/app/main.sh

Without the slash, rsync copies the directory itself. With it, rsync copies the contents. The source's slash decides the layout; the destination's barely matters. Neither result is wrong, and the backup job reports success either way. The mismatch shows up when something reads the backup by path: a restore script looking in backup/app while the files sit in backup/projects/app.

Add --delete and the slash also decides which trees get compared. I moved main.sh out of the source and previewed the mirror: --dry-run alone printed nothing and exited 0, while --dry-run -v showed deleting app/main.sh. A dry run without -v proves nothing.

For the remote half, use key auth with ssh -o BatchMode=yes, so a cron job with no one to type a password fails fast instead of hanging. The hardened script, the cron line and the --link-dest snapshot variation are in the rsync remote backup snippet.


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 #devops & #linux deep dives?

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

2 Comments

0 votes
0

More Posts

The cleanup failed on the night there was nothing to clean

BashSnippets - Dec 2

My hung process had no file open. It was stuck inside open().

BashSnippets - Dec 1

StarlingX 13.0 Turns Two Edge Upgrades Into One Reboot. Test the Targets Yourself.

Tom Smithverified - Nov 24

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

A deploy guard that passes with no token

BashSnippets - Nov 24
chevron_left
4k Points • 144 Badges
North America • bashsnippets.xyz
79Posts
43Comments
14Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Commenters (This Week)

12 comments
2 comments

Contribute meaningful comments to climb the leaderboard and earn badges!