feat: backup-db container hinzufügen

This commit is contained in:
deployn 2025-04-24 23:21:04 +02:00
parent db473c4282
commit 2ef2c47bae

View File

@ -26,7 +26,9 @@ services:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
depends_on: depends_on:
- db - db
db: db:
container_name: gitea-db
image: postgres:17 image: postgres:17
restart: unless-stopped restart: unless-stopped
environment: environment:
@ -37,3 +39,38 @@ services:
- gitea - gitea
volumes: volumes:
- ./postgres:/var/lib/postgresql/data - ./postgres:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "gitea", "-d", "gitea"]
interval: 10s
timeout: 5s
retries: 5
postgres-backup:
container_name: gitea-db-backup
networks:
- gitea
image: postgres:17
environment:
PGHOST: db
PGDATABASE: gitea
PGUSER: gitea
PGPASSWORD: giteaasdf
BACKUP_NUM_KEEP: 7
BACKUP_FREQUENCY: 1d
entrypoint: |
bash -c 'bash -s <<EOF
trap "break;exit" SIGHUP SIGINT SIGTERM
sleep 2m
while /bin/true; do
pg_dump -h $$PGHOST -U $$PGUSER -d $$PGDATABASE -Fc > /dump/pg_backup_\`date +%d-%m-%Y"_"%H_%M_%S\`.dump
(ls -t /dump/pg_backup_*.dump|head -n $$BACKUP_NUM_KEEP;ls /dump/pg_backup_*.dump)|sort|uniq -u|xargs rm -f -- 2>/dev/null || true
sleep $$BACKUP_FREQUENCY
done
EOF'
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped
volumes:
- /etc/localtime:/etc/localtime:ro
- ./backup-db:/dump