DEV Community

LingamSuyambu
LingamSuyambu

Posted on Originally published at sqlcloudlab.blogspot.com

SQL Server Backup Types and Recovery Models Explained

Originally published at SQL & Cloud Lab.

This post was drafted with AI assistance.

Backups are the one part of database work you cannot get wrong. The right strategy depends on two questions your business must answer: how much data can we afford to lose (recovery point objective, RPO) and how long can we be down (recovery time objective, RTO). SQL Server's backup types and recovery models are the tools you use to meet them.

SQL Server backup types and recovery models

Recovery models

  • SIMPLE: the transaction log is truncated automatically at checkpoints, so you cannot take log backups. You can only restore to the time of a full or differential backup. Good for development, test and databases that can be rebuilt easily.
  • FULL: every change is kept in the log until a log backup. With regular log backups you can restore to any point in time. The standard choice for production. Without log backups, the log keeps growing.
  • BULK_LOGGED: like FULL, but some bulk operations are minimally logged. Point-in-time restore is not possible within a log backup that contains bulk operations. Usually switched to temporarily for big loads.
SELECT name, recovery_model_desc FROM sys.databases;

ALTER DATABASE [Payroll] SET RECOVERY FULL;
Enter fullscreen mode Exit fullscreen mode

Backup types

Full backup

A complete copy of the database, including enough log to make it consistent. Every restore starts from a full backup.

BACKUP DATABASE [Payroll]
TO DISK = N'D:\Backup\Payroll_FULL.bak'
WITH COMPRESSION, CHECKSUM, STATS = 10;
Enter fullscreen mode Exit fullscreen mode

Differential backup

Contains every extent changed since the last full backup. Each differential grows over time until the next full. To restore, you need the full backup plus only the latest differential.

BACKUP DATABASE [Payroll]
TO DISK = N'D:\Backup\Payroll_DIFF.bak'
WITH DIFFERENTIAL, COMPRESSION, CHECKSUM;
Enter fullscreen mode Exit fullscreen mode

Transaction log backup

Contains all log records since the previous log backup, and lets the log space be reused. Only possible in FULL or BULK_LOGGED. The interval between log backups is roughly your maximum data loss.

BACKUP LOG [Payroll]
TO DISK = N'D:\Backup\Payroll_LOG_202610241200.trn'
WITH COMPRESSION, CHECKSUM;
Enter fullscreen mode Exit fullscreen mode

Copy-only backup

A one-off backup, for example to refresh a test environment, that does not reset the differential base or affect the log chain. Use WITH COPY_ONLY so your regular schedule is not disturbed.

A typical production schedule

Backup Frequency
Full Weekly (or nightly for smaller databases)
Differential Daily
Transaction log Every 5 to 15 minutes

Adjust to your RPO and RTO: more frequent log backups mean less data loss; more frequent full or differential backups mean faster restores.

Good habits

  • Use CHECKSUM so SQL Server validates pages as it backs them up.
  • Use COMPRESSION; it usually makes backups smaller and faster.
  • Keep copies off the server, ideally in another location. BACKUP ... TO URL can write directly to Azure Blob Storage.
  • Test restores regularly. RESTORE VERIFYONLY checks that a file is readable, but only a real restore, followed by DBCC CHECKDB, proves you can recover.
  • Monitor the jobs and alert when a backup is missed, not just when one fails.

Check your backup history

SELECT TOP (20)
    database_name,
    CASE type WHEN 'D' THEN 'Full' WHEN 'I' THEN 'Differential' WHEN 'L' THEN 'Log' END AS backup_type,
    backup_finish_date,
    CAST(compressed_backup_size / 1048576.0 AS DECIMAL(12,1)) AS size_mb
FROM msdb.dbo.backupset
ORDER BY backup_finish_date DESC;
Enter fullscreen mode Exit fullscreen mode

Azure SQL Database

In Azure SQL Database, backups are automatic: full, differential and log backups are taken for you and support point-in-time restore within the configured retention period. You can add long-term retention for compliance. You still need to know your retention settings and practise a restore.

Quick checklist

  • Production databases: FULL recovery model plus regular log backups.
  • Full plus differential plus log, matched to your RPO and RTO.
  • CHECKSUM and COMPRESSION on every backup.
  • Copies stored off the server.
  • Regular test restores with DBCC CHECKDB.

Related reading:


More SQL Server guides on my blog, SQL & Cloud Lab.

Top comments (0)