brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pg_verifybackup checks a pg_basebackup copy against its backup manifest

Backup
~/tips/tip-database-pg-verifybackup-manifest

pg_basebackup -h mydbserver -D /usr/local/pgsql/data

Verifies a PostgreSQL base backup against its manifest for missing, extra or damaged files.

A pg_basebackup copy carries a list of every file it should contain, with checksums. pg_verifybackup uses that list to tell you whether the copy is still complete and unchanged, which is the cheapest way I know to check a PostgreSQL file backup.

pg_basebackup -h mydbserver -D /usr/local/pgsql/data
pg_verifybackup /usr/local/pgsql/data

The docs name four steps. It reads the backup_manifest file, checks that the data files on disk are the ones the server meant to send (extra and missing files are reported), checksums every file and compares with the manifest, and finally checks that the write-ahead log records needed for recovery are present and can be parsed. If everything is fine it prints a short success message, and -q / --quiet silences even that, which suits a cron job that only speaks up on errors.

Some options for other situations. A backup in tar format is verified with -F tar. -s / --skip-checksums makes it much faster, because the files are not read, though presence and size are still checked. If you want to keep the manifest away from the backup, which is a good idea since an attacker or a bug could change both together, point to it with -m:

pg_verifybackup -m /my/secure/location/backup_manifest.1234 /usr/local/pgsql/backup1234

The caveat is written in the docs themselves: the validation cannot include every check a running server makes when it uses the backup, so you should still perform test restores and check that the databases contain the right data. Also, the WAL check is version-specific, so use the pg_verifybackup of the same version as the backup.

Further reading: PostgreSQL documentation: pg_verifybackup

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link