innobackupex备份脚本

Posted liang545621

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了innobackupex备份脚本相关的知识,希望对你有一定的参考价值。

#!/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`===== " >> ${LOGFILE}
echo -e "===== Fist cp my.cnf to backup directory ${BPATH} === " >> ${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}` ======= ">>${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 " ====== Backup Jobs end at `date +%F‘ ‘%T‘ ‘%w` ===== ">> ${LOGFILE}

 





















以上是关于innobackupex备份脚本的主要内容,如果未能解决你的问题,请参考以下文章

innobackupex备份脚本

mysql热备工具innobackupex参数详解

在线热备份数据库之innobackupex 完整备份InnoDB

mysql 备份 常用脚本

mysql xtrabackup备份工具使用

MySQL Backup--innobackupex操作日志