* config example rename
+ master-to-master replication functionality
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
*.log
|
||||
.*.cnf
|
||||
.idea
|
||||
/_*
|
||||
/config.sh
|
||||
|
23
_activate-master-to-master.sh
Executable file
23
_activate-master-to-master.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/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
|
||||
|
||||
# Установка локально и удаленно MASTER-параметров
|
||||
echo "Get master status from remote server" >> $log_file
|
||||
local_master_status=`mysql --defaults-extra-file=./.remote.my.cnf -e "SHOW MASTER STATUS;
|
||||
" -N`
|
||||
|
||||
local_master_log_file=`echo $local_master_status | cut -d' ' -f1`
|
||||
local_master_log_pos=`echo $local_master_status | cut -d' ' -f2`
|
||||
|
||||
echo "Apply bin log position to remote mariadb db instance" >> $log_file
|
||||
|
||||
replication_user=`cat ./.remote.my.cnf | grep user | cut -d'=' -f2`
|
||||
replication_password=`cat ./.remote.my.cnf | grep password | cut -d'=' -f2`
|
||||
replication_host=$localdatabasepublicip
|
||||
|
||||
mysql --defaults-extra-file=./.remote.my.cnf -e "CHANGE MASTER TO MASTER_HOST = '$replication_host', MASTER_USER = '$replication_user', MASTER_PASSWORD = '$replication_password', MASTER_LOG_FILE = '$remote_master_log_file', MASTER_LOG_POS = $remote_master_log_pos;"
|
@ -16,8 +16,8 @@ remote_master_log_pos=`echo $remote_master_status | cut -d' ' -f2`
|
||||
|
||||
echo "Apply bin log position to local mariadb db instance" >> $log_file
|
||||
|
||||
replication_user=`cat ./.remote.my.cnf | grep user | cut -d'=' -f2`
|
||||
replication_password=`cat ./.remote.my.cnf | grep password | cut -d'=' -f2`
|
||||
replication_host=`cat ./.remote.my.cnf | grep host | cut -d'=' -f2`
|
||||
replication_user=`cat ./.my.cnf | grep user | cut -d'=' -f2`
|
||||
replication_password=`cat ./.my.cnf | grep password | cut -d'=' -f2`
|
||||
replication_host=`cat ./.my.cnf | grep host | cut -d'=' -f2`
|
||||
|
||||
mysql --defaults-extra-file=./.my.cnf -e "CHANGE MASTER TO MASTER_HOST = '$replication_host', MASTER_USER = '$replication_user', MASTER_PASSWORD = '$replication_password', MASTER_LOG_FILE = '$remote_master_log_file', MASTER_LOG_POS = $remote_master_log_pos;"
|
@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
log_file=replication.log
|
||||
databases=( 'database1' 'database2' )
|
||||
localdatabasepublicip=
|
@ -6,14 +6,16 @@ set -a
|
||||
. "${CONFIG_FILE}"
|
||||
set +a
|
||||
|
||||
REMOTE_SQL=
|
||||
|
||||
for i in ${databases[@]}
|
||||
do
|
||||
REMOTE_SQL=$REMOTE_SQL' USE '$i'; FLUSH TABLES WITH READ LOCK;'
|
||||
done
|
||||
|
||||
REMOTE_SQL=$REMOTE_SQL' system ./readbinlog.sh;'
|
||||
REMOTE_SQL=$REMOTE_SQL' system ./_activate-slave.sh;'
|
||||
|
||||
REMOTE_SQL=$REMOTE_SQL' system ./dump.sh;'
|
||||
REMOTE_SQL=$REMOTE_SQL' system ./_dump.sh;'
|
||||
|
||||
for i in ${databases[@]}
|
||||
do
|
||||
@ -25,3 +27,21 @@ echo "Start execution all commands on remote server" > $log_file
|
||||
mysql --defaults-extra-file=./.remote.my.cnf -e "$REMOTE_SQL"
|
||||
|
||||
mysql --defaults-extra-file=./.my.cnf -e "START SLAVE;"
|
||||
|
||||
if [ "$1" -eq "master-to-master" ]; then
|
||||
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
|
||||
fi
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user