自動備份Mysql數據庫腳本

 

 

[root@bogon ~]# cat auto_backup_mysql.sh #!/bin/bash #auto backup mysql db #by authors wugk 2014
#define backup path BAK_DIR=/data/backup/`date +%Y%m%d` MYSQLDB=cacti MYSQLUSR=backup 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 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.sql if [ $? -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
相關文章
相關標籤/搜索