Skip to content

[FEATURE] Backup: Towers of Hanoi rotation strategy #3271

@mkf-sysangels

Description

@mkf-sysangels

What's needed and why?

The current backup system supports only simple FIFO rotation: keep the N most recent files and delete the rest. This gives uniform time coverage — if you keep 7 daily backups, you can restore to any of the last 7 days, but no further.

A Towers of Hanoi rotation strategy provides exponentially increasing coverage without a proportional increase in storage. Recent backups are kept at high granularity; older backups are kept at progressively coarser intervals. This means:

  • More recovery options near the present — ideal for catching recent misconfigurations or accidental changes
  • Long-term coverage at low cost — with 24 files you cover ~85 days, versus 24 days with simple FIFO
  • Predictable storage use — the file count is fixed regardless of how long the system runs

Proposed tier structure (24 files, ~85 days coverage):

Tier Slots Interval Covers
1 6 1 h last 6 h
2 2 2 h 6–10 h ago
3 2 4 h 10–18 h ago
4 2 8 h 18–34 h ago
5 2 16 h 34–66 h ago
6 2 32 h 66–130 h ago
7 2 64 h 130–258 h ago
8 2 128 h 258–514 h ago
9 2 256 h 514–1026 h ago
10 2 512 h 1026–2050 h ago (~85 days)

Implementations ideas (optional)

  • Add hanoi as a new option for BACKUP_SCHEDULE. When selected, the job creates a backup every hour and applies the ToH rotation after each run. Existing schedules (daily, weekly, monthly) are unaffected.
  • Change the job's "every" field in plugin.json from "day" to "hour". The existing already_done guard prevents extra backups for daily/weekly/monthly users, so this is backward-compatible.
  • Add a hanoi_rotation(backup_files, now) utility function to backup.py. It walks backwards from now through the tier windows and returns the files to delete — keeping the most recent backup that falls within each slot.
  • BACKUP_ROTATION is ignored when BACKUP_SCHEDULE=hanoi; the tier counts are the effective limit.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions