Daily DB backup cache with hard byte-cap eviction #7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally filed by @coilysiren on 2026-05-22T20:33:07Z - https://github.com/coilysiren/infrastructure/issues/284
Goal - stand up a poor-girl's daily database backup cache with a hard total-size cap on the
/backupsfolder. Three databases, one folder, a moving window of backups bounded by total bytes - oldest files evicted once the folder exceeds the budget.Plan - hard byte cap
Three backup cron jobs (one per DB) write timestamped dumps into
/backups. A fourth cron step runs an eviction loop that deletes the oldest files until the folder is back under the byte budget:That is the whole "poor-girl's cache eviction" - LRU-by-mtime against a fixed total-size budget. Wrap it as one systemd service plus a timer, or fold it into the same unit that fires the backups so ordering is guaranteed (backups first, eviction last).
Considered and declined - logrotate
Logrotate was the first instinct, since "rotate a folder of backups" sounds like exactly its job. It is not. Logrotate prunes by count (
rotate N) or age (maxage D), both per-file. It has no total-folder-size budget anywhere in its config language.size/maxsizeonly gate when a single file rotates, not a directory total.Logrotate could give "keep 7 days per DB", but that is not the requested semantic. The ask is a hard byte cap, and logrotate cannot express it - so we would be hand-rolling the eviction logic regardless. At that point the
du/ls/rmloop is simpler than bending logrotate around a feature it does not have. Declined.Decision at implementation time
Pick the byte budget (placeholder above is 5 GiB) and where the eviction step lives - its own timer, or appended to the backup unit. Prefer appending to the backup unit so backups always land before eviction runs.
Part of the Infrastructure Reboot - no rush, file-and-defer.