Skip to the page

Scaling and changing databases · senior

Backups, point-in-time recovery and DELETE without WHERE

A backup is only real when you have tested a restore. After a wrong DELETE, the goal is to recover the lost rows without losing the new data written since.

The notes

What you must know

  • First: stop the script and anything else writing to the table, name one incident owner, and do not make things worse (no restore over production, keep the WAL).
  • Business: run in a degraded way (for example, ask for the address again) while the restore runs.
  • Options: a point-in-time restore of a copy to just before the mistake (base backup plus WAL, or binlog in MySQL), then copy only that table back; a delayed replica; MySQL binlog flashback tools; last night's backup plus replay.
  • Merge: restore into a separate table, insert old rows that do not conflict, keep the new rows, and check foreign keys.
  • Restoring last night's backup over production loses the whole day of new data.
  • RTO is how long recovery takes. RPO is how much data you can lose. Test restores regularly and measure both. Alert when a backup or WAL archive fails.
  • Guardrails: no direct write access to production from laptops, separate credentials per environment, a dry run with a row-count check that aborts, sql_safe_updates in MySQL clients, a delayed replica and reviewed runbooks.
  • Communicate with regular updates and write a blameless postmortem.

The red pen

Common traps: mistake → fix

  • Mistake: We have backups, so we are safe

    Fix: only a tested restore counts.

  • Mistake: Restore the full backup over production

    Fix: you lose all new data.

  • Mistake: Find who did it first

    Fix: restore service first; review later without blame.

Easy to hard

Questions interviewers ask, easy to hard

  1. Someone deleted 12 million rows in production. What do you do first?
  2. What is point-in-time recovery?
  3. What are RTO and RPO?
  4. How do you prevent a script from running on the wrong database?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview