#!/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
#执行脚本和备份结果
时间: 2024-10-07 06:13:34