SPB Git forge

spb/spinza

Public
8commits 1branches 0releases
1.6 MBsize
maindefault branch
16 days agolast push
TypeScript 97.6% SQL 1.4% JavaScript 0.5%
1.2 KB · 28 lines shellscript
Raw Blame History
1#!/bin/bash2# Daily PostgreSQL backup for Spinza (wallet ledger is critical).3# Installed on the node by deploy/install-backup.sh as a launchd agent (03:40 daily).4set -euo pipefail5export PATH="/opt/homebrew/bin:/opt/homebrew/opt/postgresql@17/bin:$PATH"6DB="${SPINZA_DB:-spinza}"7DEST="${SPINZA_BACKUP_DIR:-$HOME/backups/spinza}"8KEEP_DAYS="${SPINZA_BACKUP_KEEP_DAYS:-21}"9mkdir -p "$DEST"10STAMP=$(date +%Y%m%d-%H%M%S)11FILE="$DEST/spinza-$STAMP.dump"12pg_dump --format=custom --compress=6 --file="$FILE" "$DB"13# Verify the archive lists cleanly (restore test light).14pg_restore --list "$FILE" >/dev/null15SIZE=$(du -h "$FILE" | cut -f1)16echo "$(date -Iseconds) backup ok $FILE ($SIZE)" >>"$DEST/backup.log"17# Rotate.18find "$DEST" -name 'spinza-*.dump' -mtime +"$KEEP_DAYS" -delete19# Monthly full restore test into a scratch database (first day of month).20if [ "$(date +%d)" = "01" ]; then21  dropdb --if-exists spinza_restore_test22  createdb spinza_restore_test23  pg_restore --dbname=spinza_restore_test --no-owner "$FILE"24  ROWS=$(psql -tAqc "select count(*) from credit_transactions" spinza_restore_test)25  echo "$(date -Iseconds) restore test ok ($ROWS ledger rows)" >>"$DEST/backup.log"26  dropdb spinza_restore_test27fi28