Add backup-bot-two labels
This commit is contained in:
2
TODO.md
2
TODO.md
@ -7,7 +7,7 @@
|
|||||||
- [x] External OIDC server (+ move options to `.env.sample`)
|
- [x] External OIDC server (+ move options to `.env.sample`)
|
||||||
- [x] Customisable Django `DJANGO_SECRET_KEY` and `DJANGO_SUPERUSER_PASSWORD`
|
- [x] Customisable Django `DJANGO_SECRET_KEY` and `DJANGO_SUPERUSER_PASSWORD`
|
||||||
- [ ] Versioned recipe release
|
- [ ] Versioned recipe release
|
||||||
- [ ] `backup-bot-two` labels
|
- [x] `backup-bot-two` labels
|
||||||
- [ ] Fix Django admin static files
|
- [ ] Fix Django admin static files
|
||||||
|
|
||||||
## Should
|
## Should
|
||||||
|
1
abra.sh
1
abra.sh
@ -1,6 +1,7 @@
|
|||||||
# Set any config versions here
|
# Set any config versions here
|
||||||
# Docs: https://docs.coopcloud.tech/maintainers/handbook/#manage-configs
|
# Docs: https://docs.coopcloud.tech/maintainers/handbook/#manage-configs
|
||||||
export NGINX_CONF_VERSION=v2
|
export NGINX_CONF_VERSION=v2
|
||||||
|
export PG_BACKUP_VERSION=v3
|
||||||
|
|
||||||
# environment() {
|
# environment() {
|
||||||
# # TODO: Add file_env here
|
# # TODO: Add file_env here
|
||||||
|
16
compose.yml
16
compose.yml
@ -141,6 +141,16 @@ services:
|
|||||||
PGDATA: var/lib/postgresql/data/pgdata
|
PGDATA: var/lib/postgresql/data/pgdata
|
||||||
volumes:
|
volumes:
|
||||||
- postgres:/var/lib/postgresql/data/pgdata
|
- postgres:/var/lib/postgresql/data/pgdata
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
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'
|
||||||
|
configs:
|
||||||
|
- source: pg_backup
|
||||||
|
target: /pg_backup.sh
|
||||||
|
mode: 0555
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:5
|
image: redis:5
|
||||||
@ -179,6 +189,9 @@ services:
|
|||||||
command: minio server /data
|
command: minio server /data
|
||||||
volumes:
|
volumes:
|
||||||
- minio:/data
|
- minio:/data
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
backupbot.backup: "${ENABLE_BACKUPS:-true}"
|
||||||
|
|
||||||
web:
|
web:
|
||||||
image: nginx:1.27
|
image: nginx:1.27
|
||||||
@ -211,3 +224,6 @@ configs:
|
|||||||
nginx_conf:
|
nginx_conf:
|
||||||
name: ${STACK_NAME}_nginx_conf_${NGINX_CONF_VERSION}
|
name: ${STACK_NAME}_nginx_conf_${NGINX_CONF_VERSION}
|
||||||
file: nginx.conf
|
file: nginx.conf
|
||||||
|
pg_backup:
|
||||||
|
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||||
|
file: pg_backup.sh
|
||||||
|
35
pg_backup.sh
Normal file
35
pg_backup.sh
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BACKUP_FILE='/var/lib/postgresql/data/pgdata/backup.sql'
|
||||||
|
|
||||||
|
function backup {
|
||||||
|
# export PGPASSWORD=$(cat $POSTGRES_PASSWORD_FILE)
|
||||||
|
export PGPASSWORD="$POSTGRES_PASSWORD"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
$@
|
Reference in New Issue
Block a user