You open up your laptop on a Monday morning only to see a message from a developer. Some delete statement ran on a production table and it did not have a WHERE clause and hundreds of customer records are now lost. Can you get those records back?
Of course, the answer would be yes if you do have a working backup. If you don't, the costs would be very hefty. In fact, any type of incident - hardware failures, human errors, corruption, ransomware - can and will happen at any moment with a database. SQL Server backup and restore can be your best possible safety net against any of those problems.
In this blog, we will explain to you what SQL Server backup and restore are all about, the backup types and recovery models that you have in place and how exactly to perform a backup and restore process with SSMS and T-SQL. We will also tell you all about point-in-time recovery along with several possible mistakes you might make and how to avoid them.
Also Explore: SQL Server vs MySQL
SQL Server Backup and Restore is an in built process of copying database data and transaction logs to protect against data loss and then recovering those copies after a failure or corruption. It serves as a main pillar of database disaster recovery and data protection.
Regular backups let you restore a database to an earlier state. This reduces the risk of losing important information.
Here are the key terms you will see in this guide:
Your RPO and RTO decide your backup plan. A bank that can lose zero minutes of data needs a different plan from a small blog that can lose a day.
SQL Server supports five main backup types. Each one answers a different need.
| Backup type | What it contains | Best for |
| Full | The entire database | The base of every backup plan |
| Differential | Changes since the last full backup | Faster daily backups |
| Transaction log | Log records since the last log backup | Point-in-time recovery |
| Copy-only | A full or log copy outside the normal chain | Ad hoc copies for testing |
| File and filegroup | Selected files or filegroups | Very large databases |
A full backup copies all the data in the database. It also copies enough of the transaction log to bring the database to a consistent state on restore. Every other backup type depends on it.
| BACKUP DATABASE SalesDB TO DISK = N'D:\SQLBackups\SalesDB_Full.bak' WITH COMPRESSION, CHECKSUM, STATS = 10; |
A full backup of a large database takes time and space. Most teams run it once a day or once a week.
A differential backup copies only the data that changed since the last full backup. It is smaller and faster than a full backup. Each new differential grows larger until the next full backup resets it.
| BACKUP DATABASE SalesDB TO DISK = N'D:\SQLBackups\SalesDB_Diff.bak' WITH DIFFERENTIAL, COMPRESSION, CHECKSUM; |
To restore from a differential, you need the full backup first and then the latest differential.
A transaction log backup records every transaction since the previous log backup. It lets you restore a database to a specific moment. You can run it every few minutes to keep data loss very low.
| BACKUP LOG SalesDB TO DISK = N'D:\SQLBackups\SalesDB_Log.trn' WITH COMPRESSION, CHECKSUM; |
Two rules apply here. The database must use the Full or Bulk-logged recovery model. A full backup must also exist before the first log backup.
A tail-log backup is a special log backup. It captures the last records that no earlier log backup has saved. You take it just before a restore so you do not lose the most recent work.
A copy-only backup is a standalone copy. It does not change the backup chain. A copy-only full backup does not reset the differential base. A copy-only log backup does not truncate the log.
| BACKUP DATABASE SalesDB TO DISK = N'D:\SQLBackups\SalesDB_CopyOnly.bak' WITH COPY_ONLY, COMPRESSION; |
Use it when you need a quick copy for a test server and do not want to disturb your schedule.
A file or filegroup backup copies only part of a database. It suits very large databases where a full backup takes too long. You can back up one filegroup each night and still protect the whole database.
| BACKUP DATABASE SalesDB FILEGROUP = N'PRIMARY' TO DISK = N'D:\SQLBackups\SalesDB_Primary.bak'; |
This method needs more planning. You must keep transaction log backups so you can bring all files to the same point in time.
Read Also: How to Install Microsoft SQL Server?
A recovery model controls how SQL Server logs transactions. It also decides which backups you can take and which restores you can run. Every database uses one of three models.
| Feature | Simple | Full | Bulk-logged |
| Log backups | Not supported | Supported | Supported |
| Point-in-time restore | No | Yes | Limited |
| Log management | SQL Server clears the log automatically | You must back up the log to clear it | You must back up the log to clear it |
| Data loss risk | Everything since the last backup | Very low | Low, but higher during bulk operations |
| Best for | Test and development | Production systems | Short bulk loads |
Simple: SQL Server clears the log at each checkpoint. You can restore only to your last full or differential backup. Any work after that is lost.
Full: SQL Server retains transaction log records until they are eligible for truncation. Log backups normally allow inactive log records to be reused, subject to other factors. You can restore to a specific point in time covered by your log backups, provided the required backup chain is intact. Most production databases use this model.
Bulk-logged: This model logs bulk operations, such as BULK INSERT, with minimal detail. It saves log space. You cannot restore to a point in time inside a log backup that holds bulk changes.
Check the current model of every database with this query:
| SELECT name, recovery_model_desc FROM sys.databases; |
Change the model with ALTER DATABASE:’
| ALTER DATABASE SalesDB SET RECOVERY FULL; |
A new database copies its recovery model from the model system database. After you switch from Simple to Full, take a full backup right away. The log chain starts only after that backup.
If you are not sure which model fits, choose Full for production and Simple for test systems.
Also Read: MongoDB vs MySQL: Understanding Key Differences
You need the right permissions first. Membership in the sysadmin server role, the db_owner role or the db_backupoperator role is enough. The SQL Server service account also needs write access to the backup folder.
T-SQL gives you more control and works well in scripts and scheduled jobs. Use the BACKUP DATABASE command for full and differential backups, and BACKUP LOG for log backups. The earlier examples show each form.
Add these options when they fit your needs:
A backup that you never check is only a hope. Run this command to confirm that SQL Server can read the file:
| RESTORE VERIFYONLY FROM DISK = N'D:\SQLBackups\SalesDB_Full.bak' WITH CHECKSUM; |
You can also read your backup history from the msdb database:
| SELECT TOP 10 database_name, type, backup_start_date, backup_finish_date FROM msdb.dbo.backupset ORDER BY backup_finish_date DESC; |
In the type column, D means full, I means differential and L means log.
Create a SQL Server Agent job for each backup type. A common schedule looks like this:
| Backup | Frequency |
| Full | Weekly, on Sunday night |
| Differential | Daily, at night |
| Transaction log | Every 15 minutes |
SQL Server Express does not include SQL Server Agent. On Express, you can run a T-SQL script with sqlcmd and schedule it in Windows Task Scheduler.
A restore copies data from backup files into a database. Then SQL Server runs recovery to bring the database online. Follow the right order. You restore the full backup first, then the latest differential, and then the log backups.
Use the RESTORE DATABASE command for a simple full restore. Use WITH REPLACE only when you intentionally want to overwrite an existing database, after verifying the target database and backup.
| RESTORE DATABASE SalesDB FROM DISK = N'D:\SQLBackups\SalesDB_Full.bak' WITH REPLACE, RECOVERY, STATS = 10; |
When you restore to a new server, the drive paths may differ. First, list the files inside the backup:
| RESTORE FILELISTONLY FROM DISK = N'D:\SQLBackups\SalesDB_Full.bak'; |
Then use the MOVE option to place each file in a new location:
| RESTORE DATABASE SalesDB_Copy FROM DISK = N'D:\SQLBackups\SalesDB_Full.bak' WITH MOVE N'SalesDB' TO N'E:\Data\SalesDB_Copy.mdf', MOVE N'SalesDB_log' TO N'F:\Logs\SalesDB_Copy_log.ldf', RECOVERY; |
These three options decide what happens after each restore step.
| Option | What it does | When to use it |
| RECOVERY | Brings the database online | On the last restore step |
| NORECOVERY | Keeps the database in a restoring state | When more backups are still to come |
| STANDBY | Keeps the database read-only and ready for more restores | When you want to read data between restore steps |
If you forget NORECOVERY on an early step, SQL Server brings the database online. You then cannot apply the next backup and must start over.
| RESTORE DATABASE SalesDB FROM DISK = N'D:\SQLBackups\SalesDB_Full.bak' WITH NORECOVERY, REPLACE; RESTORE DATABASE SalesDB FROM DISK = N'D:\SQLBackups\SalesDB_Diff.bak' WITH NORECOVERY; RESTORE LOG SalesDB FROM DISK = N'D:\SQLBackups\SalesDB_Log.trn' WITH RECOVERY; |
Remember one rule about versions. You can restore a backup to the same SQL Server version or a newer one. You cannot restore it to an older version.
A point-in-time restore returns a database to an exact moment before a problem happened. It is the best tool for accidental deletes and bad updates.
You need three things:
Suppose someone deleted rows at 2:35 PM on 27 November 2026. You want the database as it looked at 2:30 PM.
| --- Step 1: Back up the tail of the transaction log BACKUP LOG SalesDB TO DISK = 'C:\Backups\SalesDB_Tail.trn' WITH NORECOVERY, NO_TRUNCATE, STATS = 10; GO -- Step 2: Restore the full backup RESTORE DATABASE SalesDB FROM DISK = 'C:\Backups\SalesDB_Full.bak' WITH NORECOVERY, REPLACE, STATS = 10; GO -- Step 3: Restore the latest differential backup RESTORE DATABASE SalesDB FROM DISK = 'C:\Backups\SalesDB_Diff.bak' WITH NORECOVERY, STATS = 10; GO -- Step 4: Restore the first transaction log backup RESTORE LOG SalesDB FROM DISK = 'C:\Backups\SalesDB_Log_1.trn' WITH NORECOVERY, STATS = 10; GO -- Step 5: Restore the next transaction log backup, if one exists RESTORE LOG SalesDB FROM DISK = 'C:\Backups\SalesDB_Log_2.trn' WITH NORECOVERY, STATS = 10; GO -- Step 6: Restore the tail-log backup to the target time RESTORE LOG SalesDB FROM DISK = 'C:\Backups\SalesDB_Tail.trn' WITH STOPAT = '2026-11-27 14:30:00', RECOVERY, STATS = 10; GO |
You can also use the SSMS Restore Database window. Click Timeline, choose Specific date and time and enter the target time. SSMS then builds the restore sequence for you.
Keep these points in mind:
Every DBA sees these errors sooner or later. This table shows the most common ones.
| Error | Cause | How to fix it |
| Msg 3159: The tail of the log has not been backed up | Some recent database changes have not been saved in a backup. Restoring now could cause data loss. | Take a tail-log backup before restoring. If you do not need the remaining changes, use WITH REPLACE. |
| Msg 3101: Exclusive access could not be obtained | Other users or applications are connected to the database, so SQL Server cannot restore it. | Disconnect other users, switch the database to SINGLE_USER mode, restore it, and then switch it back to MULTI_USER mode. |
| Msg 3201: Cannot open backup device (OS error 5) | SQL Server cannot access the backup file because the path is incorrect or it lacks permission. | Check the file path and give the SQL Server service account the required permissions to access the backup file. |
| Msg 3154: The backup set holds a backup of a different database | The backup belongs to a different database than the one you are trying to restore. | Use WITH REPLACE if you want to overwrite the existing database, or restore the backup using a new database name. |
| Msg 3156: File cannot be restored | SQL Server cannot find the original database file location on the new server. | Use RESTORE FILELISTONLY to check the database files and the MOVE option to specify a valid location. |
| Msg 3169: Backup is incompatible with this server | The backup was created using a newer version of SQL Server than the one you are restoring it to. | Restore the backup on the same or a newer SQL Server version. |
| Msg 4305: The log in this backup set begins at LSN... too recent | An earlier transaction log backup is missing, so SQL Server cannot restore the current log backup in the correct order. | Find the missing log backup and restore all required log backups in the correct sequence. |
Here is the fix for the exclusive access error:
| ALTER DATABASE SalesDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE; RESTORE DATABASE SalesDB FROM DISK = N'D:\SQLBackups\SalesDB_Full.bak' WITH REPLACE, RECOVERY; ALTER DATABASE SalesDB SET MULTI_USER; |
If SQL Server reports a damaged or unreadable backup file, run RESTORE VERIFYONLY and RESTORE HEADERONLY on it. If the file is truly corrupt, restore from your next older backup set.
Follow these habits to keep your data safe.
1. Define your RPO and RTO first: Your backup schedule must match what the business can afford to lose and to wait.
2. Follow the 3-2-1 rule: Keep three copies of your backups, on two types of media, with one copy off site or in the cloud.
3. Use the Full recovery model for production: It gives you point-in-time recovery. Remember to schedule log backups, or the log file will keep growing.
4. Combine backup types: A weekly full, a daily differential and frequent log backups balance speed and safety.
5. Use CHECKSUM and COMPRESSION: CHECKSUM finds damaged pages early. COMPRESSION saves space and time.
6. Test your restores regularly: Restore backups to a test server on a schedule. A backup counts only when you have proven it can restore.
7. Run DBCC CHECKDB: Check database integrity often. A backup of a corrupt database is a corrupt backup.
8. Encrypt your backups: Use native backup encryption and protect the certificate. Without that certificate, you cannot restore the backup.
| BACKUP DATABASE SalesDB TO DISK = N'D:\SQLBackups\SalesDB_Enc.bak' WITH ENCRYPTION (ALGORITHM = AES_256, SERVER CERTIFICATE = BackupCert); |
9. Back up the system databases: The master and msdb databases hold logins, jobs and backup history. Include them in your plan.
10. Store backups away from the data drive: A disk failure should never take out both the database and its backup.
11. Automate and monitor: Use SQL Server Agent jobs and alerts. Review msdb.dbo.backupset to confirm that every job runs.
12. Document your restore steps: Write a short runbook. In a real emergency, a clear checklist saves time.
SQL Server 2022 and later can also back up to S3-compatible object storage. Azure Blob Storage works as a backup target too. Cloud storage is a simple way to meet the off-site part of the 3-2-1 rule.
SQL Server backup and restore protects your data from hardware failures, human mistakes and corruption. You now know the five backup types, the three recovery models and the exact steps to back up and restore a database. You also know how to run a point-in-time restore and how to fix common errors.
To get started, check the recovery model of every database. Then set up a full, differential and log backup schedule. Finally, restore one backup to a test server this week. That single test tells you more about your safety than any setting.
A full backup copies the entire database. A differential backup copies only the data that changed since the last full backup. Differentials are smaller and faster, but you need the full backup to restore them.
It depends on your RPO. Many production systems take a weekly full backup, a daily differential backup and a log backup every 15 minutes. If you can lose less data, run log backups more often.
No, SQL Server cannot restore a backup to a version older than the one that created it. You can restore it to the same or a newer version.
Yes. SQL Server backs up databases online, so users can keep working. Performance may drop a little during large backups so schedule them in quiet hours when you can.
It leaves the database in a restoring state so you can apply more backups. You use it on every step except the last one. The last step uses RECOVERY to bring the database online
No, the Simple model does not support log backups. Use the Full recovery model if you need point-in-time recovery.