add backup handler scripts

This commit is contained in:
marlon 2025-05-22 00:48:23 -04:00
parent 726e3ab5c3
commit b8ea370933
3 changed files with 29 additions and 7 deletions

View File

@ -8,9 +8,14 @@ fi
if [ "$1" == "pre-restore" ]; then
# kill the running plugins that need to be overwritten
pkill plugins
pkill -f '.*plugins'
sleep 40
pkill -f '.*plugins'
sleep 40
pkill -f '.*plugins'
fi
if [ "$1" == "post-restore" ]; then
mmctl config reload --local
# kill mattermost so that the container restarts
pkill -f mattermost
fi

View File

@ -1,8 +1,12 @@
if [ "$1" == "pre-backup" ]; then
# Remove any existing db dump and then create a new one
rm -rf /var/lib/postgresql/data/postgres-backup
PGPASSWORD=$(cat ${POSTGRES_PASSWORD_FILE}) pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} --format=directory -f /var/lib/postgresql/data/postgres-backup
exit
fi
if [ "$1" == "post-backup" ]; then
rm -rf /var/lib/postgresql/data/postgres-backup
exit
fi

View File

@ -32,12 +32,15 @@ services:
- "coop-cloud.${STACK_NAME}.timeout=${TIMEOUT:-120}"
- "backupbot.backup=true"
- "backupbot.backup.path=/mattermost,/etc/ssl"
- "backupbot.restore.pre-hook=/restore.sh pre"
- "backupbot.restore.post-hook=/restore.sh post"
- "backupbot.restore.pre-hook=/backup.sh pre-restore"
- "backupbot.restore.post-hook=/backup.sh post-restore"
configs:
- source: abra_mattermost_entrypoint
target: /abra-mattermost-entrypoint.sh
mode: 0555
- source: backup-mattermost
target: /backup.sh
mode: 0777
secrets:
- postgres_password
entrypoint: /abra-mattermost-entrypoint.sh
@ -51,6 +54,10 @@ services:
- POSTGRES_USER=mattermost
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
- POSTGRES_DB=mattermost
configs:
- source: backup-postgres
target: /backup.sh
mode: 0777
secrets:
- postgres_password
networks:
@ -58,10 +65,10 @@ services:
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: "PGPASSWORD=$$(cat $${POSTGRES_PASSWORD_FILE}) pg_dump -U $${POSTGRES_USER} $${POSTGRES_DB} --format=directory -f /var/lib/postgresql/data/postgres-backup"
backupbot.backup.post-hook: "rm -rf /var/lib/postgresql/data/postgres-backup"
backupbot.backup.path: "/var/lib/postgresql/data/"
backupbot.restore.post-hook: "/backup-postgres.sh post"
backupbot.backup.pre-hook: "/backup.sh pre-backup"
backupbot.backup.post-hook: "/backup.sh post-backup"
backupbot.restore.post-hook: "/backup.sh post-restore"
secrets:
postgres_password:
@ -72,6 +79,12 @@ configs:
abra_mattermost_entrypoint:
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
file: ./entrypoint.sh
backup-mattermost:
name: backup-mattermost
file: ./backup-mattermost.sh
backup-postgres:
name: backup-postgres
file: ./backup-postgres.sh
networks: