A failure email can tell you the backup job exited non-zero. If the job never starts, or exits 0 before the upload has finished, that email never comes.
There are three questions worth an alert, and each one needs a different signal:
- Did the job run on schedule?
- Did it finish writing a complete backup to storage?
- Can that backup actually be restored?
A failed run is part of the first question, and it's the easy part.
1. Did it run?
An exit code can only report on a run that happened. If the cron entry was removed, the CI schedule was disabled, or the machine was off at 3 a.m., nothing exits at all, so nothing complains.
The fix is to invert the check: the job reports in on every run, and something outside the job raises an alert when the report doesn't arrive. That's a dead man's switch. Healthchecks.io works this way, and so does any monitoring system that can alert on "no data":
#!/usr/bin/env bash
set -euo pipefail
PING="${BACKUP_PING_URL:?}"
curl -fsS -m 10 --retry 2 "$PING/start" > /dev/null || true
if ./run-backup.sh; then
curl -fsS -m 10 --retry 2 "$PING" > /dev/null || true
else
status=$?
curl -fsS -m 10 --retry 2 "$PING/fail" > /dev/null || true
exit "$status"
fi
The || true matters. A monitoring service that's down for a minute shouldn't turn a good backup into a failed one. A lost success ping costs you a false alarm, which is the cheaper mistake.
-
Grace time. Leave room for a late CI start followed by your slowest real backup, not your average one. After a
/startping, Healthchecks also uses the grace time as the longest it waits for the success ping, so a job that hangs gets flagged too. - One check per schedule. If backups and restore tests share a check, the backup's daily success keeps it green while a restore test that stopped running goes unnoticed.
Also check where the "job failed" email actually goes. For a scheduled GitHub Actions workflow, GitHub notifies the workflow's creator by default. If someone else later edits the cron schedule, or disables and re-enables the workflow, notifications move to that person, and they only arrive if that person's notification settings allow them. Make sure failures reach someone who's still watching.
2. Did it finish uploading?
A script can swallow an upload error and exit 0 with a multipart upload still open. If the bucket or prefix comes from the project name, a rename can also send a good dump somewhere you aren't looking. In both cases the job still sends its success ping.
Have a separate process check the expected bucket and prefix directly. It needs two things from the backup job:
- A marker written last. Write the dump files first and a small manifest (file list, sizes, checksums) after everything else has uploaded. A snapshot without its manifest is one that didn't finish. "Is there a backup?" then becomes "is there a recent snapshot that has a manifest?", which is a much better question.
- Names that sort by time. If each snapshot goes into a folder named after its UTC start time, the newest complete snapshot is the last folder with a manifest in it. The checker lists the folder prefixes, then looks for a manifest from newest to oldest, so it never has to list the files inside each snapshot.
This guide to alerting on overdue Supabase backups in S3 runs the check as a daily Lambda on EventBridge Scheduler and emails you through SNS when the newest complete backup is overdue. Give the checker s3:ListBucket as well as read access: without it, S3 answers a request for a missing manifest.json with 403 instead of 404, and the check stops on an unfinished backup instead of skipping it.
If you already run Prometheus, the same check fits as a metric. Once that separate process finds the newest complete snapshot, use the LastModified time of its manifest as the finish time, and write it to a .prom file that node_exporter's textfile collector picks up:
# /var/lib/node_exporter/textfile/backup.prom
backup_last_complete_timestamp_seconds{db="app"} 1764125400
- alert: BackupOverdue
expr: time() - backup_last_complete_timestamp_seconds > 26 * 3600
for: 15m
labels:
severity: page
annotations:
summary: "Newest complete backup of {{ $labels.db }} is {{ $value | humanizeDuration }} old (limit 26h)"
Write the file to a temporary name and rename it into place, so the collector never reads half a file. If the app series stops being reported, BackupOverdue has nothing to evaluate for that database and stays quiet. Add absent(backup_last_complete_timestamp_seconds{db="app"}) as a second alert, one per database you expect to report.
On S3, also add a lifecycle rule that aborts incomplete multipart uploads after a few days. It doesn't alert on anything, but it stops failed uploads from quietly piling up in storage you pay for.
3. Can it be restored?
A complete, recent file can still let you down. The dump might leave out a schema you need, or depend on roles and extensions the restore server doesn't have. A restore can also finish without errors and still leave a table empty.
The only check that answers this is a restore: load the latest snapshot into a throwaway Postgres on a schedule, then compare what came back with what you expected, such as table counts, row counts for the tables that matter, and a recent max(created_at). For setting up the throwaway Postgres and reading the pg_restore errors you're likely to hit, see this 19-slide deck on Postgres restore drills.
- The last restore test failed. Treat this like a failed backup. It means the backup you'd rely on today might not work.
- The last successful restore test is too old. This is the "did it run?" problem again, one level up. Give restore tests their own dead man's switch, and set the deadline from the restore schedule, leaving time for both the restore and the data checks.
If you run restore tests weekly and backups daily, start with an alert after eight days without a successful restore test, and adjust it for the delays you actually see in CI. Record which snapshot each restore test used, so whoever gets paged can see which backup last passed.
Before these alerts start paging people
- Split the work. The job sends a start ping and reports its result. An external monitor alerts on missed pings, and a separate checker looks for a recent complete backup in the bucket.
-
Alert on the checker itself. Add an alarm on its errors, and track when it last ran. If it stops updating its
.promfile, node_exporter keeps serving the old value, soabsent()won't fire. node_exporter exposes each file's modification time asnode_textfile_mtime_seconds, so you can alert whentime() - node_textfile_mtime_seconds{file=~".*backup\\.prom"}gets larger than a day. - Set thresholds from the schedule. For daily backups, start with 26 hours. For weekly ones, a week plus a day. Then adjust for how late your scheduled runs actually start.
- Send one test alert end to end. Confirm it reaches the channel your team reads, not just an inbox.
- Put the numbers in the message. For example: "Backup overdue: newest complete snapshot is 31 hours old."
Top comments (1)
The restore check is the bit I would push one step further. Restoring the latest dump proves the file loads, but it does not prove you can hit your recovery point if you rely on WAL archiving for point in time recovery, because a gap in the WAL chain only shows up when you try to replay past it. I would have the drill restore to a named target time and record how long it took, then alert on the trend as well as failures. A restore that still passes but takes twice as long as last month is an early warning that your recovery time objective is drifting.