MySQL 5.5How to implement Slave Node backup script
Editor to share with you MySQL 5.5 how to achieve Slave node backup script, I hope you will learn something after reading this article, let's discuss it together!
[root@localhost script] # vim slave_full_backup_by_mysqldump.sh
#! / bin/sh
Show_slave_status () {
Echo-e "- master.info: -" > $LOG_FILE
Cat ${MAIN_PATH} / master.info | sed-n '2jue 3p' > > $LOG_FILE
Echo-e "- show slave status: -" > $LOG_FILE
Echo "show slave status\ G" | $MYSQL_CMD | egrep "Slave_IO_Running | Slave_SQL_Running | Master_Log_File | Read_Master_Log_Pos | Exec_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos" > > $LOG_FILE
Echo-e "> > $LOG_FILE
}
HOST_PORT=5505
MAIN_PATH=/mysql_data/5505
DATA_PATH=/backup/
DATA_FILE=$ {DATA_PATH} / mysqldump_dbfullbak_ `date +% F`.sql.gz
LOG_FILE=$ {DATA_PATH} / mysqldump_dbfullbak_ `date +% F`.log
MYSQL_PATH=/data/bin
MYSQL_USER=system
MYSQL_PASS=Mysql#2015
MYSQL_CMD= "${MYSQL_PATH} / mysql-u ${MYSQL_USER}-p$ {MYSQL_PASS}-S / var/lib/mysql/mysql.sock"
MYSQL_DUMP= "${MYSQL_PATH} / mysqldump-u ${MYSQL_USER}-p$ {MYSQL_PASS}-S / var/lib/mysql/mysql.sock-A-R-- single-transaction-l-- default-character-set=utf8"
Echo > $LOG_FILE
Echo-e "= Jobs started at `date +% F'% T''% w` =\ n" > > ${LOG_FILE}
Echo-e "* started position: = =" > > $LOG_FILE
Echo "stop slave SQL_THREAD;" | $MYSQL_CMD
Show_slave_status
Echo-e "* Executed command:$ {MYSQL_DUMP} | gzip > ${DATA_FILE}" > > ${LOG_FILE}
${MYSQL_DUMP} | gzip-> ${DATA_FILE}
Echo-e "* Executed finished at `date +% F'% T''% w` =" > > ${LOG_FILE}
Echo-e "* Backup file size: `du-sh ${DATA_PATH} `*\ n" > ${LOG_FILE}
Echo-e "* recheck position =" > > $LOG_FILE
Show_slave_status
Echo "start slave SQL_THREAD;" | $MYSQL_CMD
Echo-e "- Find expired backup and delete those files -" > > ${LOG_FILE}
For tfile in $(/ bin/find $DATA_PATH/-mtime + 6)
Do
If [- d $tfile]; then
Rmdir $tfile
Elif [- f $tfile]; then
Rm-f $tfile
Fi
Echo-e "- Delete file: $tfile -" > > ${LOG_FILE}
Done
Echo-e "\ nregistered girls = Jobs ended at `date +% F'% T''% w` =\ n" > > ${LOG_FILE}
After reading this article, I believe you have a certain understanding of "MySQL 5.5 how to implement Slave node backup script". If you want to know more about it, you are welcome to follow the industry information channel, thank you for reading!