mysql指令碼備份

來源:互聯網
上載者:User

標籤:mysql 指令碼 備份

[[email protected] ~]# cat mysqldump.sh#!/bin/bash#echo "============================"echo "mysql dump,youcan choose which database to backup,if not I will back all databases"echo "==========================="read -p "Please tell me which database do you want to backup ===> " base[ -d /data/back ] || mkdir -p /data/back && chown -R mysql.mysql /data/backtime=`date +%F--%T`datedir1=/data/back/all_$timedatedir2=/data/back/${base}_${time}if [ -z $base ];thenmysqldump -uzou -h172.16.1.7 -p123.comer --all-databases --lock-all-tables --flush-logs > $datedir1 >>/dev/null[ $? == 0 ] && echo "$time == ALL databases has backup ok" >> /data/back/back.log || exit 5else mysql -e "use $base" &> /dev/null [ $? == 0 ] || echo "Maybe the database $base is not exsit or the name is wrong" >> /data/back/back.log && exit 7mysqldump -uzou -h172.16.1.7 -p123.comer --databases --lock-tables $base > $datedir2 >> /dev/null[ $? == 0 ] && echo "database $base has backup ok" >> /data/back/back.log || exit 9fi增量備份指令碼如下[[email protected] ~]# cat mysqldump_added.sh #!/bin/bash#mysqladmin flush-logsbackindexdir=/data/indexback/[ -e $backindexdir ] || mkdir -p /data/indexback/indexfile=`grep ‘^log_bin‘ /etc/my.cnf | awk -F "=" ‘{print $2}‘`.indexindexdir=`grep ‘datadir‘ /etc/my.cnf | cut -d = -f2`binfiles=`cat ${indexdir}/${indexfile}`totalfile=`wc -l ${indexdir}/${indexfile} | awk ‘{print $1}‘`numindex=0for file in $binfiles;donumindex=$(($numindex+1))base=`basename $file`#判斷備份目錄裡面沒有這個檔案,並且不是剛產生的二進位檔案(上面執行命令會自動建立一個,新的暫時沒資料)if [ ! -e $backindexdir/$base -a $numindex -ne $totalfile ];thencp $indexdir/$base $backindexdirfidone

本文出自 “北極的linux” 部落格,請務必保留此出處http://941012521.blog.51cto.com/9253690/1845536

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.