From eadb2ffe85c43cf6fc741c9823cd28eedb4a844c Mon Sep 17 00:00:00 2001 From: Chia Date: Wed, 5 Aug 2026 22:01:29 +1200 Subject: feat: harden prepaid billing and commercial operations --- scripts/backup-postgres.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 scripts/backup-postgres.sh (limited to 'scripts/backup-postgres.sh') diff --git a/scripts/backup-postgres.sh b/scripts/backup-postgres.sh new file mode 100755 index 0000000..f6444c9 --- /dev/null +++ b/scripts/backup-postgres.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +: "${AIGW_DATABASE_URL:?AIGW_DATABASE_URL is required}" +backup_dir="${AIGW_BACKUP_DIR:-./backups}" +retention_days="${AIGW_BACKUP_RETENTION_DAYS:-30}" +mkdir -p -- "$backup_dir" +chmod 700 "$backup_dir" +timestamp="$(date -u +%Y%m%dT%H%M%SZ)" +target="$backup_dir/aigw-$timestamp.dump" +pg_dump --dbname="$AIGW_DATABASE_URL" --format=custom --compress=9 --file="$target" +sha256sum "$target" >"$target.sha256" +find "$backup_dir" -maxdepth 1 -type f -name 'aigw-*.dump*' -mtime "+$retention_days" -delete +printf 'backup=%s\nchecksum=%s.sha256\n' "$target" "$target" -- cgit v1.2.3