* config example rename

+ master-to-master replication functionality
This commit is contained in:
2020-10-16 16:54:25 +03:00
parent ab39087868
commit 3b8eab4600
6 changed files with 50 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
*.log
.*.cnf
.idea
/_*
/config.sh

23
_activate-master-to-master.sh Executable file
View 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;"

View File

@ -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;"

View File

View File

@ -1,3 +1,4 @@
#!/bin/bash
log_file=replication.log
databases=( 'database1' 'database2' )
localdatabasepublicip=

View File

@ -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