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

innobackupex备份脚本

时间:2018-08-04 23:19:08      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:bst   time   script   exe   log   tor   def   obs   ==   

#!/bin/bash

# 10 23 * * * /bin/bash /data/script/backup.sh

BDATE=`date +%Y%m%d%H%M%S`
BPATH=/data/backup
BFILE=${BPATH}/`hostname`_fullbak_${BDATE}.xbstream.gz
LOGFILE=${BPATH}/log/`hostname`_fullbak_${BDATE}.log
ORI_CONF_FILE=/etc/my.cnf
BAK_CONF_FILE=${BPATH}/my_`date +%Y%m%d%H%M%S`.cnf
BAKCMD="/usr/bin/innobackupex --defaults-file=${ORI_CONF_FILE} --user=root --password=PASSWD --slave-info --stream=xbstream --parallel=2 /tmp"


echo > ${LOGFILE}

echo -e "===== Backup Job start at `date +%Y-%m-%d‘ ‘%T`=====\n" >> ${LOGFILE}
echo -e "===== Fist cp my.cnf to backup directory ${BPATH} ===\n" >> ${LOGFILE}
/bin/cp ${ORI_CONF_FILE} ${BAK_CONF_FILE}
echo >> ${LOGFILE}


echo -e "**** Executed command: ${BAKCMD} |gzip > ${BFILE}" >> ${LOGFILE}
${BAKCMD} 2>> ${LOGFILE} |gzip > ${BFILE}

echo -e "*** Execute finished at `date +%Y-%m-%d‘ ‘%T` =====">>${LOGFILE}
echo -e "*** Backup file size: `du -sh ${BFILE}` =======\n">>${LOGFILE}


echo -e "----- clear expired backup and delete those files ------" >> ${LOGFILE}

for tfile in $(/usr/bin/find $BPATH/ -mtime +3)
do
if [ -d $tfile ];then
rmdir $tfile
elif [ -f $tfile ];then
rm -f $tfile
fi

echo -e "---- Delete backup file: $tfile ------" >> ${LOGFILE}

done

echo -e "\n====== Backup Jobs end at `date +%F‘ ‘%T‘ ‘%w` =====\n">> ${LOGFILE}

 

innobackupex备份脚本

标签:bst   time   script   exe   log   tor   def   obs   ==   

原文地址:https://www.cnblogs.com/liang545621/p/9420433.html

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