Incremental folder backups with rsync: snapshots and calendar retention

Archiving 20 GB of uploads every night is slow and eats disk space. rsync downloads only the files that changed, and hard links turn every run into a full snapshot of the folder.

A plain sync

rsync -rlpt deploy@example.com:/var/www/uploads/ ~/Backups/uploads/current/

-rlpt copies folders, symlinks, permissions and modification times. It is -a without owner and group: on the Mac the files end up yours anyway. A trailing slash on the source means "the folder’s contents"; without it you get a nested uploads folder on the Mac. The server only needs rsync itself: sudo apt install rsync.

Such a copy has one problem: there is only one. If a file on the server is damaged or deleted, the next run carries the damage into the copy.

Snapshots with hard links

Each run creates a new dated folder. Files that haven’t changed since the previous snapshot aren’t downloaded again; they become hard links to it:

b=~/Backups/uploads
d=$(date +%F)
rsync -rlpt --exclude='cache/' --link-dest="$b/latest" \
  deploy@example.com:/var/www/uploads/ "$b/$d/" \
  && ln -sfn "$b/$d" "$b/latest"

On the first run latest doesn’t exist yet. rsync warns about it and downloads everything.

How many snapshots to keep

The simple "last N" rule:

cd ~/Backups/uploads && ls -1d 20*/ | sort -r | tail -n +15 | xargs rm -rf

It keeps the 14 newest snapshots. But a script like this doesn’t check whether the latest runs succeeded, and a string of failures wipes out your good copies.

A calendar (the GFS scheme) works better: keep the newest copy of each of the last 7 days, each of the last 4 weeks and each of the last 12 months. That is at most 23 snapshots, with history going back a year, so a mistake you notice late can still be rolled back a week or a month.

What about the cloud

Hard links only work within one disk. Cloud storages don’t understand them, so send a snapshot there as a single archive:

tar -C ~/Backups/uploads/2026-10-18 -cf - . | zstd -T0 > uploads-2026-10-18.tar.zst