标签:select test root use 出错 char exit com lob
[root@centos7 data]$cat back_mysql.sh[ -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
编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份
标签:select test root use 出错 char exit com lob
原文地址:https://blog.51cto.com/14812296/2542216