All problems

Backup Cleanup Keeps the Oldest Snapshots Instead of the Newest

Level 2 · node · Reliability · Retention policy sort direction error

Scenario

A nightly backup worker limits storage by keeping only the three newest snapshots for each database. Nothing appears wrong with three or fewer backups, but once four or more accumulate, recent backups are deleted while old ones remain. The snapshot repository and retention service are separated.

Requirements

- Keep the three newest snapshots for each database - Delete only older snapshots beyond the limit - Delete nothing when there are three or fewer snapshots - Do not affect snapshots belonging to other databases - After cleanup, remaining snapshot IDs can be read newest-first

Acceptance criteria

  • All three snapshots are kept when there are three
  • With four snapshots only the oldest one is deleted
  • With five snapshots the newest three remain
  • Backups for another database remain intact
  • The post-cleanup ID list is correct in newest-first order