Backup and Restore
A backup is only proven when you have restored it. Plan backups from how much data you can afford to lose.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Step-by-step screens
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Nov 26, 2026
Related tutorials
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#
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;
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#
- FULL recovery enables log backups and point-in-time restore.
- Full, differential and log backups are compressed and checksummed.
- The copy is restored under a new name with MOVE, so the live database is untouched.
- NORECOVERY leaves it ready for the next file.
- 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#
The log file grows until the disk is full. Schedule log backups or use SIMPLE.
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
RESTORE VERIFYONLY FROM DISK = N'D:\Backup\ShopDB_full.bak' WITH CHECKSUM;
Mini quiz#
Which recovery model allows point-in-time restore?
Want more? Practise all SQL Server MCQs · SQL Server interview questions
My notes#
Saved in this browser.