mirror of
https://github.com/Such-Software/xmrcheckout.git
synced 2026-10-17 05:51:34 +02:00
Add optional Postgres backup service
This commit is contained in:
@@ -4,6 +4,9 @@ POSTGRES_PASSWORD=xmrcheckout
|
|||||||
POSTGRES_DB=xmrcheckout
|
POSTGRES_DB=xmrcheckout
|
||||||
DATABASE_URL=postgresql://xmrcheckout:xmrcheckout@db:5432/xmrcheckout
|
DATABASE_URL=postgresql://xmrcheckout:xmrcheckout@db:5432/xmrcheckout
|
||||||
|
|
||||||
|
# Optional: Postgres backups (used by the `db-backup` Compose profile)
|
||||||
|
BACKUP_RETENTION_DAYS=7
|
||||||
|
|
||||||
# API authentication
|
# API authentication
|
||||||
API_KEYS=dev-key-1
|
API_KEYS=dev-key-1
|
||||||
API_KEY_ENCRYPTION_KEY=replace-with-fernet-key
|
API_KEY_ENCRYPTION_KEY=replace-with-fernet-key
|
||||||
|
|||||||
@@ -8,3 +8,5 @@ ui/node_modules/
|
|||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
||||||
nginx/certs/
|
nginx/certs/
|
||||||
|
|
||||||
|
backups/
|
||||||
|
|||||||
@@ -105,6 +105,19 @@ If you’re running the bundled `monerod` service:
|
|||||||
docker compose --profile local-daemon up --build -d
|
docker compose --profile local-daemon up --build -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Optional: Postgres backups (disabled by default)
|
||||||
|
|
||||||
|
This repository includes an optional `db-backup` service that runs `pg_dump` hourly and writes backups to `./backups/postgres` on the host.
|
||||||
|
|
||||||
|
Enable it by starting Compose with the `db-backup` profile:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker compose --profile db-backup up --build -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Retention defaults to 7 days. To override:
|
||||||
|
- Set `BACKUP_RETENTION_DAYS` in `.env`
|
||||||
|
|
||||||
### Optional: donations (disabled by default)
|
### Optional: donations (disabled by default)
|
||||||
|
|
||||||
Donation endpoints and UI are off by default for self-hosted deployments.
|
Donation endpoints and UI are off by default for self-hosted deployments.
|
||||||
|
|||||||
@@ -216,6 +216,22 @@ services:
|
|||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 10
|
retries: 10
|
||||||
|
db-backup:
|
||||||
|
build:
|
||||||
|
context: ./docker/pg_backup
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: db
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
|
||||||
|
volumes:
|
||||||
|
- ./backups/postgres:/backups
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
restart: on-failure
|
||||||
|
profiles: ["db-backup"]
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
monerod_data:
|
monerod_data:
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM postgres:16-alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache bash
|
||||||
|
|
||||||
|
COPY backup.sh /usr/local/bin/backup.sh
|
||||||
|
COPY pg_backup.cron /etc/cron.d/pg_backup
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/backup.sh \
|
||||||
|
&& chmod 0644 /etc/cron.d/pg_backup \
|
||||||
|
&& crontab /etc/cron.d/pg_backup
|
||||||
|
|
||||||
|
CMD ["crond", "-f", "-l", "8"]
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
: "${POSTGRES_HOST:?}"
|
||||||
|
: "${POSTGRES_USER:?}"
|
||||||
|
: "${POSTGRES_PASSWORD:?}"
|
||||||
|
: "${POSTGRES_DB:?}"
|
||||||
|
|
||||||
|
backup_retention_days="${BACKUP_RETENTION_DAYS:-7}"
|
||||||
|
|
||||||
|
export PGPASSWORD="$POSTGRES_PASSWORD"
|
||||||
|
|
||||||
|
backup_dir="/backups"
|
||||||
|
timestamp="$(date +%Y%m%d_%H%M%S)"
|
||||||
|
backup_path="${backup_dir}/${POSTGRES_DB}_${timestamp}.dump"
|
||||||
|
|
||||||
|
mkdir -p "$backup_dir"
|
||||||
|
|
||||||
|
pg_dump -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -F c -f "$backup_path"
|
||||||
|
|
||||||
|
find "$backup_dir" -type f -name "*.dump" -mtime "+${backup_retention_days}" -delete
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
0 * * * * /usr/local/bin/backup.sh >> /var/log/pg_backup.log 2>&1
|
||||||
Reference in New Issue
Block a user