标签:mysql自动备份脚本
自动备份数据库脚本
#!/bin/bash
#auto bakcup mysql
#by 2015-7-2
BAK_DIR="/data/backup/`date +%Y%m%d`"
MYSQL_DB=discuz
MYSQL_USER=root
MYSQL_PW=123456
MYSQL_CMD=/usr/bin/mysqldump
if [ $UID -ne 0 ]; then
echo "Must to be use root for run shell.."
exit
fi
if [ ! -d "$BAK_DAR" ]; then
mkdir -p $BAK_DIR
echo -e "\033[32mthe $BAK_DIR is create successfully\033[0m"
else
echo "this $BAK_DIR is exists......"
fi
#mysql backup commend
$MYSQL_CMD -u$MYSQL_USER -p$MYSQL_PW $MYSQL_DB>$BAK_DIR/$MYSQL_DB.sql
if [ $? -eq 0 ] ; then
echo -e "\033[32mthe mysql $MYSQL_DB is backup successfully\033[0m"
else
echo -e "\033[32mthe mysql $MYSQL_DB is backup failed,please check\033[0m"
fi
本文出自 “毛毛鸭” 博客,请务必保留此出处http://woshitieren.blog.51cto.com/2466034/1670336
标签:mysql自动备份脚本
原文地址:http://woshitieren.blog.51cto.com/2466034/1670336