add sql-server-db-backup-and-restore-guide

This commit is contained in:
Othmane Ataallah 2026-04-29 11:32:42 +01:00
parent 6010b96146
commit 31a80bc72c
35 changed files with 258 additions and 0 deletions

View 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."
}
}

View File

@ -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."
}
}

View 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…**
![SSMS Backup Menu](img/1.png)
4. The **Back Up Database** window will open. Under **Backup type**, make sure **Full** is selected.
![Backup Type Full](img/2.png)
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**.
![Backup Destination](img/3.png)
6. Click **OK** to start the backup.
![Start Backup](img/4.png)
7. A confirmation dialog will appear when it completes successfully.
![Backup Success](img/5.png)
---
## Differential Backup
Follow the same steps as a full backup, with one change at step 4: under **Backup type**, select **Differential** instead of Full.
![Backup Type Differential](img/6.png)
**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`).
![Backup Type Transaction Log](img/7.png)
4. Click **OK** to run the backup.
![Start Log Backup](img/8.png)
**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.
![Check Recovery Model](img/9.png)
---
## 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**.
![Configure Backup](img/10.png)
2. At the top of the window, click **Script → Script Action to Job**
![Script to Job](img/11.png)
3. The **New Job** window will open. Go to the **Schedules** page and click **New**.
![New Schedule](img/12.png)
4. Define your schedule (frequency, start time, recurrence) and click **OK**.
![Define Schedule](img/13.png)
5. Click **OK** again to save the job. SQL Server Agent will run the backup automatically on the defined schedule.
![Save Job](img/14.png)
**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).
![SQL Server Agent Status](img/15.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View 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.

View File

@ -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) |

View File

@ -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…**
![SSMS Restore Menu](img/16.png)
2. The **Restore Database** window opens on the **General** page. Under **Source**, select **Device**, then click the … (Browse) button.
![Restore Source Device](img/17.png)
3. In the **Select backup devices** dialog, click **Add**.
![Add Backup Device](img/18.png)
4. Navigate to your `.bak` file, select it, and click **OK**. Then click **OK** again to close the dialog.
![Select BAK File](img/19.png)
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.
![Verify Restore Sets](img/20.png)
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.
![Restore Options](img/21.png)
9. A confirmation message will appear on success.
![Restore Success](img/22.png)
---
## Restore from a Full + Differential Backup
1. Follow steps 14 above, but when adding backup devices, add **both** the full backup file and the differential backup file.
![Add Multiple Backup Devices](img/23.png)
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.
![Multiple Restore Sets](img/24.png)
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 14 above, adding the full backup file **and all transaction log** (`.trn`) files in the **Select backup devices** dialog.
![Add Log Files](img/25.png)
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**.
![Restore Timeline](img/26.png)
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.
![Rename Database](img/27.png)
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.
![Relocate Files](img/28.png)
5. Click **OK** to restore.

View File

@ -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}) {