码迷,mamicode.com
首页 > 其他好文 > 详细

innobackup增量备份脚本

时间:2017-05-04 16:29:49      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:size   cat   comm   ***   word   pex   my.cnf   hose   llb   

参考涂抹mysql里的脚本,做了下改进

[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

innobackup增量备份脚本

标签:size   cat   comm   ***   word   pex   my.cnf   hose   llb   

原文地址:http://www.cnblogs.com/godspeed034/p/6807324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!