Overview

SQL Server backups come in three kinds (full, differential, transaction log) and the recovery model decides which of them you can take and how far back you can restore. The goal is to meet your RPO (data you can lose) and RTO (time to be back).

Core concepts

Recovery modelLog behaviourPoint-in-time restore
SIMPLELog truncated at checkpoint; no log backupsNo: restore to the last full or differential
FULLLog kept until backed upYes, to any moment inside the log chain
BULK_LOGGEDLike FULL but bulk operations minimally loggedYes, except inside a bulk-logged interval
  • Full backup: all data plus enough log to be consistent. Differential: pages changed since the last full. Log backup: the log since the previous log backup; the unbroken series is the log chain.
  • Tail-log backup (BACKUP LOG ... WITH NORECOVERY) captures the final log before restoring over a damaged database.
  • COPY_ONLY backups do not disturb the differential base or the log chain.
  • Always use WITH CHECKSUM and COMPRESSION (available in Standard and above), and test with RESTORE VERIFYONLY plus real restores; VERIFYONLY does not prove the data is usable.
  • Backups can go to disk, to a network share or to Azure Blob (TO URL). Backups of a TDE database stay encrypted; you need the certificate to restore elsewhere (sqlserver-security).
  • Corruption is detected by DBCC CHECKDB and PAGE_VERIFY CHECKSUM; run CHECKDB regularly on the database or a restored copy (sqlserver-agent-maintenance).

Worked example

Point-in-time recovery, executed on SQL Server 2022:

ALTER DATABASE kb SET RECOVERY FULL;
BACKUP DATABASE kb TO DISK='/var/opt/mssql/data/kb_full.bak' WITH INIT, COMPRESSION, CHECKSUM;
INSERT dbo.Important VALUES (1,'keep'),(2,'keep');
BACKUP LOG kb TO DISK='/var/opt/mssql/data/kb_log1.trn' WITH INIT, COMPRESSION, CHECKSUM;
INSERT dbo.Important VALUES (3,'before-mistake');          -- 21:29:56
DELETE dbo.Important;                                       -- the mistake, 2 s later
BACKUP LOG kb TO DISK='/var/opt/mssql/data/kb_log2.trn' WITH INIT, COMPRESSION, CHECKSUM;

Restore a copy to just before the DELETE without touching the original:

RESTORE DATABASE kb_pit FROM DISK='/var/opt/mssql/data/kb_full.bak'
  WITH MOVE 'kb' TO '/var/opt/mssql/data/kb_pit.mdf',
       MOVE 'kb_log' TO '/var/opt/mssql/data/kb_pit.ldf', NORECOVERY;
RESTORE LOG kb_pit FROM DISK='/var/opt/mssql/data/kb_log1.trn' WITH NORECOVERY;
RESTORE LOG kb_pit FROM DISK='/var/opt/mssql/data/kb_log2.trn'
  WITH STOPAT='2026-11-24 21:29:57', RECOVERY;
SELECT * FROM kb_pit.dbo.Important;      -- 1 keep, 2 keep, 3 before-mistake

Then copy the lost rows back to the live database. The full backup of the 500,000-row test database was 10,850 pages and took 0.25 s with compression on this small data set.

Pitfalls and production notes

  • A database in FULL recovery with no log backups grows its log forever (sqlserver-storage-tempdb).
  • Backups on the same disk as the data are not backups. Follow 3-2-1 and keep copies in another failure domain; protect them like production data.
  • A restore drill with a measured duration is the only proof of RTO.
  • Backups from a readable secondary are possible in Availability Groups but have rules (copy-only full) (sqlserver-always-on).
  • Back up master, msdb and (Linux or Windows) the encryption certificate and private key.
  • RESTORE ... WITH REPLACE overwrites; look at the target twice.
  • Compare to PostgreSQL PITR (pg-backup-pitr).

Practice questions

  1. The log chain is broken (a log backup file is lost). What can you restore to?
  2. When would you choose differential backups?
  3. Why is SIMPLE recovery wrong for most production OLTP databases?

References

  • Microsoft Learn, Back up and restore of SQL Server databases; Recovery models

sqlserver-agent-maintenance · sqlserver-security · sqlserver-always-on · pg-backup-pitr