Systems Administrator

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.

50 min

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, and d.day == 1 is the first of a month.
  • The rules are constants: KEEP_DAILY = 7 (age 0 to 6), Sundays with age under KEEP_WEEKLY = 28, first-of-month with age under KEEP_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_delete and oldest_kept. The checks run plan on 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 toTypeWhat you get
see which backups a retention policy would remove, without removing themrestic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --dry-runwhat would be kept and what would be forgotten
list the snapshots of a restic repositoryrestic snapshotsthe id, time and paths of each backup
find old backup files by age (dry run first)find /backups -type f -mtime +30 -printfiles older than 30 days, listed and not deleted

Only run commands on systems that you own or have written permission to test.

🔒 The debrief unlocks when you close the case. Finish the lab above.

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).

0 words

🧪 Want to practise this on your own computer? See how to set up your lab →

📝

Knowledge Check

1 of 4

A retention rule keeps the last 7 days. A backup is exactly 7 days old. Is it kept by that rule?

Report a problem

About: /lessons/case-the-retention-plan