背景:现网环境全备份脚本:基于xtrabackup命令
#!/bin/sh # MySQL端口 PORT=‘3003‘ # 备份用户 USER=‘bkpuser‘ PAWD=‘bkpuser‘ Time=`date +%Y%m%d_%H%M%S` # 备份路径 BASEDIR=‘/data/backup‘ # 备份保留天数 BACKUP_SAVE_DAYS=‘2‘ # 备份过程->LOG文件 LOGFILE="${BASEDIR}/${Time}info.log" touch ${LOGFILE} # 开始备份 StartTime=`date +%Y%m%d_%H%M%S` echo "Start-Time :${StartTime}" |tee -a ${LOGFILE} echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |tee -a ${LOGFILE} # 备份命令 innobackupex --defaults-file=/data/config/my${PORT}.cnf --user=${USER} --password=${PAWD} --stream=tar /data/backup/ 2>> ${LOGFILE}|gzip >/data/backup/${Time}.tar.gz # 结束备份 StopTime=`date +%Y%m%d_%H%M%S` echo "Stop-Time :${StopTime}" |tee -a ${LOGFILE} echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |tee -a ${LOGFILE} # 清除N天之前的备份 cd ${BASEDIR} /usr/bin/find -name "*.tar.gz" -mtime +${BACKUP_SAVE_DAYS} -exec rm {} \; /usr/bin/find -name "*info.log" -mtime +${BACKUP_SAVE_DAYS} -exec rm {} \;
时间: 2024-11-09 07:56:44