SQL Server · Administration

Backup and Restore

A backup is only proven when you have restored it. Plan backups from how much data you can afford to lose.

Advanced 5 min Lesson 41 of 44Examples run on SQL Server 2022 and Azure SQL Database.
0/44 in SQL Server
On this page · 5 min · Advanced

Learning objectives#

  • Choose a recovery model
  • Take full, differential and log backups
  • Restore to a point in time
  • Verify and test backups

Explanation#

Recovery model SIMPLE: only full and differential backups; you can restore to the last backup. FULL: also log backups, so you can restore to any moment (point-in-time). Production databases where losing an hour of orders matters use FULL with log backups every 5–15 minutes.

A common plan: weekly full, daily differential (changes since the full), log backups every 15 minutes. Add WITH COMPRESSION, CHECKSUM and copy the files off the server.

To restore: the full backup WITH NORECOVERY, the latest differential WITH NORECOVERY, then the log backups in order, the last one WITH STOPAT = 'time', RECOVERY. In SSMS: right-click Databases → Restore Database…, choose the device and a point in time on the Timeline.

Test restores regularly on another server. RESTORE VERIFYONLY checks the file is readable, but only a real restore proves it works.

Step-by-step screens#

Drawings of SQL Server 2022 Setup and SQL Server Management Studio (SSMS 20) with the ShopDB sample database. The red numbers match the numbered actions under each picture; names on your computer will differ.

Loading pictures…

Code example: Backups and a point-in-time restore#

SQLBackups and a point-in-time restore Illustrative
ALTER DATABASE ShopDB SET RECOVERY FULL;


BACKUP DATABASE ShopDB TO DISK = N'D:\Backup\ShopDB_full.bak'  WITH COMPRESSION, CHECKSUM, INIT;
BACKUP DATABASE ShopDB TO DISK = N'D:\Backup\ShopDB_diff.bak'  WITH DIFFERENTIAL, COMPRESSION, CHECKSUM, INIT;
BACKUP LOG      ShopDB TO DISK = N'D:\Backup\ShopDB_log_1015.trn' WITH COMPRESSION, CHECKSUM;


-- Someone deleted orders at 10:12. Restore a copy as it was at 10:10:
RESTORE DATABASE ShopDB_Restore FROM DISK = N'D:\Backup\ShopDB_full.bak'
    WITH MOVE 'ShopDB' TO N'D:\Data\ShopDB_Restore.mdf', MOVE 'ShopDB_log' TO N'D:\Data\ShopDB_Restore.ldf', NORECOVERY;
RESTORE DATABASE ShopDB_Restore FROM DISK = N'D:\Backup\ShopDB_diff.bak' WITH NORECOVERY;
RESTORE LOG ShopDB_Restore FROM DISK = N'D:\Backup\ShopDB_log_1015.trn'
    WITH STOPAT = '2026-11-26T10:10:00', RECOVERY;
Expected output
Processed 1240 pages for database 'ShopDB', file 'ShopDB' on file 1.
BACKUP DATABASE successfully processed 1242 pages in 0.311 seconds (31.2 MB/sec).
...
RESTORE LOG successfully processed 18 pages in 0.040 seconds (3.5 MB/sec).

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. FULL recovery enables log backups and point-in-time restore.
  2. Full, differential and log backups are compressed and checksummed.
  3. The copy is restored under a new name with MOVE, so the live database is untouched.
  4. NORECOVERY leaves it ready for the next file.
  5. STOPAT stops just before the mistake; RECOVERY opens the database.

Real-world use case#

A developer ran DELETE without WHERE at 10:12. The DBA restored a copy as of 10:10 and copied the missing orders back — about two minutes of work lost instead of a day.

Common mistakes#

FULL recovery without log backups

The log file grows until the disk is full. Schedule log backups or use SIMPLE.

Backups only on the same server

If the disk or server dies, the backups die with it. Copy them elsewhere.

Best practices#

  • Match the plan to acceptable data loss
  • COMPRESSION and CHECKSUM
  • Copy backups off the server
  • Test restores monthly

Remember this#

SIMPLE = to the last backup; FULL = any moment.

Full → diff → logs.

An untested backup is a hope, not a plan.

Practice exercise#

Your task: Check that a backup file can be read without restoring it.

Show solution
SQL Illustrative
RESTORE VERIFYONLY FROM DISK = N'D:\Backup\ShopDB_full.bak' WITH CHECKSUM;

Mini quiz#

Backup and Restore quizMultiple choice Question 1 of 1

Which recovery model allows point-in-time restore?

Score so far: 0/0

Want more? Practise all SQL Server MCQs · SQL Server interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.