This commit is contained in:
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user