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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- windows mysqldump備份指令碼WindowsMySql指令碼
- mysql備份指令碼MySql指令碼
- mysqldump壓縮備份匯出匯入(含定期備份shell指令碼)MySql指令碼
- 兩套mysql備份指令碼MySql指令碼
- Mysqldump備份說明及資料庫備份指令碼分享-運維筆記MySql資料庫指令碼運維筆記
- mysql5.6 mysqldump備份報錯MySql
- MySQL主從配置及mysqldump備份MySql
- MySQL中binlog備份指令碼分享MySql指令碼
- MYSQL Slave開機啟動指令碼MySql指令碼
- Mysql定時備份資料指令碼MySql指令碼
- 【MySQL】Xtrabackup備份及恢復指令碼MySql指令碼
- MySQL:Windows下分庫備份指令碼MySqlWindows指令碼
- 備份指令碼指令碼
- Mysql備份和還原資料庫-mysqldumpMySql資料庫
- 【mysqldump】mysqldump及備份恢復示例MySql
- Mysqldump的備份流程MySql
- MySQLDump的備份方法MySql
- mysqldump備份技巧分享MySql
- MySQL資料庫備份的shell指令碼MySql資料庫指令碼
- MySQL備份指令碼,應該這麼寫MySql指令碼
- linux mysql定時備份指令碼記錄LinuxMySql指令碼
- 使用Mysqldump備份和恢復MySQL資料庫MySql資料庫
- rman 備份指令碼指令碼
- ORACLE備份指令碼Oracle指令碼
- Liunx備份mysql資料庫的shell指令碼MySql資料庫指令碼
- 詳解MySQL資料備份之mysqldump使用方法MySql
- 自動備份指令碼指令碼
- Mysqldump實現mysql的master-slave主從複製MySqlAST
- 簡單的mysqldump備份(windows)MySqlWindows
- mysqldump 資料庫備份程式MySql資料庫
- Networker備份oracle單節點Oracle
- MySQL自動備份指令碼30天自動刪除MySql指令碼
- expdp 邏輯備份指令碼指令碼
- 資料庫備份指令碼資料庫指令碼
- mysqldump使用方法(MySQL資料庫的備份與恢復)MySql資料庫
- 自動定時備份 mysql 資料庫 的 shell 指令碼MySql資料庫指令碼
- mysql容器的定時備份指令碼,有二種方法,備份好後打包傳送到遠端備份主機MySql指令碼
- oracle自動冷備份指令碼Oracle指令碼
- 分享Oracle Rman的備份指令碼Oracle指令碼