Use this skill when the user wants to apply a backup retention policy to a server's snapshot list: decide which snapshots to keep (recent or weekly copies) and which to delete, produce a retention plan and a summary of space freed. Fits requests like 'prune old snapshots', 'keepDays/keepWeeks retention', 'which backups can I delete'. Not for restoring backups or other cleanup tasks.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Backup Retention?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-backup-retention-3fa3f041)
---
name: backup-retention
description: "Use this skill when the user wants to apply a backup retention policy to a server's snapshot list: decide which snapshots to keep (recent or weekly copies) and which to delete, produce a retention plan and a summary of space freed. Fits requests like 'prune old snapshots', 'keepDays/keepWeeks retention', 'which backups can I delete'. Not for restoring backups or other cleanup tasks."
---
# Backup retention
## Inputs
Read `input.json` in the working folder: `today` (int day number), `keepDays`, `keepWeeks` (ints), `snapshots` (array of `{id, day, sizeGb}` in the order taken; day never decreases; days may repeat; ids unique).
If the file or a field is missing or malformed, do not guess: state what is missing and stop. An empty `snapshots` array is valid (write header-only CSV and zeros).
## Rules (exact)
For each snapshot, with `i` = its 0-based index in the input list:
- `age = today - day`. (A negative age, i.e. a future day, is `<= keepDays` when keepDays >= 0, so it is recent.)
- **Recent** if `age <= keepDays` -> `keep-recent`.
- Otherwise it is **older**. `week = floor(day / 7)` (integer division, remainder dropped; for day 0..6 week is 0).
- For each week, among older snapshots only, pick the winner: largest `day`; ties on day go to the largest `i` (listed later).
- The winner is `keep-weekly` only if `age <= 7 * keepWeeks`. If it fails this, the week has no weekly copy: do NOT promote another snapshot from that week (the winner is the newest, so all others are even older and also fail).
- Every other older snapshot is `delete`.
- Recent snapshots never take or block a weekly place.
- If keepDays or keepWeeks is 0, the formulas still apply literally (keepWeeks 0 means weekly copies need age <= 0, which no older snapshot meets).
## Steps
1. Read `input.json`; number snapshots by index.
2. Classify each snapshot as recent or older.
3. Group older ones by week; choose each week's winner; apply the age limit.
4. Assign actions.
5. Order rows: `day` descending; for equal day, larger index first.
6. Write `retention-plan.csv` beside `input.json`: header `id,action`, then one row per snapshot, `id,action`, no spaces, no quoting unless an id contains a comma or quote.
7. Write `retention-summary.json` beside it: exactly the keys `kept` (keep-recent + keep-weekly count), `deleted` (count), `freed_gb` (sum of sizeGb of deleted; JSON number, 0 if none), e.g. `{"kept": 3, "deleted": 2, "freed_gb": 40}`.
8. Check: row count equals snapshot count; kept + deleted equals snapshot count; freed_gb re-added from the delete rows.
## Worked example
today 100, keepDays 7, keepWeeks 4 (limit age 28):
- day 93 (age 7): keep-recent.
- day 92 (age 8, week 13): keep-weekly, despite recent day 93 in the same week.
- day 72 (age 28, week 10): keep-weekly if it is the newest older of week 10; day 71 then -> delete.
- day 70 in week 10 is older than the winner -> delete. A day 69 (week 9, age 31) winner would exceed 28 -> delete.
Rows: 93,92,72,71 order by day descending.
## Limits
No commands needed; do all computation by hand carefully, working through the list one snapshot at a time.