您好,登錄后才能下訂單哦!
下文內容主要給大家帶來記錄mysql 備份腳本,這里所講到的知識,與書籍略有不同,都是億速云專業技術人員在與用戶接觸過程中,總結出來的,具有一定的經驗分享價值,希望給廣大讀者帶來幫助。
mysql備份腳本,記錄一下:
全備:
#!/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
對于以上關于記錄mysql 備份腳本,如果大家還有更多需要了解的可以持續關注我們億速云的行業推新,如需獲取專業解答,可在官網聯系售前售后的,希望該文章可給大家帶來一定的知識更新。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。