mysql增量備份指令碼

來源:互聯網
上載者:User

標籤:mysql增量備份指令碼

#!/bin/bash

BakDir=/home/webdata/mysqlbackup/mysqlbackup_log/

BinDir=/home/mysql/var/

LogFile=/home/webdata/mysqlbackup/mysqlbackup_log/bak.log

BinFile=/home/mysql/var/mysql-bin.index

mysqldump -udearedu -p --lock-tables --flush-logs --master-data=1 vkt > /home/webdata/mysqlbackup/mysqlbackup_log/vkt.backup

####重新整理日誌,產生新的日誌並拷貝到相應目錄下

Counter=`wc -l $BinFile |awk ‘{print $1}‘`###計算bin-log索引裡面。Binlog日誌數量

NextNum=0

for file in cat $BinFile`

do

     base=`basename $file`擷取去除./檔案名稱

     NextNum=`expr $NextNum + 1`

     if [ $NextNum -eq $Counter ] 

       then

           echo $base skip!  >> $LogFile  

       else

           dest=$BakDir/$base

           if(test -e $dest)

              then

                 echo  $base exist! >> $LogFile####跳過最後一個bin_log日誌,因為最後一個日誌正在記錄中

              else

                 cp $BinDir/$base $BakDir

                 echo $base copying >> $LogFile

            fi

      fi

done

/usr/bin/expect<<EOF

###引入expect,用於互動登入,普通shell指令碼不能實現互動式,輸入密碼自動登入mysql

###下面是自動拷貝到備份伺服器

set timeout 300;

spawn scp -r $BakDir 192.168.0.90:/sde/50_mysqlbackup

expect "*password:"

send "password\r"

sleep 1

expect 1

expect eof

EOF

 


本文出自 “滿宇帥的技術部落格” 部落格,請務必保留此出處http://manyushuai.blog.51cto.com/8818545/1733283

mysql增量備份指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.