生產(chǎn)環(huán)境的MySQL是通過(guò)crontab的方式,定時(shí)調(diào)度熱備腳本備份數(shù)據(jù)。目前是通過(guò)XtraBackup軟件實(shí)現(xiàn)熱備。關(guān)于熱備腳本方面,請(qǐng)查看我原先的博客《使用shell實(shí)現(xiàn)mysql自動(dòng)全備、增備&日志備份》:http://linzhijian.blog.51cto.com/1047212/1891745 ,這里不再展開說(shuō)明。
靈石ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!備份存放:通過(guò)XtraBackup的流式備份,將備份異地存放到備份服務(wù)器上。
備份策略:周日全備,周一到周六增備。
目前缺漏:這些備份數(shù)據(jù)未能實(shí)現(xiàn)有效性檢查,無(wú)法探知這些備份是否具有可用性,需要通過(guò)一定的機(jī)制實(shí)現(xiàn)有效性檢測(cè)。
目前在備份機(jī)的備份文件列表如下:
drwxr-xr-x 18 mysql mysql 4096 Apr 9 03:28 mysql01_20170409_023001_full drwxr-xr-x 18 mysql mysql 4096 Apr 10 03:25 mysql01_20170410_023001_incr drwxr-xr-x 18 mysql mysql 4096 Apr 11 03:26 mysql01_20170411_023001_incr drwxr-xr-x 18 mysql mysql 4096 Apr 12 03:25 mysql01_20170412_023001_incr drwxr-xr-x 18 mysql mysql 4096 Apr 13 03:26 mysql01_20170413_023001_incr drwxr-xr-x 18 mysql mysql 4096 Apr 14 03:26 mysql01_20170414_023001_incr drwxr-xr-x 18 mysql mysql 4096 Apr 15 03:27 mysql01_20170415_023001_incr drwxr-xr-x 18 mysql mysql 4096 Apr 16 03:29 mysql01_20170416_023001_full drwxr-xr-x 18 mysql mysql 4096 Apr 17 03:26 mysql01_20170417_023001_incr其中full結(jié)尾的說(shuō)明當(dāng)天是全備的,incr結(jié)尾的說(shuō)明當(dāng)天是增備的。
腳本實(shí)現(xiàn)邏輯:自動(dòng)恢復(fù)全備數(shù)據(jù),并依次恢復(fù)其余的增備數(shù)據(jù)到全備數(shù)據(jù)中,最后將恢復(fù)完畢的全備數(shù)據(jù)用mysqld拉起來(lái),檢查MySQL的錯(cuò)誤日志是否有異常報(bào)錯(cuò)來(lái)判斷恢復(fù)是否正常。
vim dbrecover.sh
#!/bin/sh if [ $# -ne 1 ] then echo "usage: `basename $0` [mysql01|mysql02]" exit 1 fi hostname=$1 today=`date +%Y%m%d` sh /home/mysql/shell/mysql_recover.sh $hostname $todayvim mysql_recover.sh
#!/bin/sh if [ $# -ne 2 ] then echo "usage: `basename $0` [mysql01|mysql02|mysql03] 20170501 " exit 1 fi hostname=$1 #hostname="mysql02" #today=`date +%Y%m%d` today=$2 #week=`date +%w` week=`date -d $today +%w` time1=`date +%s` timestamp=`date +%Y%m%d%H%M%S` logdir="/home/mysql/log/mysqlrecoverlog/$hostname/$timestamp" dir="/mysqlbackup/databak/$hostname/" fullname="$dir/full_backup_file.txt" incrname="$dir/incr_backup_file.txt" datadir=`grep datadir /etc/my.cnf|awk -F \= '{print $NF}'` errlog=`grep log-error /etc/my.cnf|awk -F \= '{print $NF}'` n1="0" ##周幾做熱備,周一到周六為1~6,周日為0。 n2="6" ##周幾最后一次增備,周一到周六為1~6,周日為0。 mkdir $logdir ##創(chuàng)建日志目錄 function getdir() { if [ $week -eq "$n1" ] then fulldir=`find /mysqlbackup/databak/${hostname}/ -type d -name "*${today}*full"` #/mysqlbackup/databak/mysql01/mysql01_20170430_023001_full if [ ! -n "$fulldir" ] then echo "the fulldir not exist!!!" >> $logdir/recover_${timestamp}.log exit 1 fi num=`find /mysqlbackup/databak/${hostname}/ -type d -name "*${today}*full"|wc -l` #/mysqlbackup/databak/mysql01/mysql01_20170429_023001_incr if [ $num -eq "1" ] then echo $fulldir > $fullname else echo "there are not only full dbbackup in $today, please check!!!" >> $logdir/recover_${timestamp}.log exit 1 fi else incrdir=`find /mysqlbackup/databak/${hostname}/ -type d -name "*${today}*incr"` if [ ! -n "$incrdir" ] then echo "the incrdir not exist!!!" >> $logdir/recover_${timestamp}.log fi num=`find /mysqlbackup/databak/${hostname}/ -type d -name "*${today}*incr"|wc -l` if [ $num -eq "1" ] then echo $incrdir > $incrname else echo "there are not only incr dbbackup in $today, please check!!!" >> $logdir/recover_${timestamp}.log exit 1 fi fi } function uncompress() { dir=$1 /usr/bin/innobackupex --decompress --parallel=8 $dir >>$logdir/uncompress_${timestamp}.log 2>&1 success_flag=`cat $logdir/uncompress_${timestamp}.log|grep "completed OK"` if [ -n success_flag ] then echo "$dir decompress sucessfully!" >> $logdir/recover_${timestamp}.log else echo "$dir decompress failed " >> $logdir/recover_${timestamp}.log exit 1 fi } function full_recover() { fullbakdir=$1 uncompress $fullbakdir /usr/bin/innobackupex --use-memory=2G --apply-log --redo-only $fullbakdir >>$logdir/full_recover_${timestamp}.log 2>&1 success_flag=`cat $logdir/full_recover_${timestamp}.log|grep "innobackupex: completed OK"` if [ -n "$success_flag" ] then echo "the full dbbackup $fullbakdir recovery is success!" >> $logdir/recover_${timestamp}.log else echo "the full dbbackup $fullbakdir recovery is fail!" >> $logdir/recover_${timestamp}.log exit 1 fi } function incr_recover() { incrbakdir=$1 fullbakdir=$2 uncompress $incrbakdir uncompress $fullbakdir if [ $week -ne "$n2" ] then /usr/bin/innobackupex --use-memory=2G --apply-log --redo-only --incremental-dir=$incrbakdir $fullbakdir >>$logdir/incr_recover_${timestamp}.log 2>&1 else /usr/bin/innobackupex --use-memory=2G --apply-log --incremental-dir=$incrbakdir $fullbakdir >>$logdir/incr_recover_${timestamp}.log 2>&1 fi success_flag=`cat $logdir/incr_recover_${timestamp}.log|grep "innobackupex: completed OK"` if [ -n "$success_flag" ] then echo "the incr dbbackup $incrbakdir recovery is success!" >> $logdir/recover_${timestamp}.log else echo "the incr dbbackup $incrbakdir recovery is fail!" >> $logdir/recover_${timestamp}.log exit 1 fi } function mysqlrecover() { fullbakdir=$1 #uncompress $fullbakdir rm -fr $datadir /bin/ln -s $fullbakdir $datadir chown -R mysql:mysql $datadir chown -R mysql:mysql $fullbakdir /sbin/service mysqld start error_flag=`grep -i error $errlog` if [ -z "$error_flag" ] then echo "the mysqld don't report error, mysql recover is success!" >> $logdir/recover_${timestamp}.log else echo "the mysqld report error, mysql recover is fail, please check!" >> $logdir/recover_${timestamp}.log exit 1 fi /sbin/service mysqld stop } getdir if [ $week -eq "$n1" ] then full=`cat $fullname` full_recover $full else incr=`cat $incrname` full=`cat $fullname` incr_recover $incr $full if [ $week -eq "$n2" ] then mysqlrecover $full fi fi time2=`date +%s` times=$((${time2}-${time1})) echo "it takes $times seconds to finish the recover!!!" >> $logdir/recover_${timestamp}.log備份機(jī)目前采用二進(jìn)制包安裝MySQL的方式,直接上傳到/usr/local/mysql目錄上,配置好相應(yīng)的/etc/profile和/etc/my.cnf即可。
cat /etc/my.cnf
[mysqld] datadir=/mysqlbackup/mysql_test socket=/mysqlbackup/mysql_test/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/mysqlbackup/mysql_test/mysqld.log pid-file=/mysqlbackup/mysql_test/mysqld.pid生成的日志文件如下:
-rw-r--r-- 1 root root 613918 May 4 09:34 incr_recover_20170504092501.log -rw-r--r-- 1 root root 307 May 4 09:34 recover_20170504092501.log -rw-r--r-- 1 root root 259310 May 4 09:26 uncompress_20170504092501.log其中:
uncompress_20170504092501.log:解壓備份文件時(shí)產(chǎn)生的日志信息
incr_recover_20170504092501.log:XtraBackup應(yīng)用備份文件時(shí)產(chǎn)生的日志信息
recover_20170504092501.log:當(dāng)次恢復(fù)備份文件記錄的簡(jiǎn)要日志信息
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前題目:基于XtraBackup的備份有效性檢查腳本-創(chuàng)新互聯(lián)
當(dāng)前地址:http://www.rwnh.cn/article30/cchjpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容