Backup job monitoring: get an alert when a backup fails or doesn’t run

To monitor a backup job, make the backup script send an HTTP check-in to Alert51 after every run, with the result and the backup’s cron schedule. Alert51 alerts you when a backup reports a failure, and when no check-in arrives by the next scheduled time plus a grace period, which means the backup did not run at all.

Why backups need their own monitoring

A backup is only noticed when someone needs to restore it. A full disk, an expired database password or a crontab lost in a server migration can stop backups for weeks without a single error reaching anyone. Database backup monitoring closes both gaps: an alert when a backup fails, and an alert when a backup does not run.

1. Store an API token on the backup host

Create a token under API tokens in the dashboard (your email must be verified) and save it in a root-only file. Details: API token authentication.

/etc/alert51.env (mode 600)
export ALERT51_URL="https://api.alert51.com"
export ALERT51_TOKEN="a51_xxxxxxxx_your-secret"

2. Report the result from the backup script

The script runs pg_dump, turns its exit code into success or failure, sends the check-in with the duration, and exits with the backup’s own status, so cron and any other tooling still see a failed backup as failed. Swap pg_dump for mysqldump, restic or any other command.

/opt/scripts/backup.sh
#!/bin/sh
set -u
started=$(date +%s)
if pg_dump --format=custom --file=/var/backups/app.dump "$DATABASE_URL"; then
  status=success
else
  status=failure
fi
duration_ms=$(( ($(date +%s) - started) * 1000 ))

curl --fail-with-body --silent --show-error --max-time 10 \
  -H "Authorization: Bearer $ALERT51_TOKEN" \
  -H 'Content-Type: application/json' \
  -d "{\"project\":\"production\",\"job\":\"db-backup\",\"status\":\"$status\",\"cron\":\"0 3 * * *\",\"timezone\":\"UTC\",\"graceSeconds\":1800,\"durationMs\":$duration_ms}" \
  "$ALERT51_URL/v1/check-ins"

[ "$status" = success ]

3. Schedule it

The crontab entry loads the token and runs the script daily at 03:00. The cron value in the check-in, 0 3 * * *, must match it, and timezone must be the zone the cron daemon runs in.

crontab -e
0 3 * * * . /etc/alert51.env && /opt/scripts/backup.sh

4. Run it once and check the response

Run . /etc/alert51.env && /opt/scripts/backup.sh by hand. The first check-in creates the monitor production / db-backup. This is the response from our test run:

Response
{
  "monitorId": "45656f16-fe18-4fcf-9392-defd48043c1a",
  "project": "production",
  "job": "db-backup",
  "created": true,
  "checkIn": {
    "id": "17e5d9f9-e64a-48f6-95a2-1cecb3314085",
    "status": "success",
    "receivedAt": "2026-11-23T00:44:07.609Z",
    "slotAt": "2026-11-22T03:00:00.000Z",
    "outcome": "applied",
    "late": true
  },
  "schedule": {
    "cron": "0 3 * * *",
    "timezone": "UTC",
    "graceSeconds": 1800,
    "changed": false
  },
  "monitorStatus": "up",
  "nextRunAt": "2026-11-23T03:00:00.000Z",
  "deadlineAt": "2026-11-23T03:30:00.000Z",
  "incident": null
}

The backup is now monitored. deadlineAt is 03:30 UTC: the next 03:00 run plus 1,800 seconds of grace. late: true only reflects that the test ran outside the schedule.

Alert when a backup fails

When pg_dump exits non-zero, the script reports failure and Alert51 opens an incident immediately. The monitor turns down and every enabled channel is notified: email and Telegram on every plan, signed webhooks on Startup and above. To test it, run the script once with a wrong DATABASE_URL; the next successful backup resolves the incident.

Alert when a backup does not run

If the host is down, cron is stopped or the crontab entry disappears, nothing reports. At the deadline, 03:30 UTC in this example, Alert51 opens a missed incident. It stays one incident however many nights are missed, and the next successful backup resolves it. See schedules and timing for how deadlines are calculated.

Confirm it’s you

Security changes need a sign-in from the last 10 minutes. Confirm once and the change continues automatically.