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 model | Log behaviour | Point-in-time restore |
|---|---|---|
SIMPLE | Log truncated at checkpoint; no log backups | No: restore to the last full or differential |
FULL | Log kept until backed up | Yes, to any moment inside the log chain |
BULK_LOGGED | Like FULL but bulk operations minimally logged | Yes, 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_ONLYbackups do not disturb the differential base or the log chain.- Always use
WITH CHECKSUMandCOMPRESSION(available in Standard and above), and test withRESTORE VERIFYONLYplus real restores;VERIFYONLYdoes 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 CHECKDBandPAGE_VERIFY CHECKSUM; runCHECKDBregularly 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-mistakeThen 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
FULLrecovery 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,msdband (Linux or Windows) the encryption certificate and private key. RESTORE ... WITH REPLACEoverwrites; look at the target twice.- Compare to PostgreSQL PITR (pg-backup-pitr).
Practice questions
- The log chain is broken (a log backup file is lost). What can you restore to?
- When would you choose differential backups?
- Why is
SIMPLErecovery wrong for most production OLTP databases?
References
- Microsoft Learn, Back up and restore of SQL Server databases; Recovery models
Related
sqlserver-agent-maintenance · sqlserver-security · sqlserver-always-on · pg-backup-pitr