#!/usr/bin/env bash # Daily backup of smb-db (the CRM Postgres = source of truth). Keeps 14 days. # Installed on the homelab at /home/mivanchenko/backups/bin/ and run via cron. set -euo pipefail DEST=/home/mivanchenko/backups/smb-crm mkdir -p "$DEST" TS=$(date +%Y%m%d-%H%M%S) FILE="$DEST/smbcrm-$TS.sql.gz" # pg_dump runs inside the container; gzip on the host. docker exec smb-db pg_dump -U smbcrm -d smbcrm | gzip > "$FILE" # keep the 14 most recent dumps, delete older ls -1t "$DEST"/smbcrm-*.sql.gz 2>/dev/null | tail -n +15 | xargs -r rm -f echo "$(date -Is) backup ok: $FILE ($(du -h "$FILE" | cut -f1))"