#!/bin/bash
# 备份数据库
BAK_DIR=/data/backup/`date +%Y%m%d`
MYSQLDB=dexin
MYSQLUSER=root
MYSQLPW=123456
MYSQLCMD=/usr/bin/mysqldump
# 判断是否是root执行的
if [ $UID -ne 0 ];then
echo "Must use root"
exit
fi
# 判断目录是否存在
if [ ! -d $BAK_DIR ];then
mkdir -p $BAK_DIR
echo "The $BAK_DIR create success."
else
echo "The $BAK_DIR is exist. "
fi
# 进行备份操作
$MYSQLCMD -u$MYSQLUSER -p$MYSQLPW $MYSQLDB >$BAK_DIR/$MYSQLDB.sql
if [ $? -eq 0 ];then
echo -e "