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

xtrabackup备份脚本

时间:2017-08-07 18:30:47      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:color   zip   结束   logfile   backup   sed   style   脚本   exec   

 背景:现网环境全备份脚本:基于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 {} \;

 

xtrabackup备份脚本

标签:color   zip   结束   logfile   backup   sed   style   脚本   exec   

原文地址:http://www.cnblogs.com/cuisi/p/7300485.html

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