下文內(nèi)容主要給大家?guī)碛涗沵ysql 備份腳本,這里所講到的知識(shí),與書籍略有不同,都是創(chuàng)新互聯(lián)專業(yè)技術(shù)人員在與用戶接觸過程中,總結(jié)出來的,具有一定的經(jīng)驗(yàn)分享價(jià)值,希望給廣大讀者帶來幫助。
創(chuàng)新互聯(lián)公司主要從事網(wǎng)站設(shè)計(jì)、做網(wǎng)站、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)雁江,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108mysql備份腳本,記錄一下:
全備:
#!/bin/sh set -x USER=root PASSWORD=123456 time=`date +"%y-%m-%d-%H-%M"` date >> /data/mysqlbackup/logs/$time'_allbackup.log' #1 begin Full Backups echo "begin backup--------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log' /usr/bin/innobackupex --defaults-file=/etc/my.cnf --user=$USER --password=$PASSWORD --use-memory=2GB --parallel=4 --no-timestamp /data/mysqlbackup/full-$time 2>>/data/mysqlbackup/logs/$time'_allbackup.log' cp /etc/my.cnf /data/mysqlbackup/full-$time/my.cnf.bk echo "end backup----------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log' #2 begin compress echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log' archivename=full-$time echo "The archive time is $time" >> /data/mysqlbackup/logs/$time'_allbackup.log' tarname=$archivename.tar.gz echo "The tar name is $tarname" >> /data/mysqlbackup/logs/$time'_allbackup.log' cd /data/mysqlbackup /bin/tar -zcvf ./$tarname ./$archivename >> /data/mysqlbackup/logs/$time'_allbackup.log' 2>&1 rm -rf /data/mysqlbackup/full/xtrabackup_checkpoints cp /data/mysqlbackup/full-$time/xtrabackup_checkpoints /data/mysqlbackup/full/xtrabackup_checkpoints#3 Delete Document
file=/data/mysqlbackup/$tarname if [[ -e $file ]] then echo "The $tarname file exists.begin to perform delete action" >> /data/mysqlbackup/logs/$time'_allbackup.log' /bin/rm -rf /data/mysqlbackup/$archivename else echo "The file is not exists." >> /data/mysqlbackup/logs/$time'_allbackup.log' fi date >> /data/mysqlbackup/logs/$time'_allbackup.log' find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I '{}' mv {} /data/ftp cd /data/ftp function logftp (){ ftp -v -n xxx.xxx.xxx.xxx << EOF user username password binary hash cd ftp_mysql prompt put /data/mysqlbackup/*tar.gz ls -la bye EOF } logftp >>/data/mysqlbackup/logs/to_ftp.log cd /data/ftp find /data/ftp/*tar.gz |xargs rm -rf增量備份:
#!/bin/sh set -x USER=root PASSWORD=123456 time=`date +"%y-%m-%d-%H-%M"` date >>/data/mysqlbackup/logs/$time'_incre.log' #1 begin Incre Backups echo "begin backup--------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log' /usr/bin/innobackupex --defaults-file=/etc/my.cnf --user=$USER --password=$PASSWORD --incremental --incremental-basedir=/data/mysqlbackup/full --use-memory=2GB --safe-slave-backup --parallel=4 --slave-info --no-timestamp /data/mysqlbackup/incre-$time 2>>/data/mysqlbackup/logs/$time'_incre.log' cp /etc/my.cnf /data/mysqlbackup/incre-$time/my.cnf.bk echo "end backup----------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log' #2 begin compress echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log' archivename=incre-$time echo "The archive time is $time" >> /data/mysqlbackup/logs/$time'_incre.log' tarname=$archivename.tar.gz echo "The tar name is $tarname" >> /data/mysqlbackup/logs/$time'_incre.log' cd /data/mysqlbackup/ /bin/tar -zcvf ./$tarname ./$archivename >> /data/mysqlbackup/logs/$time'_incre.log' 2>&1 #3 Delete Document file=/data/mysqlbackup/$tarname if [[ -e $file ]] then echo "The $tarname file exists.begin to perform delete action" >> /data/mysqlbackup/logs/$time'_incre.log' /bin/rm -rf /data/mysqlbackup/$archivename else echo "The file is not exists." >> /data/mysqlbackup/logs/$time'_incre.log' fi date >> /data/mysqlbackup/logs/$time'_incre.log' find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I '{}' mv {} /data/ftp cd /data/ftp function logftp (){ ftp -v -n xxx.xxx.xxx.xxx << EOF user username password binary hash cd ftp_mysql prompt put /data/mysqlbackup/*tar.gz ls -la bye EOF } logftp >>/data/mysqlbackup/logs/to_ftp.log cd /data/ftp find /data/ftp/*tar.gz |xargs rm -rf對(duì)于以上關(guān)于記錄mysql 備份腳本,如果大家還有更多需要了解的可以持續(xù)關(guān)注我們創(chuàng)新互聯(lián)的行業(yè)推新,如需獲取專業(yè)解答,可在官網(wǎng)聯(lián)系售前售后的,希望該文章可給大家?guī)硪欢ǖ闹R(shí)更新。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。