diff --git a/deploy/wizwar-backup.sh b/deploy/wizwar-backup.sh index 2f15b8c..d9abc41 100755 --- a/deploy/wizwar-backup.sh +++ b/deploy/wizwar-backup.sh @@ -11,7 +11,12 @@ STAMP=$(date +%Y-%m-%d) # Sentry Crons check-in: /root/.wizwar-sentry-cron holds the check-in URL # (auto-creates the monitor on first ping). Absent file = no check-ins. CRON_URL=$(cat /root/.wizwar-sentry-cron 2>/dev/null || true) -checkin() { [ -n "$CRON_URL" ] && curl -sf -o /dev/null "$CRON_URL?status=$1" || true; } +# One check-in, when the run ends, carrying its duration: a start and a +# finish sent seconds apart can reach Sentry in either order, and a start +# that lands second is never closed. A run that never ends sends nothing, +# and Sentry marks the night missed. +START=$SECONDS +checkin() { [ -n "$CRON_URL" ] && curl -sf -o /dev/null "$CRON_URL?status=$1&duration=$((SECONDS - START))" || true; } if grep -q CHANGE_ME /root/.config/rclone/rclone.conf; then echo "$(date -Is) skipped: Spaces credentials not configured yet" >> "$LOG" @@ -20,7 +25,6 @@ fi { echo "=== $(date -Is) backup start" - checkin in_progress if rclone sync "$SRC" "spaces:$BUCKET/wizwar/current" 2>&1 && rclone copy "$SRC" "spaces:$BUCKET/wizwar/snapshots/$STAMP" 2>&1; then checkin ok diff --git a/deploy/wizwar-rollup.sh b/deploy/wizwar-rollup.sh index b06bcfc..737a53c 100755 --- a/deploy/wizwar-rollup.sh +++ b/deploy/wizwar-rollup.sh @@ -21,13 +21,17 @@ CRON_URL=$(cat /root/.wizwar-sentry-cron-rollup 2>/dev/null || true) # The check-in carries the schedule: Sentry only keeps a monitor it has # been told the shape of, and a bare ping to an unknown slug is accepted # and dropped without a word. +# One check-in, when the run ends, carrying its duration: a start and a +# finish sent seconds apart can reach Sentry in either order, and a start +# that lands second is never closed. A run that never ends sends nothing, +# and Sentry marks the night missed. +START=$SECONDS checkin() { [ -n "$CRON_URL" ] && curl -sf -o /dev/null -X POST -H "Content-Type: application/json" \ - -d "{\"status\":\"$1\",\"monitor_config\":{\"schedule\":{\"type\":\"crontab\",\"value\":\"$SCHEDULE\"},\"checkin_margin\":30,\"max_runtime\":10,\"timezone\":\"UTC\"}}" \ + -d "{\"status\":\"$1\",\"duration\":$((SECONDS - START)),\"monitor_config\":{\"schedule\":{\"type\":\"crontab\",\"value\":\"$SCHEDULE\"},\"checkin_margin\":30,\"max_runtime\":10,\"timezone\":\"UTC\"}}" \ "$CRON_URL" || true } -checkin in_progress if python3 - "$DAY" "$OUT" <<'PY' >> "$LOG" 2>&1 import json, sys, os, glob, gzip, datetime, collections, subprocess, re day, out = sys.argv[1], sys.argv[2]