feat: backup-db container hinzufügen
This commit is contained in:
parent
db473c4282
commit
2ef2c47bae
@ -26,7 +26,9 @@ services:
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
db:
|
||||
container_name: gitea-db
|
||||
image: postgres:17
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
@ -37,3 +39,38 @@ services:
|
||||
- gitea
|
||||
volumes:
|
||||
- ./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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user