Get a push notification when a backup finishes
The worst time to learn a backup has been failing for three weeks is the night you need to restore. Wrap your nightly dump in a short bash script and Lert sends you the archive size when it succeeds and the error when it doesn't — so a silent, missing notification becomes the alarm that saves you.
Report success, size, and failure
A good backup notification tells you three things: that it ran, how big the result was, and — if it broke — where. A bash trap on ERR handles the failure path, so an error anywhere in the script fires a POST before it exits:
#!/usr/bin/env bash set -euo pipefail LERT_URL="https://lert.dev/p/your-id" OUT="/backups/db-$(date +%F).sql.gz" notify() { curl -sS -X POST "$LERT_URL" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg t "$1" --arg b "$2" \ '{title:$t, body:$b, tag:"backup"}')" >/dev/null } # Any error below fires a failure ping with the line number trap 'notify "Backup FAILED ❌" "exit on line $LINENO"' ERR pg_dump "$DATABASE_URL" | gzip > "$OUT" SIZE=$(du -h "$OUT" | cut -f1) notify "Backup OK ✅" "$OUT — $SIZE in ${SECONDS}s"
set -euo pipefail makes the script stop on the first error and treats a failure anywhere in the pg_dump | gzip pipe as a failure. The trap ... ERR catches that and sends the failure notification with the line number; if everything works, the last line reports the path, human-readable size, and how many seconds it took.
Set it up in three steps
1. Copy your Lert URL
Open the Lert app and copy your unique endpoint — something like https://lert.dev/p/your-id. Store it in the script or an environment variable and treat it like a password.
2. Wrap your existing backup command
Whatever you run now — pg_dump, mysqldump, tar, restic, rsync — goes in the middle. Add set -euo pipefail at the top, the ERR trap for failures, and the size-and-duration POST at the end.
3. Schedule it
Run it from cron overnight. Because the script reports both outcomes, you'll get a small green "Backup OK" every morning — and the absence of one is a signal in itself.
# 2:30am every night
30 2 * * * /opt/scripts/nightly-backup.sh
Watch the size, not just the exit code. A dump that succeeds but shrinks to a few kilobytes usually means an empty or broken database. Since the size is right there in the notification, you'll spot it at a glance. For the schedule itself, see cron job notifications; to catch the machine before it fills up, server monitoring pairs well.
Guard against the silent skip
The failure mode a nightly ping catches best is the one no error handler sees: the job that stopped being scheduled at all. A crashed cron, a full disk that killed the daemon, a host that got rebuilt without the crontab. When the expected 2:30am "Backup OK" doesn't arrive, that gap is your cue to go look. Some teams take it further with a dead-man's-switch: a separate check that alerts if no success ping was recorded overnight.
Where this earns its keep
- Database dumps: nightly
pg_dump/mysqldumpwith the compressed size confirmed each morning. - File & volume backups:
restic,borg, ortarsnapshots reporting how much was written. - Offsite sync: an
rsyncorrclonepush to S3 that pings when the upload completes. - Restore drills: wrap a periodic test-restore so you're told it still actually works.
Why Lert for backup alerts
Backup tooling that emails on failure trains you to trust silence — and silence is exactly what a dead backup produces. Lert flips it: a real push every night that a locked phone can't miss, set up with one function and one POST. No agent on the box, no account, no key to rotate — the endpoint URL is the authentication. It's the cheapest insurance you'll add all year.
FAQ
Why notify on success and not just on failure?
A backup that silently stops running looks identical to one that simply never fails. A nightly success ping with the archive size confirms the job ran and produced a sane file — so a missing notification becomes the alert that something's wrong.
How do I catch a failure in the middle of the script?
Use set -e with a bash trap ... ERR, or check the backup command's exit code directly. The trap fires a failure POST with the failing line number before the script exits, so a mid-backup error still reaches your phone.
Can I include the backup size and duration?
Yes. Measure the archive with du -h and time the run with the shell's SECONDS variable, then put both in the body. A size that suddenly drops toward zero is an early warning even when the exit code looks clean.
Do I need an API key or account?
No. Your Lert endpoint URL is the authentication — there's no separate key, token, or login. Keep it in the script or an env var.
How fast does the notification arrive?
Typically within a second or two of the POST. It's a real push, so it wakes a locked phone and buzzes a paired Apple Watch.
Related use cases
Know your backups ran — every night.
Download Lert, copy your URL, wrap your backup in one script. Your phone reports the size, or the error.