pgBackRest monitoring setup for dbWatch

Purpose

The pgBackRest monitoring jobs in dbWatch depend on backup metadata being available in a PostgreSQL table, normally:

dbwatch_cc.pgbackrest_backup_log

The table name is configurable through the job parameter pgbackrest output table.

Additional resources

Example scripts for configuring pgBackRest backups and collecting backup metadata for dbWatch monitoring are available from GitHub:
Github link

Files to include

Suggested directory

/opt/dbwatch/pgbackrest/

Suggested contents:

/opt/dbwatch/pgbackrest/createpgbackrest.sql
/opt/dbwatch/pgbackrest/get_pgbackrest.sh
/opt/dbwatch/pgbackrest/run_backup_full.sh
/opt/dbwatch/pgbackrest/run_backup_diff.sh
/opt/dbwatch/pgbackrest/run_backup_incr.sh

Setup steps

1. Create the monitoring table in the PostgreSQL database monitored by dbWatch:

psql -h <postgres_host_or_vip> -U postgres -d postgres -f /opt/dbwatch/pgbackrest/createpgbackrest.sql

2. Edit `get_pgbackrest.sh` and verify these values:

PG_USER="postgres"
PG_DATABASE="postgres"
PG_SCHEMA="dbwatch_cc"
PG_TABLE="pgbackrest_backup_log"
STANZA="main"
VIP_HOST="<postgres_vip_or_haproxy_ip>"

3. Make the scripts executable:
chmod 700 /opt/dbwatch/pgbackrest/*.sh

4. Add cron scheduling, for example:

# Full backup every Sunday at 02:00
0 2 * * 0 /usr/bin/flock -n /tmp/pgbackrest.lock /opt/dbwatch/pgbackrest/run_backup_full.sh >> /var/log/pgbackrest_backup_full.log 2>&1

# Incremental backup every 2 hours

0 */2 * * * /usr/bin/flock -n /tmp/pgbackrest.lock /opt/dbwatch/pgbackrest/run_backup_incr.sh >> /var/log/pgbackrest_backup_incr.log 2>&1

# Differential backup Monday-Saturday at 02:00

0 2 * * 1-6 /usr/bin/flock -n /tmp/pgbackrest.lock /opt/dbwatch/pgbackrest/run_backup_diff.sh >> /var/log/pgbackrest_backup_diff.log 2>&1

# Collect pgBackRest metadata every 30 minutes

*/30 * * * * /opt/dbwatch/pgbackrest/get_pgbackrest.sh >> /var/log/get_pgbackrest.log 2>&1

dbWatch monitoring jobs

The following dbWatch jobs use the data from the pgBackRest output table:

All three jobs have the parameter:

pgbackrest output table = dbwatch_cc.pgbackrest_backup_log

The table does not have to be in the dbWatch schema, but it must be accessible from the monitored PostgreSQL database.

Notes