{"id":2255,"date":"2015-07-01T06:45:20","date_gmt":"2015-07-01T06:45:20","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=2255"},"modified":"2024-01-27T17:36:34","modified_gmt":"2024-01-27T17:36:34","slug":"monitoring-mysql-database-backups","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/monitoring-mysql-database-backups","title":{"rendered":"How to monitor MySQL backups"},"content":{"rendered":"\n<p>It&#8217;s important to monitor the (database) backups after you set-it-up. In this post we will answer a few how to monitor MySQL Database backups solutions &#8211; monitoring methods.<\/p>\n\n\n\n<p>We should see suggestions for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Monitoring Holland MySQL Backup<\/li>\n\n\n\n<li>Monitoring mysqldump backups<\/li>\n\n\n\n<li>Monitoring Xtrabackup using log<\/li>\n\n\n\n<li>Monitoring Backups using Nagios<\/li>\n<\/ul>\n\n\n\n<p>Usually we can have our backup script capable of detecting the status of the backup and send an success \/ failure email accordingly. Alternatively the backup script can write the status to backup logs and the monitoring system should be capable of reading logs, determine the backup failure and alert.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Let&#8217;s consider one by one.<\/p>\n\n\n\n<p><h2><b>Monitoring MySQL Backup<\/b> &#8211; <strong>Holland Framework<\/strong><\/h2>  <p>Recently we saw how to setup MySQL backup using holland and xtrabackup. So if you&#8217;re using Holland framework to configure and setup your backup, things get little easier for you! From version 1.0.7 we have the new variable, failed-backup-command, which comes handy to take an action upon backup failure detected by Holland framework itself.<\/p> <\/p>\n\n\n\n<p>We already have a configuration option to help us out on backup failure scenario:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    failed-backup-command = echo \"The backup on `hostname` (`date '+%Y%m%d'`) has failed. Please review the backup logs.\" | mail -s \"[ALERT] Backup has failed on `hostname`.\" email@domain.com\n<\/pre>\n\n\n\n<p>Instead of a command we can use a script in this command option.<\/p>\n\n\n\n<p>We can ofcourse check the holland backup logs to view if the backup has failed. (If you&#8217;re using older Holland version and this feature sounds interesting, it&#8217;s time to upgrade.)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Monitoring backups taken by MySQLdump<\/b><\/h2>\n\n\n\n<p><p>Let&#8217;s consider we&#8217;re using mysqldump to take logical backup. The backup script can have an additional check-point for backup confirmation.<\/p> <\/p>\n\n\n\n<p>Check out the snippet as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    # ... mysqldump command to take mysql-backup ...#\n    # Confirming last line of mysqldump as 'dump completed'\n    IsOK=`zcat full_dump.sql.gz | tail -n1 | grep \"Dump completed\" | wc -l`\n    if [ $IsOK -eq 1 ]; then\n        subject=\"SUCCESS: $DBSERVER Daily backup completed.\";\n        content=\"Success string 'Dump completed' found in the backup file full_dump.sql.gz. Backup is successful.\"\n        email_list=$success_email;\n        log \"Backup is successful.\"\n    else\n        subject=\"FAILURE: $DBSERVER Daily backup failed.\";\n        content=\"Success string 'Dump completed' not found in the backup file full_dump.sql.gz. Backup appears to have been failed.\"\n        email_list=$failure_email\n        log \"[ERROR] Backup failed.\" # Write in log, we can scan log for backup verification as well.\n    fi;\n    sendEmail # Use the send email function to alert for failure\n<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">(Functions in above code snippet are  taken from previous post. You might want to <a href=\"http:\/\/kedar.nitty-witty.com\/blog\/10-useful-shell-script-code-snippets-linux\" target=\"_blank\" rel=\"noopener\" title=\"\">refer useful-code-snippets-for-your-shell-scripts<\/a>.)\n<\/pre>\n\n\n\n<p><h2><strong><b>Monitoring MySQL Backups by Xtrabackup <\/b>log<\/strong><\/h2> In case you&#8217;re using a script wrapper around xtrabackup, make sure you check the xtrabackup backup-log for possible errors to detect the failures. For a successful backup, xtrabackup writes &#8220;completed OK!&#8221; to the log, which should confirm the backup success. Though we should make sure to also verify the backup log to check for &#8220;ERROR&#8221; or &#8220;WARNING&#8221; getting logged in case of any failures. Xtrabackup may also fail due to a <a href=\"http:\/\/kedar.nitty-witty.com\/umask-umask_dir-changing-mysql-file-dir-permissions\" target=\"_blank\" rel=\"nofollow noopener\">database directory \/ file permission issues<\/a> for the backup user!<\/p>\n\n\n\n<p>You may check for:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    grep \"ERROR\\|WARNING\" xtrabackup.log # Should be 0\n    grep \"completed OK!\" xtrabackup.log | wc -l # Should be &gt;1\n<\/pre>\n\n\n\n<p><h2><b>Monitoring MySQL Backups using Nagios:<\/b><\/h2> If you&#8217;re using Nagios to monitor the MySQL database system you may choose to configure check_file_age plugin to look to check the backup file. <\/p>\n\n\n\n<p>Define Nagios Service:<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi localhost.cfg (usually under \/usr\/local\/nagios\/etc\/objects\/)\ndefine service{\n    use                             active-service\n    hostgroup_name                  mysql-servers\n    service_description             MySQL User Connections\n    check_command                   check_file_age!86400!86400!\/backup\/file-name\n}\n<\/pre>\n\n\n\n<p>Define Nagios Command:<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi commands.cfg (usually under \/usr\/local\/nagios\/etc\/objects\/)\ndefine command{\n    command_name    check_file_age\n    command_line    $USER1$\/check_file_age -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$\n}\n<\/pre>\n\n\n\n<p>I hope this answers few of the the backup monitoring needs.<br>Ofcourse, never to forget that even when you confirm that the backups are successful, restore tests doesn&#8217;t loose their importance.<\/p>\n","protected":false},"excerpt":{"rendered":"It&#8217;s important to monitor the (database) backups after you set-it-up. In this post we will answer a few how to monitor MySQL Database backups solutions &#8211; monitoring methods. We should&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,870,377],"tags":[881,879,878,876,877,882,875,880],"class_list":{"0":"post-2255","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-mysql","7":"category-mysql-tools","8":"category-mysql-articles","9":"tag-backup-monitor-nagios","10":"tag-monitor-mysqldump","11":"tag-monitor-xtrabackup","12":"tag-monitoring-backups","13":"tag-mysql-backups","14":"tag-mysql-holland-backup","15":"tag-mysql-monitor-backup","16":"tag-mysql-monitoring-using-nagios"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=2255"}],"version-history":[{"count":11,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2255\/revisions"}],"predecessor-version":[{"id":3200,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2255\/revisions\/3200"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=2255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=2255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=2255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}