Case File: The Retention Plan
The backup disk is full of every night since the company started, and the one backup that is needed is from three weeks ago. Write the retention rule that keeps the last seven days, the Sundays of the last four weeks and the first of the month for six months, and decides which backups to delete. Check the exact edges of each rule on lists you cannot see. The backup dates are generated for you alone.
Sabi Logistics · Recovery 1
The Retention Plan
The backup disk is full, and last week a customer asked for a file as it was twenty-three days ago
Musa Head of IT · Phone call
Musa. Two problems that turn out to be one. The backup disk is full, because nobody ever deleted a backup. And on Monday a customer asked us for a spreadsheet as it was twenty-three days ago, after somebody had overwritten it, and I was not sure that we still had it.
I want a retention rule: keep a lot of recent backups, fewer older ones, and delete the rest, so that the disk does not fill and the old data we might need is still there. Here is my proposal: every backup of the last 7 days, the Sunday backups of the last 28 days, and the backups of the first of the month for about six months. Please write it as code, run it on our list of backups, and tell me how many we can delete.
The brief
What you need to know first.
- Why tiers. Most restores are of yesterday (“I just deleted it”), some of last month (“we found the error late”), and a few of last year (“the auditor asks”). Keeping every night for ever is expensive, and keeping only a week is dangerous. A tiered retention (daily, weekly, monthly, sometimes called grandfather-father-son) keeps the dense recent history and a thin long history.
- Real dates. Use
date.fromisoformat("2026-11-09"). The age of a backup is(today - d).days.d.weekday()is 6 for a Sunday, andd.day == 1is the first of a month. - The rules are constants:
KEEP_DAILY = 7(age 0 to 6), Sundays with age underKEEP_WEEKLY = 28, first-of-month with age underKEEP_MONTHLY = 183. A backup is kept if any rule keeps it. A date in the future (a wrong clock) is not kept. - Edges. Age 6 is still daily and age 7 is not; a Sunday of age 27 is kept and one of age 28 is not. Write each comparison with care and test it. A missing night is simply not in the list: do not keep another day instead.
- Fill in
keep_rule,plan(returns{"keep": sorted dates, "delete": sorted dates}),result,n_keep,n_deleteandoldest_kept. The checks runplanon requests you cannot see, including one with today on a Sunday and dates at every edge.
The lab gives you the data for this case, invented and generated for you alone. Today is 2026-11-09.
Preparing your data…
On a real system
The lab modelled the rules with a script. These are the commands that you would type on the real thing.
| You want to | Type | What you get |
|---|---|---|
| see which backups a retention policy would remove, without removing them | restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --dry-run | what would be kept and what would be forgotten |
| list the snapshots of a restic repository | restic snapshots | the id, time and paths of each backup |
| find old backup files by age (dry run first) | find /backups -type f -mtime +30 -print | files older than 30 days, listed and not deleted |
Only run commands on systems that you own or have written permission to test.
Musa: “The disk has room again and the customer got the file. Now the finance director asks for one more rule: keep the last backup of every year for seven years. And somebody asks whether the rule might delete the only good backup.”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Musa: “So the retention rule must know which backups are good, and not only how old they are.”
What a senior systems administrator would do next. Add the yearly tier, and let the law and the business set the longest one (tax and employment records have legal retention periods). Never delete the last verified backup, whatever its age: the rule should skip a backup that is the newest good one of its kind. Test the rule on a copy of the list (a dry run that prints what it would delete) before it deletes anything, and log every deletion. Remember that dependent backups (an incremental that needs its full backup) cannot be deleted one by one. Keep one tier offline or immutable, so that ransomware cannot delete the history, and apply the 3-2-1 rule: three copies, two kinds of media, one off site. Finally, check the cost: retention is a trade between money and the oldest day that you can go back to.
The trap. A cleanup script that runs on a wrong date. A clock that is a year ahead makes everything look old, and the script deletes the whole history in one night.
Write the retention note
Write the note for the Head of IT: the three tiers and the exact rule of each (ages and days), how many backups are kept and deleted and the oldest that is kept, why the edges (age 6 and 7, Sunday 27 and 28) are tested, what a future date means, and what a safe cleanup needs (a dry run, logging, never deleting the last good backup, dependent incrementals, an offline or immutable copy, legal retention).
🧪 Want to practise this on your own computer? See how to set up your lab →