[root@bogon ~]# cat auto_backup_mysql.sh #!/bin/bash#auto backup mysql db#by authors wugk 2014#define backup pathBAK_DIR=/data/backup/`date +%Y%m%d`MYSQLDB=cactiMYSQLUSR=backupMYSQLPW=123456MYSQLCMD=/usr/bin/mysqldumpif [ $UID -ne 0 ];then echo "Must to be use root for exec shell." exitfiif [ ! -d $BAK_DIR ];then mkdir -p $BAK_DIR echo -e "\033[32mThe $BAK_DIR Create Successfully!\033[0m"else echo "This $BAK_DIR is exists..."fi#Mysql BACKUP COMMAND$MYSQLCMD -u$MYSQLUSR -p$MYSQLPW -d $MYSQLDB > $BAK_DIR/$MYSQLDB.sqlif [ $? -eq 0 ];then echo -e "\033[32mThe Mysql Backup $MYSQLDB Successfully!\033[0m"else echo -e "\033[32mThe Mysql Backup $MYSQLDB Failed, please check.\033[0m"fi