Backups and point-in-time recovery
A 100 GB database, four nights of backups and one bad DELETE at 14:32. See how full backups, incrementals and the archived log let you rewind to 14:31.
In 30 seconds
A full backup copies the whole database. Incremental backups then save only what changed since the last one, which is far smaller.
Backups alone can only return you to the moment they were taken. So the database’s log of every change is archived as well. To recover, you restore the backups and replay the log up to the exact minute you want: point-in-time recovery.
Two cautions: a backup counts only once a test restore has worked, and a replica is not a backup, because it copies mistakes too.
Backups and point-in-time recovery, step by step
Simplified: some tools use differential backups (changes since the last full) instead, and a recovery target can also be a transaction or log position rather than a clock time. Sizes and timings are invented.
- Step 1: A full backup. A full backup is a complete copy of the database, taken here every Sunday at 02:00 and kept on separate storage. It is the simplest thing to restore from, but it is big and slow to make: copying all 100 GB every night would mean 700 GB a week.
- Step 2: Incremental backups. An incremental backup stores only what changed since the previous backup: 4, 6 and 5 GB on the next three nights. That is quick and small. The price is paid at restore time: you need Sunday’s full backup plus every incremental after it, applied in order.
- Step 3: The gap between backups. On Wednesday at 14:32 someone runs a DELETE without a WHERE clause and the orders table is emptied. With nightly backups alone, the best you can do is go back to Wednesday 02:00. Every order taken in the twelve and a half hours since is lost.
- Step 4: Archive the log. The database already writes every change to its transaction log before applying it. Log archiving copies each log file to backup storage as soon as it fills, or after a short timeout. Now the storage holds, besides the backups, a continuous record of everything that happened after them.
- Step 5: Restore to an exact time. Point-in-time recovery combines the two. Restore the full backup and the three incrementals to reach Wednesday 02:00, then replay the archived log, change by change, and stop at 14:31. The orders taken that day are back; the DELETE at 14:32 is never replayed.
- Step 6: Test the restore. A backup that has never been restored is only a hope. Files get corrupted, a log segment goes missing, a backup job quietly stops. So teams regularly restore onto a spare server, check the data, and time it. Here the restore takes 38 minutes: that is the real time to recover.
- Step 7: A replica is not a backup. A replica is a live copy that follows the primary within about a second. It rescues you when a server dies, but it copies mistakes just as faithfully: the DELETE reaches it at once. Only backups and the archived log can take you back to a moment before the mistake.
Try it yourself
Learn this first
Spotted a mistake on this page?