Mysql資料庫增量備份,mysql資料庫增量

來源:互聯網
上載者:User

Mysql資料庫增量備份,mysql資料庫增量

MySQL資料庫增量備份,在這之前修改我們的資料庫設定檔/etc/my.cnf開啟bin-log日誌功能即可。接下來是我參考了下網上的一些方法,自己寫的,主要還是要能學到他的一些思路和方法。

#function:MYSQL增量備份#version:1.0.0#author:wangyanlin#date:2017/08/02#-----------------------------------------------------------------------------------------------#!/bin/shexport LANG=en_US.UTF-8#設定時間DATE=`date +%Y%m%d`#設定資訊USER=rootPASSWORD=withub#設定路徑cd //usr/bin/mkdir -p mysql_bak/daily /usr/bin/mkdir -p mysql_bak/logsBakDir=/mysql_bak/dailyBinDir=/var/lib/mysqlLogFile=/mysql_bak/logs/Daily_$DATE.logBinlogFile=/var/lib/mysql/mysql-bin.index/usr/bin/mysqladmin -u$USER -p$PASSWORD flush-logs #重新整理日誌Counter=`wc -l $BinlogFile | awk '{print $1}'`NextNum=0start_time=`date +'%Y-%m-%d %H:%M:%S'`echo `date +"%Y年%m月%d日 %H:%M:%S"` $Next1 Bakup start! >> $LogFile#這個for迴圈用於比對$Counter,$NextNum這兩個值來確定檔案是不是存在或最新的。for file in  `cat $BinlogFile`do        base=`basename $file`        #basename用於截取mysql-bin.00000*檔案名稱,去掉./mysql-bin.000005前面的./        NextNum=`expr $NextNum + 1`        if [ $NextNum -eq $Counter ]        then                echo $base skip!  >> $LogFile        else                dest=$BakDir/$base                if(test -e $dest)                #test -e用於檢測目標檔案是否存在,存在就寫exist!到$LogFile去。                then                        echo  $base exist! >> $LogFile                else                        cp $BinDir/$base $BakDir                        echo $base copying >> $LogFile                fi        fidoneecho `date +"%Y年%m月%d日 %H:%M:%S"` $Next2 Bakup succ! >> $LogFileend_time=`date +'%Y-%m-%d %H:%M:%S'`start_seconds=$(date --date="$start_time" +%s);end_seconds=$(date --date="$end_time" +%s);echo "本次備份已耗用時間: "$((end_seconds-start_seconds))"s" >> $LogFile

 

添加計劃任務:

                       crontab -e

                       00 03 * * * /root/MySQL_incrementbak.sh    #每天的淩晨3點開始增量備份日

logs日誌列印出來的效果:

                      

有問題請留言,我們互相交流!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.