标签: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}
标签:bst time script exe log tor def obs ==
原文地址:https://www.cnblogs.com/liang545621/p/9420433.html