Point-in-Time Recovery

Restoring to a Moment

Point-in-time recovery (PITR) restores the database as it was at an exact moment, for example one second before someone ran DELETE FROM Orders without a WHERE. It needs a full backup plus every transaction-log backup since then.

  1. Restore the last full backup taken before the incident.
  2. Apply differential backup (if any).
  3. Replay log backups up to the chosen time, and stop there.
  4. Bring the database online and verify.

Examples

-- SQL Server
RESTORE LOG ShopDB FROM DISK = 'D:\Backups\ShopDB_log.trn'
WITH STOPAT = '2024-06-01T14:29:59', RECOVERY;

# PostgreSQL (postgresql.conf / recovery settings)
restore_command = 'cp /archive/%f %p'
recovery_target_time = '2024-06-01 14:29:59+05:30'

# MySQL: restore full dump, then replay binary logs up to a time
mysqlbinlog --stop-datetime="2024-06-01 14:29:59" binlog.000042 | mysql shopdb