#!/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