Files
Assistant/deploy/install-postgres-backup-cron.sh
m e9594306e5
CI / test (push) Successful in 10s
ops: add verified PostgreSQL backups
2026-08-16 17:53:40 +03:00

31 lines
714 B
Bash
Executable File

#!/bin/sh
set -eu
schedule_file="${1:-/home/m/assistant-ops/assistant-postgres-backup.crontab}"
marker="/home/m/assistant-ops/backup-postgres.sh"
current="$(mktemp)"
updated="$(mktemp)"
cleanup() {
rm -f -- "$current" "$updated"
}
trap cleanup EXIT HUP INT TERM
if [ ! -f "$schedule_file" ]; then
echo "Cron schedule file not found: $schedule_file" >&2
exit 1
fi
crontab -l >"$current" 2>/dev/null || true
grep -vF "$marker" "$current" >"$updated" || true
cat "$schedule_file" >>"$updated"
crontab "$updated"
matches="$(crontab -l | grep -Fc "$marker")"
if [ "$matches" -ne 1 ]; then
echo "Expected one backup cron entry, found $matches" >&2
exit 1
fi
echo "PostgreSQL backup cron entry installed"