溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

innobackup增量備份腳本

發(fā)布時(shí)間:2020-08-08 12:26:07 來源:ITPUB博客 閱讀:177 作者:wkdahlia 欄目:MySQL數(shù)據(jù)庫
參考涂抹mysql里的腳本,做了下改進(jìn)

[mysql@mysql01 scripts]$ cat mysql_full_backup_by_xtra.sh
#!/bin/sh
# Created by wk

DATA_PATH=/data/mysqldata/backup/mysql_full
DATA_FILE=${DATA_PATH}/xtra_fullbak_`date +%Y%m%d%H%M`
LOG_FILE=${DATA_PATH}/xtra_fullbak_`date +%Y%m%d%H%M`.log
ORI_CONF_FILE=/data/mysqldata/3306/my.cnf
NEW_CONF_FILE=${DATA_PATH}/my_3306_`date +%Y%m%d%H%M`.cnf
MYSQL_PATH=/data/mysqldata/backup/innobackupex/bin
MYSQL_CMD="${MYSQL_PATH}/innobackupex --user=root --password=pass1 --defaults-file=/data/mysqldata/3306/my.cnf --no-lock --no-timestamp ${DATA_FILE}"

echo > $LOG_FILE
echo -e "==== Jobs started at `date +%F' '%T' '%w` ====\n" >> $LOG_FILE
echo -e "==== First cp my.cnf file to backup directory ====" >> $LOG_FILE
/bin/cp ${ORI_CONF_FILE} ${NEW_CONF_FILE}
echo >> $LOG_FILE

#echo -e "**** Executed command:${MYSQL_CMD} | gzip > ${DATA_FILE}" >> $LOG_FILE
${MYSQL_CMD} 2>>${LOG_FILE}
echo -e "**** Executed finished at `date +%F' '%T' '%w` ====" >> $LOG_FILE
echo -e "**** Backup file size: `du -sh ${DATA_FILE}` ====\n" >> ${LOG_FILE}

echo -e "---- Find expired backup and delete those files ----" >> ${LOG_FILE}
for tfile in $(/usr/bin/find $DATA_PATH/ -mtime +6)
do
        if [ -d $tfile ] ; then
             rmdir $tfile
        elif [ -f $tfile ] ; then
             rm -f $tfile
        fi
         echo -e "---- Delete tfile: $tfile ----" >> ${LOG_FILE}
done

echo -e "\n==== Jobs ended at `date +%F' '%T' '%w` ====\n" >> $LOG_FILE

echo "backup_full=${DATA_FILE}" >/data/mysqldata/scripts/backup.conf
echo "backup_pre_name=${DATA_FILE}" >>/data/mysqldata/scripts/backup.conf

[mysql@mysql01 scripts]$ cat mysql_incr_backup_by_xtra.sh
#!/bin/sh
# Created by wk
source /data/mysqldata/scripts/backup.conf
DATA_PATH=/data/mysqldata/backup/mysql_full
DATA_FILE=${DATA_PATH}/xtra_incrbak_`date +%Y%m%d%H%M`
#OLD_DATA_FILE=${DATA_PATH}/xtra_fullbak_`date -d "1 days ago" +"%F"`
LOG_FILE=${DATA_PATH}/xtra_incrbak_`date +%Y%m%d%H%M`.log
ORI_CONF_FILE=/data/mysqldata/3306/my.cnf
NEW_CONF_FILE=${DATA_PATH}/my_3306_`date +%Y%m%d%H%M`.cnf
MYSQL_PATH=/data/mysqldata/backup/innobackupex/bin
MYSQL_CMD="${MYSQL_PATH}/innobackupex --user=root --password=pass1 --defaults-file=/data/mysqldata/3306/my.cnf --incremental --no-lock --no-timestamp
--incremental-basedir=${backup_pre_name} ${DATA_FILE}"

echo > $LOG_FILE
echo -e "==== Jobs started at `date +%F' '%T' '%w` ====\n" >> $LOG_FILE
echo -e "==== First cp my.cnf file to backup directory ====" >> $LOG_FILE
/bin/cp ${ORI_CONF_FILE} ${NEW_CONF_FILE}
echo >> $LOG_FILE

echo -e "**** Executed command:${MYSQL_CMD} | gzip > ${DATA_FILE}" >> $LOG_FILE
${MYSQL_CMD} 2>>${LOG_FILE}
echo -e "**** Executed finished at `date +%F' '%T' '%w` ====" >> $LOG_FILE
echo -e "**** Backup file size: `du -sh ${DATA_FILE}` ====\n" >> ${LOG_FILE}

echo -e "---- Find expired backup and delete those files ----" >> ${LOG_FILE}
for tfile in $(/usr/bin/find $DATA_PATH/ -mtime +6)
do
        if [ -d $tfile ] ; then
             rmdir $tfile
        elif [ -f $tfile ] ; then
             rm -f $tfile
        fi
         echo -e "---- Delete tfile: $tfile ----" >> ${LOG_FILE}
done

echo -e "\n==== Jobs ended at `date +%F' '%T' '%w` ====\n" >> $LOG_FILE

echo "backup_full=${DATA_FILE}" >/data/mysqldata/scripts/backup.conf
echo "backup_pre_name=${DATA_FILE}" >>/data/mysqldata/scripts/backup.conf

[mysql@mysql01 scripts]$ cat backup.conf
backup_full=/data/mysqldata/backup/mysql_full/xtra_incrbak_201609011805
backup_pre_name=/data/mysqldata/backup/mysql_full/xtra_incrbak_201609011805

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI