Get a text when a database backup fails

Yes. Homing Pigeon (homingpigeon.dev) lets your backup script text your phone when the dump fails, and also when it finishes but the file is too small to be a real backup. Your coding agent can add it to the script you already have.

What to tell your agent

Use Homing Pigeon to text me if my nightly database backup fails or the dump file is too small.

Your agent asks for your number, you read back the six-digit code, and it does the rest.

How it works in code

Install the command with npm install -g homingpigeondev and verify your phone. Then save this as backup.sh, with your own database name, folder and minimum size:

#!/bin/sh
out="/var/backups/mydb-$(date +%F).dump"
day=$(date +%Y%m%d)

if ! pg_dump -Fc -f "$out" mydb; then
  homingpigeon send "Backup of mydb failed on $(hostname)." --idempotency-key "backup-failed-$day"
  exit 1
fi

size=$(wc -c < "$out")
if [ "$size" -lt 1000000 ]; then
  homingpigeon send "Backup of mydb is only $size bytes on $(hostname)." --idempotency-key "backup-small-$day"
  exit 1
fi

Then run it every night from cron:

30 2 * * * PATH=/usr/local/bin:/usr/bin:/bin /home/me/backup.sh

Good to know

  • For MySQL or MariaDB, change the dump line to if ! mysqldump --single-transaction mydb > "$out"; then and keep the rest.
  • A dump can exit cleanly and still be nearly empty, for example when it connects to the wrong database. The size check catches that. Set the minimum to about half the size of a normal dump, which ls -l /var/backups shows.
  • Cron cannot answer a password prompt, so keep the database password in ~/.pgpass for pg_dump or ~/.my.cnf for mysqldump, owned by the user the job runs as.
  • The date in the idempotency key means a rerun on the same night never texts you twice for the same problem. A quiet phone means the backup worked.
  • Verify as the same user the cron job runs as, because the key is saved in that user's home folder.

Get started

Add Homing Pigeon to Claude Code, then ask for what you want:

claude mcp add homingpigeondev -- npx -y homingpigeondev mcp

You get 50 free texts every month, on US mobile numbers. See more use cases.