if语句编写Mysql备份脚本
#!/bin/bash #auto bakcup mysql db #by authors zgh 2019 #define backup path BAK_DIR=/data/backup/`date +%Y%m%d` MYSQLDB=mysql MYSQLUSR=root MYSQLPW=123456 MYSQLCMD=/usr/bin/mysqldump if [ $UID -ne 0 ];then echo "Must to be use root for exec Shell." exit fi if [ -d $BAK_DIR ];then echo "This $BAK_DIR is exists..." else mkdir -p $BAK_DIR echo -e "\033[32m The $BAK_DIR Create Suessfully!\033[0m" fi #Mysql BACKUP COMMAND $MYSQLCMD -u$MYSQLUSR -p$MYSQLPW -d $MYSQLDB >$BAK_DIR/$MYSQLDB.sql if [ $? -eq 0 ];then echo -e "\033[32m The mysql Backup $MYSQLDB Successfully!\033[0m" else echo -e "\033[32m The mysql Backup $MYSQLDB Failed,Please check.\033[0m" fi
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步