Files
replication-helper/start-replication.sh

48 lines
1.0 KiB
Bash
Raw Normal View History

2020-04-29 01:29:07 +03:00
#!/bin/bash
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2020-10-17 00:19:28 +03:00
CONFIG_FILE=$DIR/config.sh
2020-04-29 01:29:07 +03:00
[[ ! -r "${CONFIG_FILE}" ]] && { echo "Could not read ${CONFIG_FILE}!"; exit 1; }
set -a
. "${CONFIG_FILE}"
set +a
REMOTE_SQL=
2020-04-29 01:29:07 +03:00
for i in ${databases[@]}
do
REMOTE_SQL=$REMOTE_SQL' USE '$i'; FLUSH TABLES WITH READ LOCK;'
done
REMOTE_SQL=$REMOTE_SQL' system ./_activate-slave.sh;'
2020-04-29 01:29:07 +03:00
REMOTE_SQL=$REMOTE_SQL' system ./_dump.sh;'
2020-04-29 01:29:07 +03:00
for i in ${databases[@]}
do
REMOTE_SQL=$REMOTE_SQL' USE '$i'; UNLOCK TABLES;'
done
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