运维开发网

编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份

运维开发网 https://www.qedev.com 2020-10-18 12:34 出处:51CTO 作者:蜗牛漫步者
[[email protected]]$catback_mysql.sh#!/bin/bash#USER="test"PASSWD="123.com"HOSTIP="192.168.2.7"BACKUP=/data/allback_date+%F[-d"$BACKUP"]||mkdir$BACKUPPS3="请

[[email protected] data]$cat back_mysql.sh

#!/bin/bash

#

USER="test"

PASSWD="123.com"

HOSTIP="192.168.2.7"

BACKUP_DUMP=/data/allbackdump$(date +%F)

BACKUP_XTRA=/data/allbackxtra$(data +%F)

[ -d "${BACKUP_DUMP}" ] || mkdir ${BACKUP_DUMP}

[ -d "${BACKUP_XTRA}" ] || mkdir ${BACKUP_XTRA}

PS3="请按数字选择工具:"

select num in mysqldump xtrabackup quit; do

case $num in

mysqldump)

echo "您选择了mysqldump,请稍等..."

mysqldump -u$USER -p$PASSWD -h$HOSTIP -A -F -E -R --single-transaction --master-data=1 --flush-privileges --triggers --default-character-set=utf8 --hex-blob > ${BACKUP_DUMP}/$(date +%H%M%S).sql 2> /dev/null

if [ "$?" -eq 0 ]; then

echo "mysqldump已执行完毕"

exit 0

else

echo "mysqldump执行出错,请检查"

exit 1

fi

;;

xtrabackup)

echo "您选择了xtrabackup,请稍等..."

which xtrabacup &>/dev/null

#yum安装xtrabackup,需要开启epel源

[ "$?" -eq 0 ] || yum -y install percona-xtrabackup &>/dev/null

xtrabackup --user=$USER --password=$PASSWD --host=$HOSTIP --backup --target-dir=${BACKUP_XTRA} &> /dev/null

if [ "$?" -eq 0 ]; then

echo "xtrabackup已执行完毕"

exit 0

else

echo "xtrabackup执行出错,请检查"

exit 2

fi

;;

quit)

echo "您选择了退出"

break

;;

*)

echo "请输入所需功能前的数字..."

esac

done

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号