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.

47 lines
1.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/bin/bash
  2. export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. CONFIG_FILE=$DIR/config.sh
  4. [[ ! -r "${CONFIG_FILE}" ]] && { echo "Could not read ${CONFIG_FILE}!"; exit 1; }
  5. set -a
  6. . "${CONFIG_FILE}"
  7. set +a
  8. REMOTE_SQL=
  9. for i in ${databases[@]}
  10. do
  11. REMOTE_SQL=$REMOTE_SQL' USE '$i'; FLUSH TABLES WITH READ LOCK;'
  12. done
  13. REMOTE_SQL=$REMOTE_SQL' system ./_activate-slave.sh;'
  14. REMOTE_SQL=$REMOTE_SQL' system ./_dump.sh;'
  15. for i in ${databases[@]}
  16. do
  17. REMOTE_SQL=$REMOTE_SQL' USE '$i'; UNLOCK TABLES;'
  18. done
  19. echo "Start execution all commands on remote server" > $log_file
  20. mysql --defaults-extra-file=./.remote.my.cnf -e "$REMOTE_SQL"
  21. mysql --defaults-extra-file=./.my.cnf -e "START SLAVE;"
  22. if [ "$1" -eq "master-to-master" ]; then
  23. LOCAL_SQL=
  24. for i in ${databases[@]}
  25. do
  26. LOCAL_SQL=LOCAL_SQL' USE '$i'; FLUSH TABLES WITH READ LOCK;'
  27. done
  28. LOCAL_SQL=LOCAL_SQL' system ./_activate-master-to-master.sh;'
  29. for i in ${databases[@]}
  30. do
  31. LOCAL_SQL=LOCAL_SQL' USE '$i'; UNLOCK TABLES;'
  32. done
  33. fi