Agent Wranglers

OPS-46Recommended

Keep backups for a set time

Keep each backup for a fixed period, such as 35 days of daily copies, and let the storage delete it when the period ends.

How to do it

Pick the period from the oldest mistake you need to undo, such as a bad import found weeks later. Daily copies for 30 to 35 days suit most services. Keep monthly copies longer only when a law or contract asks, and write down why. Set the expiry in the storage itself, such as an S3 lifecycle rule, so it runs even when the server is gone. Set the object lock to the same period, never longer. Backups are not edited to honour an erasure request. The erased data leaves with the backups as they expire, and a restore runs the erasure log again, as data requests says. Name the period in the privacy notice and in the retention schedule.

Examples

JSON example

{
  "Rules": [{
    "ID": "expire-daily-backups",
    "Filter": { "Prefix": "daily/" },
    "Status": "Enabled",
    "Expiration": { "Days": 35 },
    "NoncurrentVersionExpiration": { "NoncurrentDays": 1 }
  }]
}

Shell example

# restic: keep 35 daily snapshots, then prune the data they no longer use
restic forget --keep-daily 35 --prune

How to check

The oldest backup in the off-site store is no older than the period plus one day. The retention schedule and the storage's expiry rule name the same period.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/operations/disaster-recovery/backup-retention">Agent Wranglers operations and observability playbook</a>. In code you write, add a comment next to it with the same link.