restore snippets

How to monitor database backups with monit

Tagged backup, monit, monitoring, restore, sql  Languages 

“It’s not the backup, it’s the restore”

We want to know when our database backup process, including restore, is broken. We can use monit to monitor that our database:

  • is being backed up, i.e., that the backup script is being run periodically
  • can be restored from a backup, i.e., that the backup is not corrupted

More specifically we want to monitor the following:

We use monit to monitor the script that restores the database from a backup. For this we need:

  • a script, e.g. written in Ruby, that restores the database from a fresh backup

    • the script should write to a log file, e.g. /var/log/db-restore.log, after the database has been successfully restored
    • the script should check facts such as, e.g., number of rows
  • a monit script that checks the script has been run successfully within, e.g., the last 24 hours