From beb464fad781d7cda0b28f7870b4a26219f6e44e Mon Sep 17 00:00:00 2001 From: Justin Burnham Date: Mon, 10 Dec 2012 13:17:11 -0800 Subject: [PATCH] Support xtrabackup safe-slave-backup option. For jayjanssen/Percona-Pacemaker-Resource-Agents#3 --- heartbeat/mysql | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/heartbeat/mysql b/heartbeat/mysql index d6a278271..4ad1f054e 100755 --- a/heartbeat/mysql +++ b/heartbeat/mysql @@ -87,6 +87,7 @@ OCF_RESKEY_max_slave_lag_default="3600" OCF_RESKEY_evict_outdated_slaves_default="false" OCF_RESKEY_reader_attribute_default="readable" OCF_RESKEY_reader_failcount_default="1" +OCF_RESKEY_backup_lockfile_default="/var/lock/innobackupex" : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} @@ -121,6 +122,7 @@ MYSQL_BINDIR=`dirname ${OCF_RESKEY_binary}` : ${OCF_RESKEY_reader_attribute=${OCF_RESKEY_reader_attribute_default}} : ${OCF_RESKEY_reader_failcount=${OCF_RESKEY_reader_failcount_default}} +: ${OCF_RESKEY_backup_lockfile=${OCF_RESKEY_backup_lockfile_default}} ####################################################################### # Convenience variables @@ -374,6 +376,28 @@ there are short intermittent issues like clock adjustments in VMs. Allowed failcount for reader + + + +The path to a file that will be exclusively locked by any backup +process. The lockfile serves to provide a reliable way of determining +whether to restart the slave process or not. If a thirdparty process +locks this file, the agent will fail to lock the file and will not +start the slave. When this agent is able to lock the file, it is +assumed that backups are finished and the slave thread should be +running and will start it. + +A typical cron command example would be like: +flock -xn /var/lock/innobackupex innobackupex --safe-slave-backup /tmp/mysqlbackup + +This example will use innobackupex's ability to stop the slave when necessary +to ensure backup consistency. During this time the agent will not start the +slave. Once the backup is complete, the lock will automatically expire and +the agent can start the slave if it isn't already. + +Path to backup lockfile + + @@ -558,9 +582,22 @@ check_slave() { set_reader_attr 0 $CRM_MASTER -v 0 - # try to restart slave - ocf_run $MYSQL $MYSQL_OPTIONS_REPL \ - -e "START SLAVE" + # Check that the flock tool exists first + if type flock &>/dev/null; then + ( + flock -xn 200 + if [ $? -eq 0 ]; then + ocf_run $MYSQL $MYSQL_OPTIONS_REPL \ + -e "START SLAVE" + else + ocf_log info "Unable to lock $OCF_RESKEY_backup_lockfile. Not starting slave." + fi + ) 200>$OCF_RESKEY_backup_lockfile + else + # try to restart slave + ocf_run $MYSQL $MYSQL_OPTIONS_REPL \ + -e "START SLAVE" + fi # Return success to prevent a restart exit $OCF_SUCCESS