Compare commits

..

7 Commits

Author SHA1 Message Date
f
09b1997b46 Merge branch 'main' into backups 2025-05-05 10:53:46 -03:00
f
a38f60ddfe Merge branch 'main' into backups 2025-04-30 10:17:36 -03:00
f
883ccf5950 Merge branch 'main' into backups 2025-04-14 10:22:07 -03:00
f
500bd060af fix: use volume name 2025-04-14 10:15:41 -03:00
f
ff2d1543a4 Merge branch 'main' into backups 2025-04-14 10:15:12 -03:00
f
955c3b2497 fix: abra.sh 2025-01-02 16:57:28 -03:00
f
c52e9c6744 feat: enable backup-bot-two 2025-01-02 16:48:09 -03:00
5 changed files with 54 additions and 3 deletions

View File

@ -9,3 +9,4 @@ LETS_ENCRYPT_ENV=production
SECRET_DB_PASSWORD_VERSION=v1
SECRET_NC_DB_URL_VERSION=v1
ENABLE_BACKUPS=true

View File

@ -8,7 +8,7 @@
* **Status**: 0
* **Image**: [`nocodb`](https://hub.docker.com/r/nocodb), 4, upstream
* **Healthcheck**: No
* **Backups**: No
* **Backups**: Yes
* **Email**: No
* **Tests**: No
* **SSO**: No

1
abra.sh Normal file
View File

@ -0,0 +1 @@
export PG_BACKUP_VERSION=v1

View File

@ -3,7 +3,7 @@ version: "3.8"
services:
app:
image: nocodb/nocodb:0.263.6
image: nocodb/nocodb:0.263.1
secrets:
- nc_db_url
networks:
@ -28,7 +28,8 @@ services:
#- "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}-redirect"
#- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLForceHost=true"
#- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}"
- "coop-cloud.${STACK_NAME}.version=1.1.5+0.263.6"
- "backupbot.backup=${ENABLE_BACKUPS:-true}"
- "coop-cloud.${STACK_NAME}.version=1.1.1+0.263.0"
db:
image: postgres:13.2-alpine
@ -47,6 +48,16 @@ services:
interval: 10s
timeout: 2s
retries: 10
deploy:
labels:
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'
configs:
- source: pg_backup
target: /pg_backup.sh
mode: 0555
volumes:
data:
@ -65,3 +76,7 @@ secrets:
nc_db_url:
external: true
name: ${STACK_NAME}_nc_db_url_${SECRET_NC_DB_URL_VERSION}
configs:
pg_backup:
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
file: pg_backup.sh

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 /run/secrets/db_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
}
$@