#!/bin/bash
#back_mysql by 2016-11-14
bak_dir=/data/backup_db/`date +%Y%m%d`
mysqldb=mysql
mysqluser=*****
mysqlpw=******
if [ $UID -ne 0 ];then
echo "must to be use root for exec shell"
exit
fi
#判断是否存在文件,\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
#执行脚本和备份结果
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。