- #!/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
- #####################################################################################
mysql自动备份的脚步
原创
©著作权归作者所有:来自51CTO博客作者随风飘云的原创作品,请联系作者获取转载授权,否则将追究法律责任
mysql自动备份的脚步,这个脚步可以输入参数以实现是完整备份还有增量备份
上一篇:一键制作linux
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL 8自动备份脚本密码安全警告
作者:田逸(formyz)目标需求接到一个任务,需要在凌晨四点对一个数据库进行备
mysql v8 MySQL