C.W.K.
Stream
Lesson 09 of 12 · published

Backup Patterns with --link-dest

~18 min · backup, link-dest, incremental, snapshots

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

Incremental backups that look like full snapshots

The classic backup pattern: nightly rsync to a NAS, but each night looks like a complete snapshot. The trick is --link-dest. rsync compares source against the named directory; for files that haven't changed, it creates a hard link instead of copying. Result: every night's directory looks complete, but only changed files use new disk space. A month of dailies might consume only 5–10 % more than one full backup.

What's actually on disk

Hard links are multiple directory entries pointing to the same inode. From the user's perspective, both look like full files. From the storage perspective, there's exactly one copy. Delete one entry — the other still works. That's why --link-dest snapshots are so cheap: every "copy" of an unchanged file is just another inode reference.

Code

Daily incremental backup·bash
#!/bin/bash
# nightly-backup.sh
set -euo pipefail

SOURCE="/home/you_username/"
DEST_HOST="nas"
DEST_BASE="/volume1/backups/you_username"
DATE=$(date +%Y-%m-%d)
LATEST="${DEST_BASE}/latest"
BACKUP="${DEST_BASE}/${DATE}"

rsync -avz --delete \
  --link-dest="${LATEST}" \
  --exclude '.Trash' --exclude 'Library/Caches' --exclude 'Downloads' \
  "${SOURCE}" "${DEST_HOST}:${BACKUP}/"

# Update the 'latest' symlink for tomorrow's --link-dest
ssh "${DEST_HOST}" "ln -snf '${DATE}' '${LATEST}'"

echo "Backup ${DATE} complete."

External links

Exercise

Set up the script above against a test target (a directory on the same machine, or a NAS path). Run it three days in a row, modifying one file in source between runs. Inspect each backup directory: du -sh /backups/2026-05-01 /backups/2026-05-02 /backups/2026-05-03. Notice that days 2 and 3 are tiny because most files are hard links into day 1's blocks.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.