2 Commits

Author SHA1 Message Date
820523773d update postgres from 12 to 13
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2024-10-24 16:43:49 +02:00
01689fbedb update backupbot label 2024-10-24 15:56:31 +02:00
6 changed files with 54 additions and 5 deletions

View File

@ -17,6 +17,8 @@ steps:
DOMAIN: {{ .Name }}.swarm-test.autonomic.zone
STACK_NAME: {{ .Name }}
LETS_ENCRYPT_ENV: production
PG_BACKUP_VERSION: v1
PRETIX_CONFIG_VERSION: v1
trigger:
branch:
- main

View File

@ -2,6 +2,8 @@ TYPE=pretix
DOMAIN=pretix.example.com
ENABLE_BACKUPS=true
## Domain aliases
#EXTRA_DOMAINS=', `www.pretix.example.com`'
@ -16,4 +18,4 @@ SMTP_HOST=127.0.0.71
SMTP_USER=pretix
SMTP_PORT=1025
SMTP_TLS=on
SMTP_SSL=off
SMTP_SSL=off

View File

@ -1 +1,2 @@
export PRETIX_CONFIG_VERSION=v1
export PG_BACKUP_VERSION=v1

View File

@ -34,7 +34,7 @@ services:
# start_period: 1m
db:
image: postgres:12
image: postgres:13
volumes:
- "postgres:/var/lib/postgresql/data"
networks:
@ -52,9 +52,15 @@ services:
retries: 5
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: "PGPASSWORD=$$(cat $${POSTGRES_PASSWORD_FILE}) pg_dump -U $${POSTGRES_USER} $${POSTGRES_DB} > /var/lib/postgresql/data/backup.sql"
backupbot.backup.post-hook: "rm -rf /var/lib/postgresql/data/backup.sql"
backupbot.backup: "${ENABLE_BACKUPS:-true}"
backupbot.backup.pre-hook: "/pg_backup.sh backup"
backupbot.backup.volumes.postgres.path: "backup.sql"
backupbot.restore.post-hook: '/pg_backup.sh restore'
backupbot.backup.volumes.redis: "false"
configs:
- source: pg_backup
target: /pg_backup.sh
mode: 0555
redis:
image: redis:7.0.10-alpine
@ -78,6 +84,9 @@ configs:
name: ${STACK_NAME}_pretix_config_${PRETIX_CONFIG_VERSION}
file: pretix.cfg.tmpl
template_driver: golang
pg_backup:
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
file: pg_backup.sh
networks:
proxy:

34
pg_backup.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
set -e
BACKUP_FILE='/var/lib/postgresql/data/backup.sql'
function backup {
export PGPASSWORD=$(cat $POSTGRES_PASSWORD_FILE)
pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > $BACKUP_FILE
}
function restore {
cd /var/lib/postgresql/data/
restore_config(){
# Restore allowed connections
cat pg_hba.conf.bak > pg_hba.conf
su postgres -c 'pg_ctl reload'
}
# Don't allow any other connections than local
cp pg_hba.conf pg_hba.conf.bak
echo "local all all trust" > pg_hba.conf
su postgres -c 'pg_ctl reload'
trap restore_config EXIT INT TERM
# Recreate Database
psql -U ${POSTGRES_USER} -d postgres -c "DROP DATABASE ${POSTGRES_DB} WITH (FORCE);"
createdb -U ${POSTGRES_USER} ${POSTGRES_DB}
psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} -1 -f $BACKUP_FILE
trap - EXIT INT TERM
restore_config
}
$@

1
release/next Normal file
View File

@ -0,0 +1 @@
Postgres update: please do a backup before the upgrade, remove the postgres volume and restore it after the upgrade