Skip to content
Back to skills

Backup Retention

ASecurity

Use this skill when the user wants to apply a snapshot backup retention policy (keep recent days plus one weekly copy per week, delete the rest) to a server's snapshot list, producing a keep/delete plan and a freed-space summary, e.g. from input.json with today, keepDays, keepWeeks and snapshots. Not for restoring backups or scheduling backup jobs.

  • 24 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 6, 2026
toolsgo

Security analysis

A100/100

Scanned December 6, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill backup-retention --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Backup Retention?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Backup Retention
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-backup-retention-c0c9bca5/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-backup-retention-c0c9bca5)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: backup-retention
description: "Use this skill when the user wants to apply a snapshot backup retention policy (keep recent days plus one weekly copy per week, delete the rest) to a server's snapshot list, producing a keep/delete plan and a freed-space summary, e.g. from input.json with today, keepDays, keepWeeks and snapshots. Not for restoring backups or scheduling backup jobs."
---

# Backup retention

Classify each snapshot as `keep-recent`, `keep-weekly` or `delete`, then write `retention-plan.csv` and `retention-summary.json`. Do the work by reading and writing files; no commands are needed.

## Inputs
Read `input.json` in the working folder (output files go beside it):
- `today`, `keepDays`, `keepWeeks`: whole numbers.
- `snapshots`: array of `{id, day, sizeGb}` in the order taken (`day` never decreases down the list; ties possible). `sizeGb` is a whole number; ids are unique.

If a field is missing or not a whole number, stop and tell the user rather than guessing. An empty `snapshots` array is valid: write the header-only CSV and the summary `{"kept":0,"deleted":0,"freed_gb":0}`.

## Rules (exact)
For each snapshot, with its 0-based position `i` in the input list:
- `age = today - day`. A negative age (future day) is `<= keepDays`, so it is recent.
- **Recent** if `age <= keepDays` → `keep-recent`. (`keepDays = 0` means only age 0 or less is recent.)
- Otherwise **older**. `week = floor(day / 7)` (integer division, remainder dropped; days are non-negative, so no negative handling is needed, but for a negative day use floor toward minus infinity).
- Among older snapshots only, for each week pick the **newest**: largest `day`; on a tie the largest `i` (listed later). Recent snapshots never take or block a week's place.
- That pick is `keep-weekly` if `age <= 7 * keepWeeks`; otherwise it is `delete` (the week has no weekly copy, and no other snapshot of the week is chosen instead). `keepWeeks = 0` means no weekly copies.
- Every other older snapshot → `delete`.

## Steps
1. Read `input.json`; number the snapshots 0..n-1.
2. Compute age for each; mark recent ones.
3. Over the older ones, write down each week number and find its newest (rule above). Because the list is ordered by day, the newest older snapshot of a week is the last older one in the list with that week.
4. Set actions per the rules.
5. Order rows newest first: `day` descending; same day → larger `i` first. Equivalent to reversing the input list.
6. Write `retention-plan.csv`: header `id,action`, one row per snapshot, `\n` line endings, no quoting unless an id contains a comma or quote (then use standard CSV quoting).
7. Write `retention-summary.json`: exactly the keys `kept` (keep-recent + keep-weekly count), `deleted` (count), `freed_gb` (sum of `sizeGb` of deleted, as a JSON number; 0 if none).
8. Re-check: row count equals snapshot count, kept + deleted = n, and the freed sum matches.

## Example
today 100, keepDays 7, keepWeeks 4 (weekly limit age 28):
| id | day | age | result |
|---|---|---|---|
| a | 71 | 29 | delete (older; week 10 newest is b, and b qualifies) |
| b | 72 | 28 | keep-weekly (week 10, age = 28 qualifies) |
| c | 92 | 8 | keep-weekly (week 13; older) |
| d | 93 | 7 | keep-recent (does not block c) |

Plan order: d, c, b, a. Note a deleted even though b's position makes it older-in-week; only the newest older snapshot per week survives.

```
id,action
d,keep-recent
c,keep-weekly
b,keep-weekly
a,delete
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.