MySQL备份脚本

MySQL备份脚本

#!/bin/bash
#auto leejm
#mysql backup sctipt
#20171010

BAK_DIR=/data/bakcup/`date +%Y%m%d`
MYSQL_USER=backup
MYSQL_PASSWD=123456
MYSQL_DB=mysql
MYSQL_CMD=/usr/bin/mysqldump

if [ $UID -ne 0 ];then
    echo -e "\033[32mMust to be user root for exec shell.\033[1m"
    exit
fi

if [ ! -d $BAK_DIR ];then
    mkdir -p $BAK_DIR
    echo -e "\033[32mThe $BAK_DIR is mkdir successful.\033[1m"
else
    echo -e "\033[32mThe $BAK_DIR is exists.\033[1m"
fi

#mysql backup command
$MYSQL_CMD -u $MYSQL_USER -p$MYSQL_PASSWD -d $MYSQL_DB >>$BAK_DIR/$MYSQL_DB.sql
if [ $? -eq 0 ];then
    echo -e "\033[32mThe mysql backup $MYSQL_DB is successful.\033[0m"
else
    echo -e "\033[32mMysql backup failed!\033[0m"
fi

 

 

你可能感兴趣的:(数据库)