Browse docs

Monitor database backups

Make sure your backup scripts actually run — and get alerted immediately when they don't.

Database backups fail quietly. A misconfigured script, a full disk, or an expired credential can cause your nightly backup to silently stop running. By the time you need a restore, weeks of backups may be missing.

Wrapping your backup script with a WatchCat ping takes two lines. If the ping doesn't arrive on schedule, you get an alert before the gap becomes a problem.

Step 1 — create a cron monitor

In WatchCat, go to Cron monitors → New monitor. Set the schedule to match your backup frequency (usually daily) and a grace period of 10–30 minutes depending on how long the backup normally takes. Copy the ping URL.

Step 2 — wrap your backup script

Add a ping to the end of your backup script. The simplest pattern pings on success and lets a missing ping indicate failure. For stricter detection, ping on start too so WatchCat can catch backups that begin but never finish.

PostgreSQL backup with ping

#!/bin/bash
set -euo pipefail

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="/backups/db_${TIMESTAMP}.dump"
PING_URL="https://watchcat.io/p/cron/YOUR_TOKEN"

pg_dump -Fc "$DATABASE_URL" > "$BACKUP_FILE"

# Ping only if pg_dump succeeded (set -e exits on error)
curl -fsS "$PING_URL" > /dev/null

MySQL / MariaDB backup with ping

#!/bin/bash
set -euo pipefail

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="/backups/db_${TIMESTAMP}.sql.gz"
PING_URL="https://watchcat.io/p/cron/YOUR_TOKEN"

mysqldump --single-transaction mydb | gzip > "$BACKUP_FILE"

curl -fsS "$PING_URL" > /dev/null
Note: set -euo pipefail causes the script to exit immediately if any command fails. This means the ping is only reached when the backup succeeds. Remove it if your script handles errors differently.

Start and end tracking for long backups

For large databases where backups can take many minutes, use start and end pings. This lets WatchCat detect backups that started but stalled before finishing.

#!/bin/bash
set -euo pipefail

PING_URL="https://watchcat.io/p/cron/YOUR_TOKEN"

curl -fsS "${PING_URL}/start" > /dev/null

pg_dump -Fc "$DATABASE_URL" > "/backups/db_$(date +%Y%m%d).dump"

curl -fsS "${PING_URL}/end" > /dev/null

Step 3 — add to crontab

Run crontab -e and add a line for your script. Run it as the user with database access.

0 3 * * * /home/deploy/backup.sh >> /var/log/backup.log 2>&1

This runs the script every day at 03:00 and logs output to /var/log/backup.log. Redirecting stderr (2>&1) ensures errors are captured too.

Recommended settings

Schedule Daily (or match your backup frequency)
Grace period 10–30 min for small DBs; 60+ min for large ones
Alert after 1 missed run — backups are critical

Start monitoring in minutes

Free plan available. No credit card required.