mysql自动备份的脚步,这个脚步可以输入参数以实现是完整备份还有增量备份
#!/bin/bash
echo -e "\033[31m please + f or d or i \033[0m"
FULLBK () {
mysqldump --triggers --lock-all-tables --all-databases >/root/`date "+%Y:%m:%d--%H:%M:%S"`.sql
if [ $? == 0 ];then
tar jcf /root/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2 /root/*.sql
echo -e "\033[032m The backup is success....\033[0m"
read -p "DO you want delete source file,y is "yes",other is "no": " A
case $A in
y|Y)
rm -rf /root/*.sql
echo -e "delete success....."
;;
*)
echo -e "you do nothing"
return 2
;;
esac
else
echo -e "\033[031m The backup is Failure....\033[0m"
fi
}
############################################################################################33
ZLBK (){
ZB='mysql -e "SHOW MASTER STATUS" |grep mysql-bin |cut -f1'
if false;then
mysql -e "FLUSH LOGS;"
mysql -e "FLUSH TABLES WITH READ LOCK;"
# read -p "please input you sql's data postion: " PT
cp /data/mydata/$ZB /root/zback/
tar jcf /root/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2 /root/$ZB && echo "Failure..."
mysql -e "UNLOCK TABLES;"
else
CYBK
fi
}
#############################################################################################
CYBK () {
rm -rf /root/cyback && mkdir /root/cyback
mysql -e "FLUSH LOGS;"
mysql -e "FLUSH TABLES WITH READ LOCK;"
# read -p "please input you sql's data postion: " PT
cp /data/mydata/mysql-bin* /root/cyback/
# tar jcf /root/cyback/* /root/cyback/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2
cd /root/cyback/
tar jcf /mnt/`date "+%Y:%m:%d--%H:%M:%S"`.tar.bz2 ./*
REL=$?
rm -rf /root/cyback/mysql-bin*
mysql -e "UNLOCK TABLES;"
}
# read -p "please input you sql's data postion: " PT
##############################################################################################
while getopts ":fid:" OPTS; do
case $OPTS in
f)
FULLBK
;;
d)
ZLBK
;;
i)
CYBK
;;
*)
echo "nothing"
;;
esac
done
#####################################################################################
阅读(1251) | 评论(0) | 转发(0) |