Shell implementation, using mysqld_multi automatic multi-instance slave database script implementation

Source: Internet
Author: User
Implement shell and use mysqld_multi to automatically perform multiple instance slave database scripts to implement catdoallslavesh001! Binsh002codebyscpman003mail: scpman @ livecom004blog: http: wwwscpmancom005name: & quot; doallsla shell implementation, using mysqld_multi to automatically perform multiple instance Slave Database Scripts # cat doallslave. sh001 #! /Bin/sh002 # code by scpman003 # mail: scpman@live.com004 # blog: http://www.scpman.com005#name : "Doallslave. sh "006 helpinfo () 007 {008 echo-e '\ t \ thelp view help information '009echo-E' \ t auto-execute allslave slave database script use help '010echo-E' \ t \ tslavename the command can only be xxx_xxx, for example: zq2013_test1 '011echo-E' \ t add a new slave database with three parameters addslave slavename ip mysql.tar-name rootpasswd '012echo-E' \ t: addslave slavename 10.0.88.88 mysql.xxx.tar passwd '013echo-E' \ t delete an example of delslave slavename '014echo-E' \ t: delslave slavename '015} 016 # if the user does not If you have input parameters (or incorrect parameters) or the input parameter is "help", the system displays the help information and exits. 017if [-z "$1"-o "$1" = "help"] 018then019helpinfo020exit021fi022mulu_create () 023 {024 if [-d $1] 025 then026 echo "$1 is have"; 027 else028 mkdir-p $1; 029 echo "create $1 OK! "030 fi031} 032check_mycnf () 033 {034 temp1 = 'tail-n 1/etc/my. cnf | grep "server_id" '; 035 if [-z "$ temp1"] 036 then037 sed-I ""' $ d'/etc/my. cnf038 check_mycnf039 040 else 041 echo "/etc/my. cnf compliant with specifications "; 042 fi043} 044fuc_addslave () 045 {046if [-n "$1"-a-n "$2"-a-n "$3"-a-n "$4"] 047then048 slavename = $1049 masterip = $2050 bao_path = $3051 passwd = $4052else053 echo "1 2 3 4 is null! Shell exit now "054 helpinfo055 exit056fi057 # check whether my. cnf is correct 058check_mycnf059echo" to create a data packet storage directory! "060 sleep 1061mulu_create"/usr/doslave/$ {slavename}/"examples"/usr/db_backups/$ {slavename} _ mysql_backup/"063mulu_create"/usr/mysql_backup/$ {slavename} _ mysql_backup/"064mulu_create"/usr/logs/$ {slavename} _ mysql_backup/"065tar-zxvf $ bao_path-C/usr/doslave/$ {slavename }/; 066rm-rf/usr/db_backups/$ {slavename} _ mysql_backup/*; 067mv/usr/doslave/$ {slavename}/usr/dlm_db/mysql/*/us R/db_backups/$ {slavename} _ mysql_backup/; 068 chown-R mysql: mysql/usr/db_backups/$ {slavename} _ mysql_backup/; 069 echo "data placement completed! Start generating the configuration file "070mulu_create"/usr/doslave/confbak "071cp/etc/my. cnf/usr/doslave/confbak/my. cnf _ 'date + % Y % m % d % H % M % s '; 072cp/usr/mysql_backup/dblist/usr/doslave/confbak/dblist _ 'date + % Y % m % d % H % M % s '; 073 ####################### my. cnf ############ 074 tempconf = "/usr/doslave/$ {slavename}/mycnf. temp "075 tail-n 6/etc/my. cnf> $ tempconf; 076 sleep 2077old_mysqld = "'cat $ tempconf | grep" mysqld "| sed-e" s/\ [mysqld/ /; S/\] //; "'" 078old_port = "'cat $ tempconf | grep 'port' | awk' {print $3} '" 079old_db_name = "'cat $ tempconf | grep" pid-file" | awk-F '/''{print $4}' | awk-f' _'' {print $1 "_" $2} ''" 080old_server_id = "'cat $ tempconf | grep "server_id" | awk '{print $3} ''" 081new_mysqld = "'expr $ {old_mysqld} + 1'" 082new_port = "'expr $ {old_port} + 1 '"083new_db_name =" $ slavename "084new_server_id = 'echo $ masterip | awk-F. '{print $3 $4 "9"} ''085old _ mysqld = "'echo $ old_mysqld '" 086old_port = "'echo $ old_port'" 087old_db_name = "'echo $ old_db_name '" 088old_server_id = "'echo $ old_server_id '" 089sed-I "s/$ old_mysqld/$ new_mysqld/g; s/$ old_port/$ new_port/g; s/$ old_db_name/$ new_db_name/g; s/$ old_server_id/$ new_server_id/g; "$ tempconf; 090 # cat $ tempconf091 # echo '---> '092sleep 2093 echo "">/etc/my. cnf; 094cat $ tempconf>/etc/my. cnf095echo" Mysqld $ {new_mysqld} ">/usr/mysql_backup/dblist; 096 ####################################### ######## 097 echo "my. cnf and dblist have been modified! "098/usr/local/bin/mysqld_multi start $ new_mysqld099sleep 1100BIN = 'cat/usr/db_backups/$ {slavename} _ mysql_backup/pos_mysql | awk '{print $1 }''; 101POS = 'cat/usr/db_backups/$ {slavename} _ mysql_backup/pos_mysql | awk '{print $2 }''; 102 # echo $ passwd103echo $ bin1_echo $ POS105echo/usr/local/bin/mysql-uroot-p $ passwd -- socket =/tmp/mysql _ $ {new_db_name }. sock106sleep 2107/usr/local/bin/mysql-uroot-p $ passwd -- socket =/tmp/mysql _ $ {new_db_name }. sock <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.