xtrabackup安装及备份脚本

AndyYang| 阅读:418 发表时间:2022-03-11 13:21:56 mysql
摘要:xtrabackup安装及备份脚本分享
安装方式一:yum安装
yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
percona-release enable-only tools release
yum install percona-xtrabackup-24


安装方式二:rpm安装

wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.4/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.4-1.el7.x86_64.rpm
yum localinstall percona-xtrabackup-24-2.4.4-1.el7.x86_64.rpm


卸载

yum remove percona-xtrabackup

添加定时任务部署:

全部备份

0 1 * * * /bin/bash /opt/ubash/innobackup-full.sh >/dev/null 2>&1


局部备份

30 * * * * /bin/bash /opt/ubash/innobackup-incremental.sh  >/dev/null 2>&1


具体脚本:

vim innobackup-full.sh

BACK_UP_PATH="/webdb_back/"
BACK_UP_GZ_PATH="/webdb_back_gz/"
FULL_DIR_NAME="full"
INCR_DIR_NAME="incr"
SOCKET_FILE='/tmp/mysql.sock'
#BANKUP_FILE="backup_$(date +%Y%m%d%H%M).tar.gz"
BANKUP_FILE="backup_$(date +%Y%m%d).tar.gz"
DB_USER="root"
DB_PASS="webyang.net"
DB_CONFIG_FILE="/etc/my.cnf"
DB_NAME='webblog'
#保存天数
save_days=3
tar zcf ${BACK_UP_GZ_PATH}${BANKUP_FILE} ${BACK_UP_PATH}
rm -rf $BACK_UP_PATH*
mkdir $BACK_UP_PATH$FULL_DIR_NAME
mkdir $BACK_UP_PATH$INCR_DIR_NAME
find $BACK_UP_GZ_PATH -mtime +$save_days -exec rm -rf {} \;
innobackupex --defaults-file=$DB_CONFIG_FILE --user=$DB_USER --password=$DB_PASS --socket=$SOCKET_FILE --databases=$DB_NAME $BACK_UP_PATH$FULL_DIR_NAME


vim innobackup-incremental.sh

BACK_UP_PATH="/webdb_back/"
BACK_UP_GZ_PATH="/webdb_back_gz/"
FULL_DIR_NAME="full"
INCR_DIR_NAME="incr"
DB_USER="root"
DB_PASS="webyang.net"
DB_CONFIG_FILE="/etc/my.cnf"
SOCKET_FILE='/tmp/mysql.sock'
DB_NAME='webblog'
#DIR_TEMPS=`find ${BACK_UP_PATH}${INCR_DIR_NAME} -maxdepth 1 -type d -mmin -90`
#cd $BACK_UP_PATH$INCR_DIR_NAME;
for filename in `find ${BACK_UP_PATH}${INCR_DIR_NAME} -maxdepth 1 -type d -mmin -90`;
do
  if [ "$filename" != "${BACK_UP_PATH}${INCR_DIR_NAME}" ]; then
        BASE_DIR=${filename}
  fi
done
if [ "$BASE_DIR" = "" ]; then
#cd $BACK_UP_PATH$FULL_DIR_NAME;
   for filename in `find  ${BACK_UP_PATH}${FULL_DIR_NAME} -maxdepth 1 -type d`;
do
   if [ "$filename" != "${BACK_UP_PATH}${FULL_DIR_NAME}" ]; then
        BASE_DIR=${filename}
   fi
done
fi
innobackupex  --defaults-file=$DB_CONFIG_FILE --lock-wait-threshold=40 --lock-wait-query-type=all --lock-wait-timeout=180 --kill-long-queries-timeout=20 --kill-long-query-type=all  --user=$DB_USER --password=$DB_PASS --socket=$SOCKET_FILE --databases=$DB_NAME --incremental --incremental-basedir=$BASE_DIR $BACK_UP_PATH$INCR_DIR_NAME

本文为AndyYang原创,转载请注明出处!
如果您觉得好,可以打赏作者:
如果您觉得累了,是否想看点美女养养眼:猛戳>>朋友帮
如果您觉得皮了,是否想来点神吐槽:猛戳>>iPhone查询中

已有0条评论

昵称:
邮箱:

  • 最新评论

iPhone查询中 - bbs.ipcxz.com 朋友帮 - www.pengyb.cn iPhone查询中 - bbs.ipcxz.com
反馈
微信订阅号