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