Microsoft Learn

Documentation for SQL Server

Differential Backups

This document provides a comprehensive guide to implementing and managing differential backups in SQL Server. Differential backups capture only the data that has changed since the last full backup, offering a more efficient backup strategy compared to taking full backups repeatedly.

Key Concept: A differential backup is based on the most recent full backup. Subsequent differential backups are based on the previous differential backup. This significantly reduces backup time and storage space.

When to Use Differential Backups

Differential backups are ideal for scenarios where you need a balance between the speed of log backups and the simplicity of full backups. They are particularly useful for:

How Differential Backups Work

When a differential backup is created, SQL Server marks all data pages that have changed since the last full backup. The differential backup then contains only these modified pages. To restore a database that uses differential backups, you need:

  1. The most recent full backup.
  2. The most recent differential backup taken after the full backup.
  3. All subsequent differential backups (if any), in the order they were taken.

Tip: The frequency of differential backups depends on your RPO and the rate of data change in your database. A common strategy is to take a full backup weekly and differential backups daily.

Creating a Differential Backup

Using Transact-SQL (T-SQL)

You can create a differential backup using the BACKUP DATABASE statement with the DIFFERENTIAL option:

BACKUP DATABASE YourDatabaseName
TO DISK = 'C:\Backup\YourDatabaseName_Diff.bak'
WITH DIFFERENTIAL, NORECOVERY, STATS = 10;

Using SQL Server Management Studio (SSMS)

  1. In Object Explorer, connect to the SQL Server Database Engine instance.
  2. Expand the Databases node.
  3. Right-click the database you want to back up, point to Tasks, and then select Back Up....
  4. In the Back Up Database dialog box:
    • Select Full as the Backup type. (Note: While this seems counterintuitive, the option to mark it as differential is later).
    • In the Destination section, specify a backup destination.
    • Click the Options page.
    • In the Differential backup section, select Yes, create a differential backup.
  5. Click OK to create the differential backup.

Restoring from a Differential Backup

To restore a database using a full and differential backup, follow these steps:

  1. Restore the last full backup first.
  2. Restore the last differential backup taken after the full backup.

Example T-SQL restore command:

-- Restore the full backup (using NORECOVERY)
RESTORE DATABASE YourDatabaseName
FROM DISK = 'C:\Backup\YourDatabaseName_Full.bak'
WITH NORECOVERY, REPLACE;

-- Restore the differential backup (using NORECOVERY)
RESTORE DATABASE YourDatabaseName
FROM DISK = 'C:\Backup\YourDatabaseName_Diff.bak'
WITH NORECOVERY;

-- Bring the database online
RESTORE DATABASE YourDatabaseName WITH RECOVERY;

Considerations for Differential Backups

Related Topics