0% found this document useful (0 votes)
9 views4 pages

Backup Guide

The System Admin Guide outlines the backup and disaster recovery procedures for a PostgreSQL-based Food Ordering System, detailing both manual and automated backup methods using pg_dump and Windows Task Scheduler. It also provides steps for restoring data after a disaster and conducting a disaster simulation drill to ensure backup integrity. Additionally, a cheat sheet of common commands is included for quick reference.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Backup Guide

The System Admin Guide outlines the backup and disaster recovery procedures for a PostgreSQL-based Food Ordering System, detailing both manual and automated backup methods using pg_dump and Windows Task Scheduler. It also provides steps for restoring data after a disaster and conducting a disaster simulation drill to ensure backup integrity. Additionally, a cheat sheet of common commands is included for quick reference.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

System Admin Guide: Backup & Disaster

Recovery
Food Ordering System (PostgreSQL)
Strategy: Zero-Code / External Tools
Role Required: System Administrator (Windows)
Tools Used: pg_dump.exe, [Link], Windows Task Scheduler
1. Prerequisites
Before starting, ensure you can access the PostgreSQL tools.
1.​ Open Command Prompt ([Link]).
2.​ Type pg_dump --version and press Enter.
○​ Success: It prints something like pg_dump (PostgreSQL) 17.2. You are ready to
proceed.
○​ Failure: If it says 'pg_dump' is not recognized..., follow the fix below before
continuing.
Fix: "Command Not Recognized" (Add to PATH)
1.​ Press the Windows key, type "env", and select "Edit the system environment
variables".
2.​ Click the "Environment Variables" button at the bottom right.
3.​ Under "System variables" (the bottom list), find the row named "Path", select it, and
click "Edit".
4.​ Click "New" on the right side.
5.​ Paste the path to your PostgreSQL bin folder.
○​ Typical Path: C:\Program Files\PostgreSQL\17\bin
○​ (Note: Check your C: drive to confirm if it is version 16, 17, or another number).
6.​ Click OK on all three open windows.
7.​ Important: Close your Command Prompt window and open a new one.
8.​ Type pg_dump --version again. It should now work.

2. Routine Backup Procedures


A. Manual Backup (On Demand)
Perform this before making major changes to the computer or updating software.
1.​ Create a folder to store backups (e.g., C:\Backups).
2.​ Open Command Prompt.
3.​ Run the following command (replace macalanda with your actual DB password if
different):
4.​ ​
set PGPASSWORD=macalanda​
pg_dump -h localhost -U postgres -F p -f "C:\Backups\foodhub_manual.sql"
foodordering​

5.​ Verify: Check the C:\Backups folder. You should see foodhub_manual.sql. Open it with
Notepad; if you see SQL text (CREATE TABLE, INSERT INTO...), it was successful.
B. Automated Backup (Daily Schedule)
Set this up once, and Windows will automatically back up your database every day.
1.​ Create the Script:
○​ Open Notepad.
○​ Paste the following code:​
@echo off​
set PGPASSWORD=macalanda​

:: Get the current date for the filename (Format: YYYY-MM-DD)​
set DATESTAMP=%date:~10,4%-%date:~4,2%-%date:~7,2%​

:: Run the backup​
:: NOTE: Ensure this path matches your PostgreSQL installation version​
"C:\Program Files\PostgreSQL\17\bin\pg_dump.exe" -h localhost -U postgres -d
foodordering -f "C:\Backups\foodhub_%DATESTAMP%.sql"​

:: Optional: Delete backups older than 7 days (Advanced)​
:: forfiles /p "C:\Backups" /s /m *.sql /D -7 /C "cmd /c del @path"​

○​ Save the file as C:\Backups\daily_backup.bat.


2.​ Schedule the Task:
○​ Press Win + R, type [Link], and press Enter.
○​ Click Create Basic Task on the right.
○​ Name: "FoodHub Daily Backup".
○​ Trigger: Daily (e.g., at 11:00 PM).
○​ Action: Start a program -> Browse to C:\Backups\daily_backup.bat.
○​ Click Finish.

3. Disaster Recovery (Restoring Data)


Use this procedure if the computer crashes, the hard drive is replaced, or the database is
accidentally deleted.

Scenario: Fresh Install / Total Loss


Assuming you have re-installed PostgreSQL and have your .sql backup file ready.
1.​ Stop the App: Ensure the Food Ordering App is closed.
2.​ Open Command Prompt.
3.​ Create a clean database (if it doesn't exist):​
set PGPASSWORD=macalanda​
psql -U postgres -c "CREATE DATABASE foodordering;"​

4.​ Restore the Data:​


psql -U postgres -d foodordering -f "C:\Backups\foodhub_manual.sql"​

(Replace foodhub_manual.sql with your specific backup filename)
5.​ Restart the App: Open your C# application. It should now see all the data exactly as it
was at the time of backup.

4. Disaster Simulation Drill (Safe to Run)


To trust your backups, you must simulate a failure. Warning: This deletes the current
database. Ensure you do Step 1 carefully.

Step 1: The Safety Net (Create a fresh backup)


First, we save exactly what you have right now.
1.​ Open Command Prompt.
2.​ Run this command to create a special simulation backup file:​
set PGPASSWORD=macalanda​
pg_dump -h localhost -U postgres -F p -f "C:\Backups\simulation_test.sql" foodordering​

3.​ Check: Go to your C:\Backups folder. Confirm you see simulation_test.sql there. Do not
proceed if this file is missing.
Step 2: The Disaster (Delete the Database)
Now we simulate the accident. We will delete the entire foodordering database.
1.​ Run this command:​
psql -U postgres -c "DROP DATABASE foodordering;"​

(If it says "database is being accessed by other users", close your C# App and try again).
2.​ Verify the Damage:
○​ Open your FoodOrderingSystem (C# App).
○​ Try to login.
○​ Result: It should Crash or show a Connection Error. This confirms the database is
gone.
Step 3: The Recovery
Now, use your backup file to bring it back.
1.​ In Command Prompt, run these two commands (one after the other):​
Command A (Create the empty shell):​
psql -U postgres -c "CREATE DATABASE foodordering;"​

Command B (Pour the data back in):​
psql -U postgres -d foodordering -f "C:\Backups\simulation_test.sql"​

Step 4: Final Verification


1.​ Open your FoodOrderingSystem (C# App) again.
2.​ Login.
3.​ Result: You should see all your menu items, users, and sales history exactly as they were
before.

5. Cheat Sheet (Common Commands)

Action Command

Backup pg_dump -U postgres -d foodordering -f


"[Link]"

Restore psql -U postgres -d foodordering -f


"[Link]"

List DBs psql -U postgres -c "\l"

Drop DB psql -U postgres -c "DROP DATABASE


foodordering"

You might also like