brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the trailing slash in rsync decides where your files land

Backup
~/tips/tip-shell-rsync-trailing-slash

rsync -a photos/ /backup/ # puts the contents straight in /backup/

With a slash on the source rsync copies the contents; without it, the folder itself.

One character, two very different results. This is the rsync detail that bites everybody once.

Without a trailing slash on the source, rsync copies the directory itself. With a slash, it copies only what is inside. The man page puts it this way: a trailing slash on the source avoids creating an additional directory level at the destination.

rsync -a photos  /backup/    # creates /backup/photos/
rsync -a photos/ /backup/    # puts the contents straight in /backup/

The slash on the destination makes no difference. Only the source counts. So rsync -a photos/ /backup/photos/ is the version I would type when I want the folder to keep its name and stay in sync with the same folder name.

The caveat shows up when you add --delete. If you forget the slash, rsync syncs into a subfolder you did not expect, and if you add it by accident, --delete may remove everything else in the destination that is not in the source. Run with -n first, and read the next tip about that.

My rule: write the destination with a slash too, and decide on the source slash on purpose every time. If I am unsure, I run a dry run and read where the paths end up.

Further reading: rsync man page, On this site: rsync -ani shows exactly what would change before it changes anything, On this site: rsync –info=progress2 shows one progress line for the whole transfer

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link