#!/bin/bash
#back_mysql by 2016-11-14bak_dir=/data/backup_db/`date +%Y%m%d`mysqldb=mysqlmysqluser=*****mysqlpw=******if [ $UID -ne 0 ];thenecho "must to be use root for exec shell"
exitfi#判断是否存在文件,\033[32m是显示颜色的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#备份语句mysqldump -u$mysqluser -p$mysqlpw -d $mysqldb >$bak_dir/$mysqldb.sql.tar.gz#是否备份成功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#执行脚本和备份结果