SQL Server Documentation

Backup & Restore Overview

This guide provides a comprehensive reference for backing up and restoring Microsoft SQL Server databases. It covers backup types, best practices, T‑SQL commands, PowerShell scripts, and common troubleshooting scenarios.

Key concepts:

Backup Types

Backup TypeDescriptionTypical Use‑Case
FullComplete copy of a database.Weekly baseline, nightly for critical DBs.
DifferentialChanges since last full backup.Mid‑day backups to reduce restore time.
LogActive transaction log records.Point‑in‑time recovery, every 15‑30 mins.
Copy‑onlyIndependent backup; does not truncate logs.Ad‑hoc backups for testing.
File/FilegroupSelective file or filegroup backup.Large databases with rarely‑used filegroups.
PartialBackup of primary filegroup + read‑only groups.Large read‑only data warehouses.

T‑SQL Backup Examples

Full Backup

BACKUP DATABASE [AdventureWorks] 
TO DISK = N'C:\Backups\AdventureWorks_Full_2025_09_13.bak' 
WITH INIT, 
NAME = N'AdventureWorks-Full Backup',
DESCRIPTION = N'Full backup of AdventureWorks on 2025‑09‑13',
COMPRESSION, 
STATS = 10;

Differential Backup

BACKUP DATABASE [AdventureWorks] 
TO DISK = N'C:\Backups\AdventureWorks_Diff_2025_09_13.bak' 
WITH DIFFERENTIAL,
NAME = N'AdventureWorks-Diff Backup',
DESCRIPTION = N'Differential backup after full backup',
STATS = 10;

Transaction Log Backup

BACKUP LOG [AdventureWorks] 
TO DISK = N'C:\Backups\AdventureWorks_Log_2025_09_13.trn' 
WITH NORECOVERY,
NAME = N'AdventureWorks-Log Backup',
DESCRIPTION = N'Log backup for point‑in‑time restore',
STATS = 10;

PowerShell Backup Example

# Requires SqlServer module
Import-Module SqlServer

$server   = 'SQL01\MAIN'
$database = 'AdventureWorks'
$path     = "C:\Backups\$($database)_Full_$(Get-Date -Format 'yyyyMMdd_HHmm').bak"

Backup-SqlDatabase -ServerInstance $server `
    -Database $database `
    -BackupFile $path `
    -CompressionOption On `
    -Initialize `
    -BackupAction Database `
    -Verbose

Write-Host "Backup completed: $path"

Restoring a Database

Restore steps typically follow this order:

  1. Restore the most recent full backup with WITH NORECOVERY.
  2. Apply one or more differential backups (if any) also with WITH NORECOVERY.
  3. Apply all required log backups in chronological order, ending with WITH RECOVERY or WITH STANDBY for a read‑only state.

Full Restore Example

RESTORE DATABASE [AdventureWorks] 
FROM DISK = N'C:\Backups\AdventureWorks_Full_2025_09_13.bak' 
WITH MOVE N'AdventureWorks_Data' TO N'D:\Data\AdventureWorks.mdf',
MOVE N'AdventureWorks_Log' TO N'D:\Logs\AdventureWorks_log.ldf',
NORECOVERY,
REPLACE,
STATS = 10;

Applying Differential Backup

RESTORE DATABASE [AdventureWorks] 
FROM DISK = N'C:\Backups\AdventureWorks_Diff_2025_09_13.bak' 
WITH NORECOVERY,
STATS = 10;

Applying Log Backups

RESTORE LOG [AdventureWorks] 
FROM DISK = N'C:\Backups\AdventureWorks_Log_2025_09_13.trn' 
WITH RECOVERY,
STATS = 10;

Best Practices

Troubleshooting

Common Errors

ErrorCauseResolution
2618 – Backup file already existsBackup file already present without WITH INITUse WITH INIT or specify a new filename.
3013 – Restore stopped because of errorIncorrect file paths or insufficient permissionsVerify paths, file existence, and service account rights.
4326 – Log chain brokenMissing log backup after a full backupEnsure regular log backups; re‑initialize chain with a new full backup.