Use this skill when the user wants to apply a backup retention policy to a server's list of snapshots: decide which snapshots to keep as recent or weekly copies and which to delete, from keepDays/keepWeeks settings (typically in input.json), and produce a retention plan CSV and a summary of freed space. Not for restoring backups or creating snapshots.
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-d3e502e8)
---
name: backup-retention
description: "Use this skill when the user wants to apply a backup retention policy to a server's list of snapshots: decide which snapshots to keep as recent or weekly copies and which to delete, from keepDays/keepWeeks settings (typically in input.json), and produce a retention plan CSV and a summary of freed space. Not for restoring backups or creating snapshots."
---
# Backup retention
Apply a keep-recent / keep-weekly / delete policy to snapshots by reading and writing files only. No scripts are needed; work through the list by hand, carefully.
## Inputs
Read `input.json` in the working folder:
- `today`, `keepDays`, `keepWeeks`: whole numbers.
- `snapshots`: array of `{id, day, sizeGb}` in the order taken (day never decreases down the list; several can share a day; ids unique).
If the file is missing or a field is absent, state that and stop; do not invent values. An empty `snapshots` array is valid (write header only, and summary 0/0/0).
## Rules (exact)
For each snapshot, with its position `i` in input.json (0-based):
1. `age = today - day`. (A day after today gives a negative age; that is still `<= keepDays`, so recent.)
2. **Recent** if `age <= keepDays` -> `keep-recent`. Age exactly keepDays is recent.
3. Otherwise it is **older**, with `week = floor(day / 7)` (integer division, remainder dropped; day 0-6 is week 0).
4. Per week, among **older** snapshots only (recent ones never take or block a place), the winner is the one with the largest `day`; ties on day go to the largest `i` (listed later). Because the input is ordered, the winner is simply the last older snapshot of that week in the list.
5. The winner is `keep-weekly` only if `age <= 7 * keepWeeks`; else (and for every other older snapshot) it is `delete`. If keepWeeks is 0, only age <= 0 qualifies, but those are already recent unless keepDays is negative; apply the formula as written. If the winner is too old, nothing else in that week is kept (do not promote the next one).
## Steps
1. Read input.json; compute age and class (recent/older) for every snapshot.
2. For older snapshots, group by week; pick each week's winner per rule 4.
3. Assign actions per rules 2 and 5.
4. Order rows newest first: day descending; same day -> larger `i` first. (Equivalent to reversing the input list, since day never decreases.)
5. Write `retention-plan.csv` beside input.json: header `id,action`, then one row per snapshot, comma-separated, no quotes unless an id contains a comma or quote, newline-terminated lines.
6. Write `retention-summary.json` beside input.json with exactly these keys:
`{"kept": <recent+weekly count>, "deleted": <delete count>, "freed_gb": <sum of sizeGb of deleted, JSON number>}`
7. Check: kept + deleted equals the number of snapshots; row count matches; freed_gb re-added once.
## Worked example
today 100, keepDays 7, keepWeeks 4 (limit 28 days):
- day 95 (age 5) -> keep-recent; day 93 (age 7) -> keep-recent.
- day 92 (age 8, week 13): newest older of week 13 -> keep-weekly (recent day 93 is in the same week but irrelevant).
- day 90 (week 12) is the only older one in week 12 -> age 10 -> keep-weekly.
- day 72 (age 28, week 10), newest older of its week -> keep-weekly; day 71 same week -> delete.
- day 60 (age 40) as week winner -> too old -> delete.
Rows: 95, 93, 92, 90, 72, 71, 60 order (newest first).