bunkerity / bunkerity/bunkerweb
[FEATURE] Backup: Towers of Hanoi rotation strategy
- Dominant language
- Python
- Stars
- 10.9k
- Forks
- 643
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 42
Description
### 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
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Research direction
Start by reading backup.py and plugin.json, then trace BACKUP_SCHEDULE, the existing already_done guard, and BACKUP_ROTATION handling. Check how backup files are selected and removed; done means the hanoi schedule and tier retention work while existing daily, weekly, and monthly schedules remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100