update backupbot labels
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Moritz 2024-10-22 20:08:54 +02:00
parent 3022729f66
commit 5f3dcb4256
4 changed files with 40 additions and 3 deletions

View File

@ -2,6 +2,7 @@ TYPE=onlyoffice
TIMEOUT=300
ENABLE_AUTO_UPDATE=true
LETS_ENCRYPT_ENV=production
ENABLE_BACKUPS=true
DOMAIN=onlyoffice.example.com
SECRET_DB_PASSWORD_VERSION=v1

View File

@ -1,4 +1,5 @@
export ENTRYPOINT_VERSION=v1
export PG_BACKUP_VERSION=v1
prepare_shutdown () {
documentserver-prepare4shutdown.sh

View File

@ -64,9 +64,10 @@ services:
image: postgres:9.5
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: "PGPASSWORD=$$(cat /run/secrets/db_password) 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.db.path: "backup.sql"
backupbot.restore.post-hook: '/pg_backup.sh restore'
environment:
POSTGRES_DB: onlyoffice
POSTGRES_USER: onlyoffice
@ -83,6 +84,10 @@ services:
timeout: 10s
retries: 10
start_period: 1m
configs:
- source: pg_backup
target: /pg_backup.sh
mode: 0555
volumes:
db:
@ -104,3 +109,6 @@ configs:
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
file: entrypoint.sh.tmpl
template_driver: golang
pg_backup:
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
file: pg_backup.sh

27
pg_backup.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/bash
set -e
BACKUP_FILE='/var/lib/postgresql/data/backup.sql'
function backup {
export PGPASSWORD=$(cat /run/secrets/db_password)
pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > $BACKUP_FILE
}
function restore {
cd /var/lib/postgresql/data/
# 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'
# 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
# Restore allowed connections
cat pg_hba.conf.bak > pg_hba.conf
su postgres -c 'pg_ctl reload'
}
$@