安装方式二: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 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
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
已有0条评论