Low Tide Notes

Cheap nightly snapshots with rsync and hard links

October 27

Before reaching for a backup product, try this. Each night gets its own directory that looks like a full copy, but unchanged files are hard links to the previous night, so they take no extra space.

#!/bin/sh
set -eu
SRC=/home/
DST=/srv/snapshots
TODAY=$(date +%F)
rsync -a --delete --link-dest="$DST/latest" "$SRC" "$DST/$TODAY"
ln -sfn "$DST/$TODAY" "$DST/latest"

Pruning

Deleting an old snapshot only removes the links it owned, so pruning is just rm -rf on directories older than you care about.

find /srv/snapshots -maxdepth 1 -type d -name "20*" -mtime +30 -exec rm -rf {} +

Restore is cp. That is the best feature.