Sub topic 9
Retention policies and reclaiming space
Assumptions: you can run restic or borg, access an initialized repository, and understand that snapshots are restore points. Retention is the rule that decides which restore points remain. Pruning removes data that no retained restore point needs.
A retention policy balances recovery history against storage cost. A useful starting policy is:
| Frequency | Retain | Purpose |
|---|---|---|
| Daily | 7 | Recover recent mistakes |
| Weekly | 4 | Cover the previous month |
| Monthly | 6 | Cover longer-term changes |
The exact values should match your recovery point objective (RPO), which is the maximum acceptable age of recoverable data. A database that changes every hour needs more frequent backups than a rarely changed documentation server.
How retention affects deduplicated data
Both tools split files into chunks and store each chunk once. Snapshots or archives contain references to those chunks. Deleting one snapshot does not necessarily free space because another retained snapshot may still reference the same chunks.
The process has two stages:
- Select snapshots or archives to retain.
- Remove unreferenced chunks and reclaim storage.
The first stage changes backup history. The second stage can be slow and creates storage traffic. Run pruning during a maintenance window when the repository is large.
Applying retention with restic
restic forget removes snapshot references according to rules. The --prune option then deletes unreferenced data in the same operation.
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/etc/restic/password
restic snapshots
restic forget \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6 \
--prune
restic snapshotsReview the proposed removals before changing the repository. Use --dry-run with the retention command first:
restic forget \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6 \
--dry-runRestic groups snapshots by host and path unless you change the grouping options. Check the output carefully when one repository contains multiple servers or backup jobs. A policy applied to the wrong group can remove history you expected to keep.
Applying retention with Borg
Borg uses archives instead of snapshots. borg prune selects archives and removes those outside the policy. In Borg 1.2 and later, borg compact reclaims space in repository segment files.
export BORG_REPO=ssh://[email protected]/./borg/myserver
export BORG_PASSCOMMAND='cat /etc/borg/passphrase'
borg list
borg prune \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6 \
--list
borg compact
borg checkRun borg prune --list and inspect the archive names before allowing automation to run it unattended. borg compact may not reduce filesystem usage immediately if the repository still contains many referenced chunks.
Safe retention workflow
Use this sequence for either tool:
- Confirm that recent backups exist.
- Run the retention command in dry-run or review mode.
- Check that the oldest required restore point remains.
- Apply the policy.
- Reclaim storage with
--pruneorcompact. - Verify the repository.
- Test a restore from a retained point.
Exercise
Why might deleting several old snapshots free little or no space?
Show answer
Deduplication means retained snapshots may still reference the same chunks. Space is freed only when chunks become unreferenced and pruning or compaction removes them.