这篇文章将为大家详细讲解有关mysqldump如何实现全量和增量备份脚本,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
#!/bin/bash # #mysql 全量备份脚本,建议在slave从库上运行,并开启log_slave_updates=1 backupdir=/backup dateDIR=`date +%Y-%m-%d` logsindexPath=/usr/local/mysql/logs/ray-bin.index if [ ! -d $backupdir ];then mkdir -p $backupdir fi cd ${backupdir} if [ ! -d $dateDIR ];then mkdir -p $dateDIR fi for i in `mysql -uroot -p123456 -e "show databases" 2>&1 | grep -v -E "Database|Warning"` do mysqldump -uroot -p123456 --default-character-set=utf8 -q --flush-privileges --single-transaction --master-data=1 --flush-logs --routines --triggers --events --hex-blob -E -R -B testdb | gzip > ${backupdir}/${dateDIR}/mysql_back_${i}_${dateDIR}.sql.gz done binlog_rm=`tail -n 1 ${logsindexPath} | awk -F '/' '{print $NF}'` mysql -uroot -p123456 -e "purge binary logs to '${binlog_rm}'" |
#!/bin/bash #mysql 增量备份脚本,建议在slave从服务器上运行,并开启log_slave_updates=1 backupdir=/backup dateDIR=`date +%Y-%m-%d` logsIndexPath=/usr/local/mysql/logs/ray-bin.index mysqladmin -uroot -p123456 flush-logs binlog_cp=`head -n -1 ${logsIndexPath}` for i in ${binlog_cp} do mysql -uroot -p123456 -e "\! cp -p ${i} ${backupdir}/${dateDIR}/" done binlog_rm=`tail -n 1 ${logsIndexPath} | awk -F '/' '{print $NF}'` mysql -uroot -p123456 -e "purge binary logs to '${binlog_rm}'" |