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:
@@ -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