Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- source ../config_region1.cfg
- source ../config_region2.cfg
- source ../lib/functions.sh
- function rebuild_container ()
- {
- echocolor "Remove Old MariaDB Container on $1"
- docker rm -f hcm-mariadb-$1
- echocolor "Rebuild MariaDB Container on $1"
- sleep 10
- export DB_ROOT_PASSWORD=$MYSQL_PASS
- bash ../files/start-mariadb.sh hcm-mariadb-$1 101
- echocolor "Creating tunnel to $2"
- if ! apt-get -qq install byobu; then apt-get install byobu -y; fi
- byobu new-session -d -s ssh_tmp
- byobu new-window -t ssh_tmp:1 -n "controller" "ssh -L 3300:localhost:3306 root@$2 -p $SSH_PORT_HN /bin/bash"
- sleep 30
- echocolor "Dumping keystone database from $2"
- mysql -u root -p$MYSQL_PASS -h 127.0.0.1 -P 3300 -e "FLUSH TABLES WITH READ LOCK"
- binlog_file=`mysql -u root -p$MYSQL_PASS -h 127.0.0.1 -P 3300 -e "SHOW MASTER STATUS" | grep binlog | awk '{print $1}'`
- binlog_pos=`mysql -u root -p$MYSQL_PASS -h 127.0.0.1 -P 3300 -e "SHOW MASTER STATUS" | grep binlog | awk '{print $2}'`
- mysqldump -u root -p$MYSQL_PASS -h 127.0.0.1 -P 3300 keystone > keystone.sql
- echocolor "Restore database to container"
- cat << EOF | mysql -uroot -p$MYSQL_PASS -h 127.0.0.1 -P 3305
- CREATE DATABASE keystone;
- GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '$KEYSTONE_DBPASS';
- GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '$KEYSTONE_DBPASS';
- FLUSH PRIVILEGES;
- EOF
- mysql -uroot -p$MYSQL_PASS -h 127.0.0.1 -P 3305 keystone < keystone.sql
- mysql -u root -p$MYSQL_PASS -h 127.0.0.1 -P 3300 -e "UNLOCK TABLES"
- echocolor "Start replication"
- cat << EOF | mysql -uroot -p$MYSQL_PASS -h 127.0.0.1 -P 3305
- CHANGE MASTER TO
- MASTER_HOST='$2',
- MASTER_USER='repl',
- MASTER_PASSWORD='weascafa221f',
- MASTER_PORT=3306,
- MASTER_LOG_FILE='$binlog_file',
- MASTER_LOG_POS=$binlog_pos,
- MASTER_CONNECT_RETRY=10;
- START SLAVE;
- EOF
- if [ "$?" -eq 0 ]; then echocolor "Start Replicate Success"; fi
- byobu kill-session -t ssh_tmp
- } # ---------- end of function create_container ----------
- hostname=`cat /etc/hostname`
- if [[ "$hostname" == controller1* ]]; then
- rebuild_container "controller1" "$CTL1_MGNT_IP_HN"
- elif [[ "$hostname" == controller2* ]]; then
- rebuild_container "controller2" "$CTL2_MGNT_IP_HN"
- else
- echocolor "Run on Controller1 or Controller2"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement