generated from coop-cloud/example
This commit is contained in:
parent
3022729f66
commit
5f3dcb4256
@ -2,6 +2,7 @@ TYPE=onlyoffice
|
|||||||
TIMEOUT=300
|
TIMEOUT=300
|
||||||
ENABLE_AUTO_UPDATE=true
|
ENABLE_AUTO_UPDATE=true
|
||||||
LETS_ENCRYPT_ENV=production
|
LETS_ENCRYPT_ENV=production
|
||||||
|
ENABLE_BACKUPS=true
|
||||||
DOMAIN=onlyoffice.example.com
|
DOMAIN=onlyoffice.example.com
|
||||||
|
|
||||||
SECRET_DB_PASSWORD_VERSION=v1
|
SECRET_DB_PASSWORD_VERSION=v1
|
||||||
|
1
abra.sh
1
abra.sh
@ -1,4 +1,5 @@
|
|||||||
export ENTRYPOINT_VERSION=v1
|
export ENTRYPOINT_VERSION=v1
|
||||||
|
export PG_BACKUP_VERSION=v1
|
||||||
|
|
||||||
prepare_shutdown () {
|
prepare_shutdown () {
|
||||||
documentserver-prepare4shutdown.sh
|
documentserver-prepare4shutdown.sh
|
||||||
|
14
compose.yml
14
compose.yml
@ -64,9 +64,10 @@ services:
|
|||||||
image: postgres:9.5
|
image: postgres:9.5
|
||||||
deploy:
|
deploy:
|
||||||
labels:
|
labels:
|
||||||
backupbot.backup: "true"
|
backupbot.backup: "${ENABLE_BACKUPS:-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.pre-hook: "/pg_backup.sh backup"
|
||||||
backupbot.backup.post-hook: "rm -rf /var/lib/postgresql/data/backup.sql"
|
backupbot.backup.volumes.db.path: "backup.sql"
|
||||||
|
backupbot.restore.post-hook: '/pg_backup.sh restore'
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: onlyoffice
|
POSTGRES_DB: onlyoffice
|
||||||
POSTGRES_USER: onlyoffice
|
POSTGRES_USER: onlyoffice
|
||||||
@ -83,6 +84,10 @@ services:
|
|||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 10
|
retries: 10
|
||||||
start_period: 1m
|
start_period: 1m
|
||||||
|
configs:
|
||||||
|
- source: pg_backup
|
||||||
|
target: /pg_backup.sh
|
||||||
|
mode: 0555
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db:
|
db:
|
||||||
@ -104,3 +109,6 @@ configs:
|
|||||||
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
|
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
|
||||||
file: entrypoint.sh.tmpl
|
file: entrypoint.sh.tmpl
|
||||||
template_driver: golang
|
template_driver: golang
|
||||||
|
pg_backup:
|
||||||
|
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||||
|
file: pg_backup.sh
|
||||||
|
27
pg_backup.sh
Normal file
27
pg_backup.sh
Normal 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'
|
||||||
|
}
|
||||||
|
|
||||||
|
$@
|
Loading…
x
Reference in New Issue
Block a user