add sql-server-db-backup-and-restore-guide
8
docs/database-operations/_category_.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"label": "Database Operations",
|
||||
"position": 4,
|
||||
"link": {
|
||||
"type": "generated-index",
|
||||
"description": "Guides for managing SQL Server databases, including backup, restore, and recovery operations."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
{
|
||||
"label": "Backup & Restore Guide",
|
||||
"position": 1,
|
||||
"link": {
|
||||
"type": "generated-index",
|
||||
"description": "Step-by-step guide for backing up and restoring SQL Server databases using SSMS."
|
||||
}
|
||||
}
|
||||
102
docs/database-operations/sql-server-backup-restore/backing-up.md
Normal file
@ -0,0 +1,102 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
title: "Backing Up a Database"
|
||||
---
|
||||
|
||||
# Backing Up a Database
|
||||
|
||||
---
|
||||
|
||||
Before performing a backup, choose the right type for your situation:
|
||||
|
||||
| Type | **What it captures** | **When to use** |
|
||||
| ------------------- | ------------------------------------------ | ----------------------------------------------- |
|
||||
| **Full** | The entire database | Weekly baseline; required before any other type |
|
||||
| **Differential** | Changes since the last full backup | Daily; faster and lighter than a full backup |
|
||||
| **Transaction Log** | All log activity since the last log backup | Hourly or more; enables point-in-time recovery |
|
||||
|
||||
---
|
||||
|
||||
## Full Backup
|
||||
|
||||
1. Open SSMS and connect to your SQL Server instance.
|
||||
2. In the **Object Explorer** panel, expand the **Databases** node.
|
||||
3. Right-click the database you want to back up, then select **Tasks → Back Up…**
|
||||
|
||||

|
||||
|
||||
4. The **Back Up Database** window will open. Under **Backup type**, make sure **Full** is selected.
|
||||
|
||||

|
||||
|
||||
5. Under **Destination**, you will see a default backup path. To change it:
|
||||
1. Click **Remove** to clear the existing path.
|
||||
2. Click **Add**, then type or browse to your desired folder and filename (e.g., `MyDatabase_Full_2025-04-22.bak`).
|
||||
3. Click **OK**.
|
||||
|
||||

|
||||
|
||||
6. Click **OK** to start the backup.
|
||||
|
||||

|
||||
|
||||
7. A confirmation dialog will appear when it completes successfully.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Differential Backup
|
||||
|
||||
Follow the same steps as a full backup, with one change at step 4: under **Backup type**, select **Differential** instead of Full.
|
||||
|
||||

|
||||
|
||||
**NOTE:** A differential backup requires that a full backup has already been taken for the same database.
|
||||
|
||||
---
|
||||
|
||||
## Transaction Log Backup
|
||||
|
||||
1. Right-click the database **→ Tasks → Back Up…**
|
||||
2. Under **Backup type**, select **Transaction Log**.
|
||||
3. Set the destination path and filename (e.g., `MyDatabase_Log_2025-04-22_10h00.trn`).
|
||||
|
||||

|
||||
|
||||
4. Click **OK** to run the backup.
|
||||
|
||||

|
||||
|
||||
**NOTE:** This option is only available when the database uses the **Full** or **Bulk-Logged** recovery model. To verify: right-click your database **→ Properties → Options →** check the **Recovery model** field.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Scheduling Automatic Backups
|
||||
|
||||
You can automate recurring backups directly from the backup window without any scripting:
|
||||
1. Configure your backup as described in the steps above, but **do not click OK yet**.
|
||||
|
||||

|
||||
|
||||
2. At the top of the window, click **Script → Script Action to Job**
|
||||
|
||||

|
||||
|
||||
3. The **New Job** window will open. Go to the **Schedules** page and click **New**.
|
||||
|
||||

|
||||
|
||||
4. Define your schedule (frequency, start time, recurrence) and click **OK**.
|
||||
|
||||

|
||||
|
||||
5. Click **OK** again to save the job. SQL Server Agent will run the backup automatically on the defined schedule.
|
||||
|
||||

|
||||
|
||||
**NOTE:** SQL Server Agent must be running for scheduled jobs to execute. You can check its status in Object Explorer (it appears as a node at the bottom of the tree).
|
||||
|
||||

|
||||
BIN
docs/database-operations/sql-server-backup-restore/img/1.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/10.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/11.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/12.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/13.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/14.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/15.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/16.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/17.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/18.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/19.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/2.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/20.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/21.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/22.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/23.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/24.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/25.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/26.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/27.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/28.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/3.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/4.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/5.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/6.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/7.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/8.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
docs/database-operations/sql-server-backup-restore/img/9.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
12
docs/database-operations/sql-server-backup-restore/index.md
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
title: "Overview"
|
||||
---
|
||||
|
||||
# Overview
|
||||
|
||||
---
|
||||
|
||||
SQL Server Management Studio (SSMS) is the official graphical tool for managing SQL Server. This guide walks through how to back up and restore a database entirely through its interface, with no scripting required.
|
||||
|
||||
All backup and restore operations in this guide produce or consume `.bak` files, which is SQL Server's native backup format.
|
||||
@ -0,0 +1,29 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
title: "Reference"
|
||||
---
|
||||
|
||||
# Reference
|
||||
|
||||
---
|
||||
|
||||
## Required Permissions
|
||||
|
||||
| **Operation** | **Required Role** |
|
||||
| ------------- | ------------------------------------------------ |
|
||||
| Backup | `db_backupoperator` database role, or `sysadmin` |
|
||||
| Restore | `sysadmin` or `dbcreator` server role |
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference
|
||||
|
||||
| Task | SSMS Path |
|
||||
| -------------------------- | -------------------------------------------------------- |
|
||||
| Full backup | Right-click DB → Tasks → Back Up → Type: Full |
|
||||
| Differential backup | Right-click DB → Tasks → Back Up → Type: Differential |
|
||||
| Transaction log backup | Right-click DB → Tasks → Back Up → Type: Transaction Log |
|
||||
| Schedule a backup | In the Back Up window → Script → Script Action to Job |
|
||||
| Restore a database | Right-click Databases → Restore Database |
|
||||
| Point-in-time restore | Restore Database → General → Timeline… |
|
||||
| Restore to new name/server | Restore Database → General (rename) + Files (relocate) |
|
||||
@ -0,0 +1,93 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
title: "Restoring a Database"
|
||||
---
|
||||
|
||||
# Restoring a Database
|
||||
|
||||
---
|
||||
|
||||
**WARNING:** Restoring a database **replaces its current contents**. Always confirm you are targeting the correct server and database before proceeding. Close any active connections to the target database beforehand.
|
||||
|
||||
---
|
||||
|
||||
## Restore from a Full Backup
|
||||
|
||||
1. In **Object Explorer**, right-click the **Databases** node (not a specific database) and select **Restore Database…**
|
||||
|
||||

|
||||
|
||||
2. The **Restore Database** window opens on the **General** page. Under **Source**, select **Device**, then click the … (Browse) button.
|
||||
|
||||

|
||||
|
||||
3. In the **Select backup devices** dialog, click **Add**.
|
||||
|
||||

|
||||
|
||||
4. Navigate to your `.bak` file, select it, and click **OK**. Then click **OK** again to close the dialog.
|
||||
|
||||

|
||||
|
||||
5. The backup details will populate in the **Backup sets to restore** grid. Verify that the correct backup is checked.
|
||||
6. Under **Destination**, confirm the database name in the **Database** field. You can type a new name here to restore as a different database.
|
||||
|
||||

|
||||
|
||||
7. Go to the **Options** page (left-hand panel). Check **Close existing connections to the destination database** to avoid connection conflicts during restore.
|
||||
8. Click **OK** to begin.
|
||||
|
||||

|
||||
|
||||
9. A confirmation message will appear on success.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Restore from a Full + Differential Backup
|
||||
|
||||
1. Follow steps 1–4 above, but when adding backup devices, add **both** the full backup file and the differential backup file.
|
||||
|
||||

|
||||
|
||||
2. SSMS will automatically detect the backup types and display them in the correct order in the **Backup sets to restore** grid.
|
||||
3. Make sure **both** the full and differential entries are checked.
|
||||
|
||||

|
||||
|
||||
4. Go to **Options**, check **Close existing connections to the destination database**.
|
||||
5. Click **OK** to restore.
|
||||
|
||||
---
|
||||
|
||||
## Point-in-Time Recovery (Transaction Logs)
|
||||
|
||||
1. Follow steps 1–4 above, adding the full backup file **and all transaction log** (`.trn`) files in the **Select backup devices** dialog.
|
||||
|
||||

|
||||
|
||||
2. SSMS will list all backup sets in the correct sequence in the grid. Verify all needed entries are checked.
|
||||
3. To restore to a specific point in time, click the **Timeline…** button at the top of the **General** page. In the **Backup Timeline** dialog, drag the slider or type a specific date and time, then click **OK**.
|
||||
|
||||

|
||||
|
||||
4. Go to **Options**, check **Close existing connections to the destination database**.
|
||||
5. Click **OK** to run the restore.
|
||||
|
||||
---
|
||||
|
||||
## Restoring to a Different Server or Name
|
||||
|
||||
To restore a backup onto a different server, or under a different database name:
|
||||
1. Connect SSMS to the **target server** (not the original one).
|
||||
2. Follow the restore steps in the section above.
|
||||
3. At step 6, change the **Database** name field to your desired new name.
|
||||
|
||||

|
||||
|
||||
4. Go to the **Files** page (left-hand panel). You will see the original file paths listed. Check **Relocate all files to folder** and specify the data and log folders on the target server.
|
||||
|
||||

|
||||
|
||||
5. Click **OK** to restore.
|
||||
@ -24,6 +24,12 @@ const categories = [
|
||||
description: 'Master Git operations across different tools like Apache NetBeans, JetBrains IDEs, and the Command-Line.',
|
||||
link: '/docs/category/git-operations',
|
||||
},
|
||||
{
|
||||
title: 'Database Operations',
|
||||
icon: '🗄️',
|
||||
description: 'Guides for managing SQL Server databases, including backup, restore, and advanced recovery operations.',
|
||||
link: '/docs/category/database-operations',
|
||||
},
|
||||
];
|
||||
|
||||
function CategoryCard({title, icon, description, link}) {
|
||||
|
||||