tracksolid_timescale_grafan.../backup/entrypoint.sh
David Kiania 108c1be057
Some checks failed
Static Analysis / static (push) Waiting to run
Tests / test (push) Waiting to run
Static Analysis / static (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
feat: nightly pg_dump sidecar uploads to rustfs fleet-db bucket
Adds a `db_backup` sidecar that dumps tracksolid_db every night at
02:30 UTC (configurable via BACKUP_HOUR/BACKUP_MINUTE), gzips the
output, and uploads to s3://fleet-db/daily/<dbname>_<ts>.sql.gz on
the rustfs S3-compatible instance (s3.rahamafresh.com). Prunes
objects older than BACKUP_KEEP_DAYS (default 30).

Required .env additions (Coolify UI):
  RUSTFS_ENDPOINT=https://s3.rahamafresh.com
  RUSTFS_ACCESS_KEY=...
  RUSTFS_SECRET_KEY=...
  RUSTFS_BUCKET=fleet-db

Mitigates data loss when Coolify service recreation wipes the
service-ID-scoped timescale-data volume.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 12:53:23 +03:00

26 lines
959 B
Bash
Executable file

#!/bin/sh
# Loops forever: sleeps until the next BACKUP_HOUR:BACKUP_MINUTE UTC, then runs backup_db.sh.
# Defaults: 02:30 UTC nightly.
set -eu
HOUR="${BACKUP_HOUR:-2}"
MINUTE="${BACKUP_MINUTE:-30}"
if [ "${BACKUP_RUN_ON_START:-0}" = "1" ]; then
echo "[$(date -u +%FT%TZ)] BACKUP_RUN_ON_START=1 — running backup immediately"
/app/backup_db.sh || echo "[$(date -u +%FT%TZ)] initial backup failed (continuing)"
fi
while true; do
NOW_EPOCH=$(date -u +%s)
TARGET=$(date -u -d "today ${HOUR}:${MINUTE}:00" +%s 2>/dev/null \
|| date -u -j -f "%H:%M:%S" "${HOUR}:${MINUTE}:00" +%s)
if [ "$TARGET" -le "$NOW_EPOCH" ]; then
TARGET=$((TARGET + 86400))
fi
SLEEP=$((TARGET - NOW_EPOCH))
echo "[$(date -u +%FT%TZ)] next backup in ${SLEEP}s (at $(date -u -d "@${TARGET}" +%FT%TZ 2>/dev/null || date -u -r "${TARGET}" +%FT%TZ))"
sleep "$SLEEP"
/app/backup_db.sh || echo "[$(date -u +%FT%TZ)] backup failed (will retry tomorrow)"
done