Compare commits

...

2 Commits

Author SHA1 Message Date
Othmane Ataallah
1a461e1847 add dead-pc-recovery
All checks were successful
Deploy triz-docs to civital server / build-and-deploy (push) Successful in 1h8m32s
2026-04-29 13:11:22 +01:00
Othmane Ataallah
31a80bc72c add sql-server-db-backup-and-restore-guide 2026-04-29 11:32:42 +01:00
39 changed files with 461 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": "Dead PC Recovery",
"position": 2,
"link": {
"type": "generated-index",
"description": "Guide for extracting database files from a failing or non-booting PC."
}
}

View File

@ -0,0 +1,26 @@
---
sidebar_position: 1
title: "Overview"
---
# Overview
---
This guide covers how to physically extract database files from a client's PC when the machine is failing or the database service cannot start, so that data can be saved to a USB drive and restored on a working machine.
There are two possible situations when you arrive at a client site:
| **Situation** | **What it means** | **Procedure** |
| ----------------------------------------------------- | --------------------------------------------- | ---------------------------------------------------- |
| **A — Windows boots, but the DB service won't start** | You can navigate the file system normally | Go directly to Part A |
| **B — Windows does not boot at all** | You need a live Linux USB to access the drive | Go to Part B first, then follow the extraction steps |
---
# What to Bring
Before going on-site, make sure you have:
- A **USB drive** with enough space (at least as large as the client's database, ideally 2x).
- A **bootable Linux live USB** (Ubuntu LTS recommended) — only needed if the PC doesn't boot.
- This guide, either printed or on your phone.

View File

@ -0,0 +1,68 @@
---
sidebar_position: 2
title: "Part A — Windows Boots"
---
# Part A — Windows Boots, Service is Down
---
In this case you can work directly in Windows Explorer or a command prompt. The database service does not need to be running to copy the files.
---
## A1 — SQL Server: Locate and Copy the Files
SQL Server databases consist of up to three file types, all of which you need:
| **File** | **Extension** | **Contains** |
| ------------------- | ------------- | ---------------------------------- |
| Primary data file | `.mdf` | The database schema and data |
| Secondary data file | `.ndf` | Overflow data (not always present) |
| Transaction log | `.ldf` | Transaction history |
**Default file locations by SQL Server version:**
| **Version** | **Default Data Path** |
| --------------- | ----------------------------------------------------------------------- |
| SQL Server 2012 | `C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\` |
| SQL Server 2014 | `C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\` |
| SQL Server 2016 | `C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\` |
| SQL Server 2017 | `C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\` |
| SQL Server 2019 | `C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\` |
| SQL Server 2022 | `C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\` |
| SQL Server 2025 | `C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\` |
**Steps:**
1. Open **Windows Explorer** and navigate to the data path for the installed SQL Server version (see table above).
2. Identify the files belonging to the target database. They will be named after the database, e.g. `ClientDB.mdf`, `ClientDB_log.ldf`.
3. Copy **all three file types** (`.mdf`, `.ndf` if present, `.ldf`) to your USB drive. Do not rename them.
4. Verify the copy completed without errors before ejecting the USB.
**Notes:**
- **Custom paths:** The client may have installed SQL Server with a non-default data path. If the files are not in the paths above, check the Windows Registry at: `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<instance>\MSSQLServer` Look for the `DefaultData` and `DefaultLog` keys.
- **Do not try to copy the system databases** (`master`, `model`, `msdb`, `tempdb`). Only copy the client's user database files.
---
## A2 — PostgreSQL: Locate and Copy the Files
PostgreSQL stores all databases in a single directory called `PGDATA`. Unlike SQL Server, you do not copy individual files — you copy the **entire data directory**.
**Default file locations by PostgreSQL version:**
| **Version** | **Default Data Path** |
| ------------- | -------------------------------------- |
| PostgreSQL 12 | `C:\Program Files\PostgreSQL\12\data\` |
| PostgreSQL 13 | `C:\Program Files\PostgreSQL\13\data\` |
| PostgreSQL 14 | `C:\Program Files\PostgreSQL\14\data\` |
| PostgreSQL 15 | `C:\Program Files\PostgreSQL\15\data\` |
| PostgreSQL 16 | `C:\Program Files\PostgreSQL\16\data\` |
**Steps:**
- Open **Windows Explorer** and navigate to the `data` folder for the installed PostgreSQL version (see table above).
- Copy the **entire `data` folder** to your USB drive. This single folder contains everything needed.
- Note the PostgreSQL version number from the folder path — you will need it when restoring.
**Notes:**
- **Note the version.** For each database in the cluster there is a subdirectory within `PGDATA/base`, named after the database's OID. Because these internal identifiers are version-specific, the data directory must be restored on a machine running the **exact same PostgreSQL version**.

View File

@ -0,0 +1,101 @@
---
sidebar_position: 3
title: "Part B — Windows Does Not Boot"
---
# Part B — Windows Does Not Boot (Linux Live USB)
---
If the client's PC will not boot into Windows, you will use a Linux live environment to access the hard drive and copy the database files.
---
## B1 — Boot from the Linux Live USB
1. Insert your bootable Ubuntu USB into the dead PC.
2. Power on the PC and enter the **Boot Menu** (usually `F8`, `F11`, or `F12` — varies by manufacturer).
3. Select your USB drive from the boot menu.
4. When Ubuntu loads, choose **"Try Ubuntu"** (do not install).
---
## B2 — Mount the Windows Drive
Ubuntu may mount the Windows drive automatically. If not:
1. Open the **Files** application (file manager). The Windows drive should appear in the left sidebar — click it to mount it.
2. If it doesn't appear, open a **Terminal** and run:
```bash
# List all available drives and partitions
sudo fdisk -l
```
Look for a partition of type `NTFS` with the size matching the client's main drive (e.g., `/dev/sda3`). Then mount it:
```bash
sudo mkdir -p /mnt/windows
sudo mount -t ntfs-3g /dev/sda3 /mnt/windows
```
Replace `/dev/sda3` with the correct partition name from `fdisk -l`.
3. Verify the drive is mounted:
```bash
ls /mnt/windows
```
You should see the familiar Windows folders: `Users`, `Program Files`, `Windows`, etc.
---
## B3 — Mount the USB Drive
1. Plug in your USB drive. Ubuntu will mount it automatically under `/media/ubuntu/`.
2. Find the exact mount point:
```bash
ls /media/ubuntu/
```
Note the folder name (it will be the USB drive label, e.g., `SUPPORT_USB`). Your full USB path will be something like `/media/ubuntu/SUPPORT_USB`.
---
## B4 — SQL Server: Copy Files from the Dead Drive
Navigate to the SQL Server data directory and copy the files:
```bash
# Adjust the MSSQL version folder (MSSQL14=2017, MSSQL15=2019, MSSQL16=2022)
ls "/mnt/windows/Program Files/Microsoft SQL Server/MSSQL15.MSSQLSERVER/MSSQL/DATA/"
```
You will see all `.mdf`, `.ndf`, and `.ldf` files listed. Copy the client's database files to the USB:
```bash
# Create a folder on the USB for organization
mkdir -p /media/ubuntu/SUPPORT_USB/SQLServer_Recovery
# Copy the target database files (replace ClientDB with the actual name)
sudo cp "/mnt/windows/Program Files/Microsoft SQL Server/MSSQL15.MSSQLSERVER/MSSQL/DATA/ClientDB.mdf" \ /media/ubuntu/SUPPORT_USB/SQLServer_Recovery/
sudo cp "/mnt/windows/Program Files/Microsoft SQL Server/MSSQL15.MSSQLSERVER/MSSQL/DATA/ClientDB_log.ldf" \ /media/ubuntu/SUPPORT_USB/SQLServer_Recovery/
# If a secondary file exists, copy it too
sudo cp "/mnt/windows/Program Files/Microsoft SQL Server/MSSQL15.MSSQLSERVER/MSSQL/DATA/ClientDB.ndf" \ /media/ubuntu/SUPPORT_USB/SQLServer_Recovery/ 2>/dev/null || true
```
---
## B5 — PostgreSQL: Copy Files from the Dead Drive
```bash
# Create a folder on the USB
mkdir -p /media/ubuntu/SUPPORT_USB/PostgreSQL_Recovery
# Copy the entire data directory (adjust version number as needed)
sudo cp -r "/mnt/windows/Program Files/PostgreSQL/15/data" \
/media/ubuntu/SUPPORT_USB/PostgreSQL_Recovery/
```

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