From 724426d2c545295bfc59108ba14ce67d0b9a5430 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Fri, 10 Nov 2023 05:52:01 +0000 Subject: [PATCH] docs: add info for restoring from db backup --- docs/dev/Backend.md | 4 +++- docs/dev/Database-Tips.md | 6 ++++-- docs/dev/Production.md | 13 ++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/dev/Backend.md b/docs/dev/Backend.md index 48aee8573d..ea4af0a69f 100644 --- a/docs/dev/Backend.md +++ b/docs/dev/Backend.md @@ -52,7 +52,9 @@ Running the database in Docker means postgres does not need to be installed on y 2. Start an instance of Postgres (with Postgis): ```bash -docker run -d --name fmtm_db -e POSTGRES_PASSWORD=xxxx -p 5432:5432 postgis/postgis:15-3.3 +GIT_BRANCH=development + +docker run -d --name fmtm-db-${GIT_BRANCH} -e POSTGRES_PASSWORD=xxxx -p 5432:5432 postgis/postgis:15-3.3 ``` The database should be accessible at localhost:5432. diff --git a/docs/dev/Database-Tips.md b/docs/dev/Database-Tips.md index 37eeab4539..17f9faa227 100644 --- a/docs/dev/Database-Tips.md +++ b/docs/dev/Database-Tips.md @@ -12,10 +12,12 @@ psql -d fmtm -U fmtm -h localhost ### Option 2 -Access a PostgreSQL shell inside the fmtm_db container: +Access a PostgreSQL shell inside the fmtm-db container: ```bash -docker exec -it fmtm_db psql -U fmtm fmtm +GIT_BRANCH=development + +docker exec -it fmtm-db-${GIT_BRANCH} psql -U fmtm fmtm ``` And then connect to the database using this command: diff --git a/docs/dev/Production.md b/docs/dev/Production.md index 82e454e663..5dbefe9a44 100644 --- a/docs/dev/Production.md +++ b/docs/dev/Production.md @@ -155,8 +155,19 @@ This will map port 5432 on the remote machine to port 5430 on your local machine ## Manual Database Backups ```bash +GIT_BRANCH=development backup_filename="fmtm-db-backup-$(date +'%Y-%m-%d').sql.gz" echo $backup_filename -docker exec -i -e PGPASSWORD=PASSWORD_HERE fmtm_db pg_dump --verbose --format c -U fmtm fmtm | gzip -9 > "$backup_filename" +docker exec -i -e PGPASSWORD=PASSWORD_HERE fmtm-db-${GIT_BRANCH} pg_dump --verbose --format c -U fmtm fmtm | gzip -9 > "$backup_filename" +``` + +## Manual Database Restores + +```bash +# On a different machine (else change the container name) +GIT_BRANCH=development +backup_filename=fmtm-db-backup-XXXX-XX-XX-sql.gz + +cat "$backup_filename" | gunzip | docker exec -i -e PGPASSWORD=NEW_PASSWORD_HERE fmtm-db-${GIT_BRANCH} pg_restore --verbose -U fmtm -d fmtm ```