MySQL 5.5 Slave節點備份指令碼(mysqldump)
[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}
#!/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
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}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2091919/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 5.5 mysqldump備份說明MySql
- mysqldump 備份指令碼MySql指令碼
- mysqldump備份指令碼MySql指令碼
- windows mysqldump備份指令碼WindowsMySql指令碼
- mysqldump來備份MYSQL資料庫(指令碼)MySql資料庫指令碼
- mysqldump備份指令碼一例MySql指令碼
- mysqldump 全量和增量備份指令碼MySql指令碼
- mysql備份指令碼MySql指令碼
- mysql 邏輯備份 (mysqldump)MySql
- mysql innobackupex備份指令碼MySql指令碼
- mysqldump壓縮備份匯出匯入(含定期備份shell指令碼)MySql指令碼
- mysql 備份資料庫 mysqldumpMySql資料庫
- MySQL 5.5 Master/Slave 配置MySqlAST
- 兩套mysql備份指令碼MySql指令碼
- mysql按表備份指令碼MySql指令碼
- Mysql異地備份指令碼MySql指令碼
- MySQL自動備份指令碼MySql指令碼
- MySQL備份之分庫分表備份指令碼MySql指令碼
- Mysqldump備份說明及資料庫備份指令碼分享-運維筆記MySql資料庫指令碼運維筆記
- MySQL主從配置及mysqldump備份MySql
- mysql5.6 mysqldump備份報錯MySql
- mysql備份恢復mysqldump面面觀MySql
- mysqldump備份不輸入密碼直接備份MySql密碼
- mysql每天定時備份指令碼MySql指令碼
- mysql定時備份shell指令碼MySql指令碼
- MySQL增量備份的指令碼(innobackupex)MySql指令碼
- mysql的一個備份指令碼MySql指令碼
- mysql之 mysqldump 備份恢復詳解MySql
- Mysql增量備份之Mysqldump& MylvmbackupMySqlLVM
- mysql的常用備份工具:mysqldump和mysqlhotcopyMySql
- Mysql定時備份資料指令碼MySql指令碼
- MySQL中binlog備份指令碼分享MySql指令碼
- MySQL:Windows下分庫備份指令碼MySqlWindows指令碼
- 【MySQL】Xtrabackup備份及恢復指令碼MySql指令碼
- 《mysql資料庫備份小指令碼》MySql資料庫指令碼
- 備份指令碼指令碼
- MYSQL Slave開機啟動指令碼MySql指令碼
- Mysql備份系列(2)--mysqldump備份(全量+增量)方案操作記錄MySql