Skip to content

Commit

Permalink
10491-dxox: remove docker volumes on run-local.sh and update postgres…
Browse files Browse the repository at this point in the history
… restore documentation for manual steps
  • Loading branch information
pixiwyn committed Dec 31, 2024
1 parent ddf740b commit eafe909
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
51 changes: 50 additions & 1 deletion docs/postgres/restore.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
# Postgres - Restore Database

## Database goes offline (Fire drill)
## Database goes offline / Lost data (Fire drill)

Ensure snapshot exists for restore (aws console, rds -> snapshots).

### Manual Restore Process

- In AWS, restore from desired snapshot to restore instance.

- Source to your target env

- Using the script below
`scripts/postgres/connect.sh`

- Temporarily modify the line
`PGPASSWORD="$DB_TOKEN" psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME"`

To restore the database:
```
PGPASSWORD="$DB_TOKEN" pg_restore \
--host="$DB_HOST" \
--username="$DB_USER" \
--dbname="$DB_NAME" \
--port="$DB_PORT" \
--format=c \
--verbose \
--clean \
--no-privileges \
--no-owner \
--table=dw_case \ # optional if doing per table
--jobs=3 \
"backup.sql"
```

To backup the database:
```
PGPASSWORD="$DB_TOKEN" pg_dump \ # change to restore instance password
--host="$DB_HOST" \ # change to restore instance host
--username="$DB_USER" \
--port="$DB_PORT" \
--dbname="$DB_NAME" \
--file="backup.sql" \
--format=c \
--no-privileges \
--no-owner \
--verbose
```

- Run the script for the backup and restore operation (separately one at a time).

- Re-add indexes using tables plus by going to each table on the restore instance under the structure tab copy and paste to target instance (writer).

- Delete the restore instance and regional cluster (in this order).

### Terraform Process

#### Prepare for deletion
Expand Down
2 changes: 1 addition & 1 deletion run-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

if [[ -z "$CI" ]]; then
echo "Stopping postgres in case it's already running"
$DOCKER_COMPOSE -f web-api/src/persistence/postgres/docker-compose.yml down || true
$DOCKER_COMPOSE -f web-api/src/persistence/postgres/docker-compose.yml down --volumes || true

echo "Starting postgres"
$DOCKER_COMPOSE -f web-api/src/persistence/postgres/docker-compose.yml up -d || { echo "Failed to start Postgres containers"; exit 1; }
Expand Down

0 comments on commit eafe909

Please sign in to comment.