Cheap daily snapshots with rsync --link-dest
Before reaching for a real backup tool it is worth knowing how far plain rsync gets you. With
--link-dest, every unchanged file in a new snapshot is a hard link to the same file in the previous
one, so each day looks like a full copy but only costs the size of what changed.
#!/bin/sh
set -eu
SRC=/home/
DST=/mnt/backup/home
today=$(date +%F)
rsync -a --delete \
--link-dest="$DST/latest" \
"$SRC" "$DST/$today.partial"
mv "$DST/$today.partial" "$DST/$today"
ln -sfn "$today" "$DST/latest"
The .partial rename means an interrupted run never becomes latest. On the very first run
latest doesn't exist yet; rsync warns and simply makes a full copy.
Pruning
find /mnt/backup/home -maxdepth 1 -name '20*' -mtime +30 -exec rm -rf {} +
Deleting an old snapshot only removes its links; data that is still referenced by newer snapshots stays.
Limits
Both directories must be on the same filesystem, a file that changes by one byte is stored again in full, and this is a copy on the same machine, not an off-site backup. For anything important I still use restic on top.