You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
#!/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
|
|
|
|
readopt='getopts $opts opt;rc=$?;[ $rc$opt == 0? ]&&exit 1;[ $rc == 0 ]||{ shift $[OPTIND-1];false; }'
|
|
|
|
opts=vfdo:
|
|
|
|
# Enumerating options
|
|
#while eval $readopt
|
|
#do
|
|
# echo OPT:$opt ${OPTARG+OPTARG:$OPTARG}
|
|
#done
|
|
|
|
# Enumerating arguments
|
|
databases=( )
|
|
|
|
for arg
|
|
do
|
|
databases=( $databases $arg )
|
|
done
|
|
|
|
if [[ -z "$databases" ]]; then
|
|
cat <<EOF
|
|
Usage: $0 database_one [...database_two]
|
|
EOF
|
|
exit
|
|
fi
|
|
|
|
echo "Set replication databases to: ${databases[@]}"
|
|
|
|
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 ./dump.sh;'
|
|
|
|
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;"
|