MySQL5.5如何实现Slave节点备份脚本-创新互联

小编给大家分享一下MySQL 5.5如何实现Slave节点备份脚本,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

创新互联主要从事网站制作、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务革吉,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

[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 '2,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 "\n==== Jobs ended at `date +%F' '%T' '%w` ====\n" >> ${LOG_FILE}

看完了这篇文章,相信你对“MySQL 5.5如何实现Slave节点备份脚本”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道,感谢各位的阅读!


分享文章:MySQL5.5如何实现Slave节点备份脚本-创新互联
本文URL:http://scyanting.com/article/jhdps.html