How to check if postgresql backup was successful?

We have a postgresql database that is maintained at night from a cron job with the following command:

su postgres -c "pg_dump our_database | gzip > /home/smb/shared/database_backup.bak.gz" 

we recently had a disk crash that started with several bad sectors, and during that time pg_dump exited with the following errors

 pg_dump: SQL command failed pg_dump: Error message from server: ERROR: catalog is missing 17 attribute(s) from relid 20158 pd_dump: The command was: LOCK TABLE public.obvez IN ACCESS SHARE MODE 

Now, since it was in the cron job, no one noticed error messages, the backup was interrupted, but it was not zero, everything seemed fine, and the error went unnoticed until the final drive failed when we realized that we did not have a backup ,

We were able to recover data from an older backup, but now I would like to know what would be the right way to check if pg_dump completed its work with success or not?

+6
source share
1 answer

I write the result to a log file, and at the end of the cronjob I send the contents of the log file to my email address. That way, I will know when something went wrong.

 su postgres "pg_dump our_database 2>> $LOG_FILE | gzip > /home/smb/shared/database_backup.bak.gz" cat $LOG_FILE | mailx $MAINTAINERS -s "Postgresql backup" 

ADD : if you want to send an email only if something went wrong, you can check the pg_dump return code:

 LOG_FILE=/tmp/pgdump.err if ! pg_dump -U backupuser "our_database" 2> $LOG_FILE then cat $LOG_FILE | mailx 'youremailaddress' -s "Postgresql backup failure!" fi 
+8
source

Source: https://habr.com/ru/post/890484/


All Articles