# PostgreSQL Backup / Restore Runbook — v0.34.0

## Backup
`python manage.py backup_database`

Creates a PostgreSQL custom-format `.dump`, verifies that `pg_restore --list` can read it, and writes a SHA-256 sidecar file. Old dumps are removed using BACKUP_RETENTION_DAYS.

## Verify
`python manage.py verify_backup /path/to/file.dump`

Verifies archive readability and SHA-256 when the sidecar exists.

## Restore
Restore is intentionally guarded and not exposed as a browser button.

`python manage.py restore_database /path/to/file.dump --confirm-db <DB_NAME> --confirm-project HRPAY-BMD-20260911-01`

By default the command takes a fresh `pre-restore` backup before restoring. After restore: run migrations/checks, start the application in maintenance/testing mode, and verify employee/payroll counts before users are allowed back in.

## Local UAT proof required before Go-Live
1. Create backup.
2. Verify backup.
3. Restore into a disposable/test PostgreSQL database or Local UAT environment.
4. Log in and check sample Employee, Attendance, Payroll, Loan and Audit records.
5. Record the result in the UAT checklist.

Do not treat a backup as successful until a restore test has been completed.
