The Rotation That Ate the Backups — JavaScript Bug Hunt

Inspired by retention scripts gone wrong the world over (and the reason "test your restores" is a proverb): the nightly rotation is supposed to keep the…

  • Language: JavaScript
  • Layer: Database
  • Difficulty: Medium
  • Concepts: Backups, Retention
  • Modelled on: Retention scripts
  • Visible tests: the newest N survive, newest first; the newest full backup is always retained
  • Reward: 50 XP for a complete fix

Briefing

Inspired by retention scripts gone wrong the world over (and the reason "test your restores" is a proverb): the nightly rotation is supposed to keep the newest N snapshots plus, always, at least one full backup. This one keeps the oldest and deletes every full.

retention.js decides what survives.

Bug report

BUG-ROTATE · Priority: Critical · Reported by: storage

keep(snapshots, keepN):

  • keep the keepN NEWEST snapshots (by created, descending in the result)
  • if no full backup made the cut, ALSO keep the newest full one
  • everything else is deleted

Observed: the script keeps the oldest N, and full backups age out first because they're the biggest and oldest. Restore drill failed this morning.

Logs

[rotate] kept: [day-001, day-002, day-003] — all incrementals from last year

The code as shipped

src/backup/retention.js (editable)

// Decides which snapshots survive the nightly rotation.
exports.keep = function (snapshots, keepN) {
  var sorted = snapshots.slice().sort(function (a, b) {
    return a.created - b.created;
  });
  return sorted.slice(0, keepN);
};

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.