mysql 备份脚本

#!/bin/bash

#auto backup mysql

#xiaosu 2015-08-06


User=root

Password=123456

DIR_BACK=/data/`date +%Y%m%d`

DATE=`date +%Y%m%d `

DATABASE=test


#判断用户是否是管理员root


if [ $UID -ne 0 ];then

echo -e "\033[32mThe script must use root\033[0m"

sleep 2

exit 

fi


#判断备份目录是否存在


if [ ! -d $DIR_BACK ];then

mkdir -p $DIR_BACK;

else

echo -e "\033[32mThe $DIR_BACK is exist\033[32m"

fi


#备份数据库

 

/usr/local/mysql/bin/mysqldump -u$User -p$Password -d $DATABASE >$DIR_BACK/$DATE.sql


if [ -f $DIR_BACK/$DATE.sql ];then

echo "The mysqlbackup successfully"

else

echo "the mysqlbackup faied"

fi


你可能感兴趣的:(mysql,用户)