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: restic forget --keep-daily 5 --dry-run shows which snapshots would go

Linux
~/tips/tip-backup-restic-forget-dry-run

restic -r /srv/restic-repo forget --keep-daily 5 --dry-run

Previews which restic snapshots a retention policy would delete without removing anything.

Retention policies are easy to get wrong, and a wrong one deletes your history. Before I let restic remove anything, I would run the policy with --dry-run first and read the list.

The restic docs show this exact pattern:

restic -r /srv/restic-repo forget --keep-daily 5 --dry-run

The output lists which snapshots restic would keep and which it would remove, and nothing changes in the repository. The keep options work per calendar period. For example --keep-daily 5 keeps the most recent snapshot of each of the last five days that have snapshots, so a quiet week does not use up the count. You can combine --keep-weekly, --keep-monthly and --keep-yearly in the same call, and --keep-within 7d keeps everything from the last seven days before the newest snapshot.

When the list looks right, run the same line without --dry-run. Adding --prune then removes the data that no snapshot uses any more:

restic -r /srv/restic-repo forget --keep-daily 5 --prune

Keep in mind that policies apply per group, and by default a group is a combination of host, paths and tags. If two machines back up into one repository, each gets its own five days. That is a safety feature against deleting unrelated backup sets, but it can surprise you if the paths of a machine change, because the old snapshots form another group.

There are two warnings in the docs I would pass on. Without --prune, forget only removes the snapshot references and does not free any space, which happens when prune runs. And during a prune the repository is locked, so a backup cannot complete in that time. Plan it for a quiet moment rather than the same minute as a nightly job.

Further reading: restic docs: Removing backup snapshots

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link