From d9d40251f7b3dca2a89107bc5a0e58d8d62206da Mon Sep 17 00:00:00 2001 From: dimti Date: Wed, 21 Oct 2020 11:31:30 +0300 Subject: [PATCH] * separate start master-to-master replication --- replication-master-to-master.sh | 36 ++++++++++++++++++++++++++++++++++++ start-replication.sh | 27 +-------------------------- 2 files changed, 37 insertions(+), 26 deletions(-) create mode 100755 replication-master-to-master.sh diff --git a/replication-master-to-master.sh b/replication-master-to-master.sh new file mode 100755 index 0000000..078bfa3 --- /dev/null +++ b/replication-master-to-master.sh @@ -0,0 +1,36 @@ +#!/bin/bash +export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +CONFIG_FILE=$DIR/config.sh +[[ ! -r "${CONFIG_FILE}" ]] && { echo "Could not read ${CONFIG_FILE}!"; exit 1; } +set -a +. "${CONFIG_FILE}" +set +a + +echo "Started activation of master-to-master replication" >> $log_file + +echo "Stop remote slave" >> $log_file +mysql --defaults-extra-file=./.remote.my.cnf -e "STOP SLAVE;" + +echo "Execute command on local server with push local binlog position to remote server" >> $log_file + +LOCAL_SQL= + +for i in ${databases[@]} +do + LOCAL_SQL=LOCAL_SQL' USE '$i'; FLUSH TABLES WITH READ LOCK;' +done + +LOCAL_SQL=LOCAL_SQL' system ./_activate-master-to-master.sh;' + +for i in ${databases[@]} +do + LOCAL_SQL=LOCAL_SQL' USE '$i'; UNLOCK TABLES;' +done + +mysql --defaults-extra-file=./.my.cnf -e "$REMOTE_SQL" + +echo "Start remote slave" >> $log_file + +mysql --defaults-extra-file=./.remote.my.cnf -e "START SLAVE;" + + diff --git a/start-replication.sh b/start-replication.sh index d923548..a1d5476 100755 --- a/start-replication.sh +++ b/start-replication.sh @@ -35,32 +35,7 @@ echo "Start local slave" >> $log_file mysql --defaults-extra-file=./.my.cnf -e "START SLAVE;" if [[ "$1" = "master-to-master" ]]; then - echo "Started activation of master-to-master replication" >> $log_file - - echo "Stop remote slave" >> $log_file - mysql --defaults-extra-file=./.remote.my.cnf -e "STOP SLAVE;" - - echo "Execute command on local server with push local binlog position to remote server" >> $log_file - - LOCAL_SQL= - - for i in ${databases[@]} - do - LOCAL_SQL=LOCAL_SQL' USE '$i'; FLUSH TABLES WITH READ LOCK;' - done - - LOCAL_SQL=LOCAL_SQL' system ./_activate-master-to-master.sh;' - - for i in ${databases[@]} - do - LOCAL_SQL=LOCAL_SQL' USE '$i'; UNLOCK TABLES;' - done - - mysql --defaults-extra-file=./.my.cnf -e "$REMOTE_SQL" - - echo "Start remote slave" >> $log_file - - mysql --defaults-extra-file=./.remote.my.cnf -e "START SLAVE;" + ./replication-master-to-master.sh; fi