#!/bin/bash
# 10 23 * * * /bin/bash /data/script/backup.sh
BDATE=`date +%Y%m%d%H%M%S`
BPATH=/data/backupBFILE=${BPATH}/`hostname`_fullbak_${BDATE}.xbstream.gzLOGFILE=${BPATH}/log/`hostname`_fullbak_${BDATE}.logORI_CONF_FILE=/etc/my.cnfBAK_CONF_FILE=${BPATH}/my_`date +%Y%m%d%H%M%S`.cnfBAKCMD="/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 fiecho -e "---- Delete backup file: $tfile ------" >> ${LOGFILE}
done
echo -e "\n====== Backup Jobs end at `date +%F' '%T' '%w` =====\n">> ${LOGFILE}
恢复过程:
xbstream -x < ynhw-mysql-slave.01.mysql.prod.sg_fullbak_20180326134255.xbstream -C /data/mysql
cd /data/
chown -R mysql:mysql mysql然后查看 /data/mysql/xtrabackup_slave_info 文件,已经写好了如下语句:
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000038', MASTER_LOG_POS=211245137