From 1240106d4d986a4c950c194f59e5b828fd45802e Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Tue, 22 Nov 2022 18:41:12 -0800 Subject: [PATCH] Add rudimentary database backup, and Postgres upgrade misery --- README.md | 27 ++++++++++++++++++++++++--- compose.yml | 6 ++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c4f8d6e..bb0495b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ A platform for community discussion [`abra`]: https://git.autonomic.zone/autonomic-cooperative/abra [`coop-cloud/traefik`]: https://git.autonomic.zone/coop-cloud/traefik -## To add a new Admin user +## To add a new admin user 1. Login to the instance `abra app run APPNAME app sh` 2. `cd /opt/bitnami/discourse` @@ -39,9 +39,30 @@ A platform for community discussion 1. Login to instance `abra app run APPNAME app sh` 2. `cd /bitnami/discourse/plugins/` -3. `git clone plugingit` for example `https://github.com/discourse/discourse-openid-connect.git` -4. `abra app restart APPNAME app` +3. `git clone plugin.git` for example `https://github.com/discourse/discourse-openid-connect.git` +4. `abra app restart YOURAPPDOMAIN app` ## Setup Notes Until issue #1 is fixed, the default user is `user` and the default password is `bitnami123` + +## Postgres major version upgrades + +Welcome to hell. + +1. `abra app run YOURAPPDOMAIN db pg_dumpall -U discourse | gzip > YOURAPPDOMAIN_db_DATE.sql.gz` +2. `abra app volume ls YOURAPPDOMAIN`, find the name of the Postgres data volume +3. `scp` the backup to your VPS +4. `abra app undeploy YOURAPPDOMAIN` +5. `abra app volume rm YOURAPPDOMAIN`, choose the Postgres data volume +6. `abra app deploy YOURAPPDOMAIN`, then `abra app undeploy YOURAPPDOMAIN` +7. `ssh` to the VPS, run (replacing `13-alpine` with the new Postgres version) + `docker run -v YOURDATAVOLUME:/var/lib/postgresql/data -e POSTGRES_HOST_AUTH_METHOD=trust -it postgres:13-alpine` +8. In another SSH session on the server, run `docker ps` to find the ID of the + new Postgres container, then `docker exec -it CONTAINERID bash` +9. In the shell you just launched, run `dropdb -U discourse discourse`, then + `createdb -U discourse discourse`, then Ctrl+D or run `exit` +10. In the second SSH session, run `zcat YOURAPPDOMAIN_db_DATE.sql.gz | docker exec -it CONTAINERID psql -U discourse` +11. Exit the second SSH session +12. Back in the first SSH session, Ctrl+C to shut down the database +13. `abra app deploy YOURAPPDOMAIN` diff --git a/compose.yml b/compose.yml index 87190b8..2d3336f 100644 --- a/compose.yml +++ b/compose.yml @@ -63,6 +63,12 @@ services: - POSTGRES_USER=discourse - POSTGRES_DB=discourse - POSTGRES_PASSWORD_FILE=/run/secrets/db_password + deploy: + labels: + backupbot.backup: "true" + backupbot.backup.pre-hook: "bash -c 'PGPASSWORD=$$(cat $${POSTGRES_PASSWORD_FILE}) pg_dump -U $${POSTGRES_USER} $${POSTGRES_DB} > /tmp/backup.sql'" + backupbot.backup.post-hook: "rm -rf /tmp/backup.sql" + backupbot.backup.path: "/tmp/backup.sql" redis: image: redis:7.0-alpine