feat(parallel-backupfile-added)-v4
This commit is contained in:
@@ -7,6 +7,7 @@ This document explains how to **restore the DentalApp PostgreSQL database** on a
|
|||||||
## 🧩 Overview
|
## 🧩 Overview
|
||||||
|
|
||||||
You will:
|
You will:
|
||||||
|
|
||||||
1. Create a PostgreSQL backup on the **main PC**
|
1. Create a PostgreSQL backup on the **main PC**
|
||||||
2. Copy it to the **target PC**
|
2. Copy it to the **target PC**
|
||||||
3. Restore it cleanly using `pg_restore`
|
3. Restore it cleanly using `pg_restore`
|
||||||
@@ -16,12 +17,14 @@ You will:
|
|||||||
## ⚙️ Prerequisites
|
## ⚙️ Prerequisites
|
||||||
|
|
||||||
Before starting:
|
Before starting:
|
||||||
|
|
||||||
- PostgreSQL is installed on both machines (same major version recommended)
|
- PostgreSQL is installed on both machines (same major version recommended)
|
||||||
- The app is **not running** during restore
|
- The app is **not running** during restore
|
||||||
- You know the database credentials
|
- You know the database credentials
|
||||||
*(from `.env` or environment variables)*
|
_(from `.env` or environment variables)_
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/dentalapp
|
DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/dentalapp
|
||||||
```
|
```
|
||||||
@@ -29,19 +32,23 @@ DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/dentalapp
|
|||||||
## 🧭 Steps to Restore Database on Another PC
|
## 🧭 Steps to Restore Database on Another PC
|
||||||
|
|
||||||
### 🖥️ Step 1 — Create Backup on Main PC
|
### 🖥️ Step 1 — Create Backup on Main PC
|
||||||
|
|
||||||
- Generate the backup.dump file from the backup page from the app.
|
- Generate the backup.dump file from the backup page from the app.
|
||||||
|
|
||||||
### Step 2 — Copy Backup File to Target PC
|
### Step 2 — Copy Backup File to Target PC
|
||||||
|
|
||||||
- Transfer the backup file to the second PC using USB, network share, cloud, or SCP.
|
- Transfer the backup file to the second PC using USB, network share, cloud, or SCP.
|
||||||
|
|
||||||
= Example destination path:
|
= Example destination path:
|
||||||
C:\db_backups\backup.dump
|
C:\db_backups\backup.dump
|
||||||
|
|
||||||
### 🧹 Step 3 — Prepare the Target PC
|
### 🧹 Step 3 — Prepare the Target PC
|
||||||
|
|
||||||
- Stop the DentalApp application to avoid database locks.
|
- Stop the DentalApp application to avoid database locks.
|
||||||
- Ensure PostgreSQL is installed and running.
|
- Ensure PostgreSQL is installed and running.
|
||||||
|
|
||||||
- (Optional but recommended) Drop the existing database:
|
- (Optional but recommended) Drop the existing database:
|
||||||
|
|
||||||
```
|
```
|
||||||
PGPASSWORD='mypassword' dropdb -U postgres -h localhost dentalapp
|
PGPASSWORD='mypassword' dropdb -U postgres -h localhost dentalapp
|
||||||
```
|
```
|
||||||
@@ -49,15 +56,17 @@ PGPASSWORD='mypassword' dropdb -U postgres -h localhost dentalapp
|
|||||||
### ♻️ Step 4 — Restore the Database
|
### ♻️ Step 4 — Restore the Database
|
||||||
|
|
||||||
# Case1: when we got a zip folder.
|
# Case1: when we got a zip folder.
|
||||||
|
|
||||||
-linux bash
|
-linux bash
|
||||||
|
|
||||||
# 4.1) unzip to a directory
|
# 4.1) unzip to a directory
|
||||||
|
|
||||||
```
|
```
|
||||||
unzip backup.zip -d /tmp/dental_dump_dir
|
unzip backup.zip -d /tmp/dental_dump_dir
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# 4.2) restore into an already-created DB named 'dentalapp'
|
# 4.2) restore into an already-created DB named 'dentalapp'
|
||||||
|
|
||||||
```
|
```
|
||||||
PGPASSWORD='mypassword' createdb -U postgres -h localhost -O postgres dentalapp # optional
|
PGPASSWORD='mypassword' createdb -U postgres -h localhost -O postgres dentalapp # optional
|
||||||
PGPASSWORD='mypassword' pg_restore -U postgres -h localhost -d dentalapp -j 4 /tmp/dental_dump_dir
|
PGPASSWORD='mypassword' pg_restore -U postgres -h localhost -d dentalapp -j 4 /tmp/dental_dump_dir
|
||||||
@@ -67,15 +76,19 @@ PGPASSWORD='mypassword' /usr/lib/postgresql/17/bin/pg_restore -v -U postgres -h
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Case2: when we got a tar folder.
|
# Case2: when we got a tar folder.
|
||||||
|
|
||||||
-linux bash
|
-linux bash
|
||||||
|
|
||||||
# 4.1) unzip to a directory
|
# 4.1) unzip to a directory
|
||||||
```
|
|
||||||
unzip backup.zip -d /tmp/dental_dump_dir
|
|
||||||
```
|
|
||||||
|
|
||||||
|
```
|
||||||
|
# create target dir and extract
|
||||||
|
mkdir -p /tmp/dental_dump_dir
|
||||||
|
tar -xzf backup.tar.gz -C /tmp/dental_dump_dir
|
||||||
|
```
|
||||||
|
|
||||||
# 4.2) restore into an already-created DB named 'dentalapp'
|
# 4.2) restore into an already-created DB named 'dentalapp'
|
||||||
|
|
||||||
```
|
```
|
||||||
PGPASSWORD='mypassword' createdb -U postgres -h localhost -O postgres dentalapp # optional
|
PGPASSWORD='mypassword' createdb -U postgres -h localhost -O postgres dentalapp # optional
|
||||||
PGPASSWORD='mypassword' pg_restore -U postgres -h localhost -d dentalapp -j 4 /tmp/dental_dump_dir
|
PGPASSWORD='mypassword' pg_restore -U postgres -h localhost -d dentalapp -j 4 /tmp/dental_dump_dir
|
||||||
@@ -84,10 +97,10 @@ or
|
|||||||
PGPASSWORD='mypassword' /usr/lib/postgresql/17/bin/pg_restore -v -U postgres -h localhost -C -d postgres /tmp/dental_dump_dir
|
PGPASSWORD='mypassword' /usr/lib/postgresql/17/bin/pg_restore -v -U postgres -h localhost -C -d postgres /tmp/dental_dump_dir
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### ✅ Step 5 — Verify the Restore
|
### ✅ Step 5 — Verify the Restore
|
||||||
|
|
||||||
- Check that the tables are restored successfully:
|
- Check that the tables are restored successfully:
|
||||||
|
|
||||||
```
|
```
|
||||||
PGPASSWORD='mypassword' psql -U postgres -h localhost -d dentalapp -c "\dt"
|
PGPASSWORD='mypassword' psql -U postgres -h localhost -d dentalapp -c "\dt"
|
||||||
```
|
```
|
||||||
@@ -97,6 +110,7 @@ PGPASSWORD='mypassword' psql -U postgres -h localhost -d dentalapp -c "\dt"
|
|||||||
### 🧩 Step 6 — Update App Configuration
|
### 🧩 Step 6 — Update App Configuration
|
||||||
|
|
||||||
- Ensure the .env file on the target PC points to the correct database:
|
- Ensure the .env file on the target PC points to the correct database:
|
||||||
|
|
||||||
```
|
```
|
||||||
DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/dentalapp
|
DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/dentalapp
|
||||||
```
|
```
|
||||||
@@ -107,22 +121,22 @@ DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/dentalapp
|
|||||||
|
|
||||||
- Use the same PostgreSQL version as the main PC.
|
- Use the same PostgreSQL version as the main PC.
|
||||||
|
|
||||||
|
|
||||||
- For large databases, use parallel restore for speed:
|
- For large databases, use parallel restore for speed:
|
||||||
|
|
||||||
```
|
```
|
||||||
pg_restore -U postgres -j 4 -d dentalapp backup.dump
|
pg_restore -U postgres -j 4 -d dentalapp backup.dump
|
||||||
```
|
```
|
||||||
|
|
||||||
- Always keep at least one recent backup archived safely.
|
- Always keep at least one recent backup archived safely.
|
||||||
|
|
||||||
|
# If such error came:
|
||||||
# If such error came:
|
|
||||||
|
|
||||||
- pg_restore: error: unsupported version (1.16) in file header
|
- pg_restore: error: unsupported version (1.16) in file header
|
||||||
|
|
||||||
- use cmd:
|
- use cmd:
|
||||||
|
|
||||||
- 1) Add PGDG (official PostgreSQL) APT repo and its key, then update and install client-17
|
- 1. Add PGDG (official PostgreSQL) APT repo and its key, then update and install client-17
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt update && sudo apt install -y wget ca-certificates gnupg lsb-release
|
sudo apt update && sudo apt install -y wget ca-certificates gnupg lsb-release
|
||||||
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/pgdg.gpg
|
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/pgdg.gpg
|
||||||
@@ -131,7 +145,8 @@ sudo apt update
|
|||||||
sudo apt install -y postgresql-client-17
|
sudo apt install -y postgresql-client-17
|
||||||
```
|
```
|
||||||
|
|
||||||
- 2) Run pg_restore from the installed v17 binary (replace password as needed)
|
- 2. Run pg_restore from the installed v17 binary (replace password as needed)
|
||||||
|
|
||||||
```
|
```
|
||||||
PGPASSWORD='mypassword' /usr/lib/postgresql/17/bin/pg_restore -v -U postgres -h localhost -C -d postgres ./backup.dump
|
PGPASSWORD='mypassword' /usr/lib/postgresql/17/bin/pg_restore -v -U postgres -h localhost -C -d postgres ./backup.dump
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user