小陆同学

python 中文名:蟒蛇,设计者:Guido van Rossum

导航

mysql备份任务

crontab -l

查看定时任务

#定时备份mysql数据库

10 00 * * * /usr/local/shell/innobackupex.sh

cat /usr/local/shell/innobackupex.sh

查看备份脚本

#!/bin/sh

 

# MySQL端口

PORT='3306'

 

# 备份用户

USER='root'

PAWD='123456'

 

Time=`date +%Y%m%d_%H%M%S`

 

# 备份路径

BASEDIR='/data/backup/3306'

 

# 备份保留天数

BACKUP_SAVE_DAYS='15'

 

# 备份过程->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}

 

# 备份命令

/usr/local/percona-xtrabackup/bin/innobackupex  --defaults-file=/etc/my.cnf --user=${USER} --password=${PAWD} --socket=/tmp/mysql.sock --stream=tar ${BASEDIR} 2>> ${LOGFILE}|gzip >${BASEDIR}/${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 {} \;

 
View Code

 

cd /data/backup/3306/

进入备份路径

ll -thr

posted on 2022-01-16 11:05  小陆同学  阅读(43)  评论(0编辑  收藏  举报