Files
postgres/docker-compose.yml
T
magnusandClaude Opus 4.6 448e31c01b Add PostgreSQL with automated hot backup setup
Weekly full backups via pg_basebackup and continuous WAL archiving
for point-in-time recovery, running as Docker Compose services.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 15:01:39 +01:00

51 lines
1.3 KiB
YAML

services:
postgres-db:
image: postgres:18
container_name: postgres-db
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "${PGPORT}:5432"
volumes:
- postgres_data:/var/lib/postgresql
- /data/backup/postgres/wal:/backup/wal
- ./init-replication-hba.sh:/docker-entrypoint-initdb.d/init-replication-hba.sh:ro
command:
- postgres
- -c
- wal_level=replica
- -c
- archive_mode=on
- -c
- archive_command=test ! -f /backup/wal/%f && cp %p /backup/wal/%f
postgres-backup:
image: postgres:18
container_name: postgres-backup
restart: unless-stopped
depends_on:
- postgres-db
environment:
POSTGRES_USER: ${POSTGRES_USER}
PGPASSWORD: ${POSTGRES_PASSWORD}
volumes:
- /data/backup/postgres:/backup
entrypoint: ["/bin/bash", "-c"]
command:
- |
mkdir -p /backup/wal /backup/full
while true; do
STAMP=$$(date +%Y-%m-%d_%H-%M-%S)
echo "Starting full backup: full_$$STAMP"
pg_basebackup -h postgres-db -U "$$POSTGRES_USER" -D "/backup/full/full_$$STAMP" -Fp -Xs -P
echo "Full backup complete: full_$$STAMP"
sleep 604800
done
volumes:
postgres_data: