标签:mysql
#Mysql备份脚本
#脚本说明
---------
此脚本可根据不同场景,定义需要备份的数据库,并定期删除备份目录中超过30天的数据。脚本很简单,可拿走直接使用,欢迎各位同仁提出意见。谢谢~
#!/bin/bash
#auto backup mysql scripts
#by wanghl 2016-01-28
#define path
M_USER=root
M_PASS=11111111
M_HOST=localhost
M_DB=cloud
M_BACK_DIR=/data/mysql/backup/
M_DIR_TIME=`date +%Y-%m-%d`
#Check User
if [ $UID -ne -0 ];then
echo -e "\033[32mplease use root."
exit 0
fi
#Check Backup Dir
if [ ! -d $M_BACK_DIR ];then
mkdir -p $M_BACK_DIR
echo "Dir create success."
fi
#Backup CMD
/usr/bin/mysqldump -h$M_HOST -u$M_USER -p$M_PASS $M_DB > $M_BACK_DIR/cloud_$M_DIR_TIME.sql
if [ $? -eq 0 ];then
echo -e "\033[32m$M_DB backup success.........\033[0m"
else
echo -e "\033[32mplease check it.\033[0m"
fi
#Check DIR Time
echo -e "\033[32m----------------------------\033[1m"
cd $M_BACK_DIR ; find -mtime +30 -exec rm -rf {} \;
echo $M_DB DIR:$M_BACK_DIR
echo -e "\033[32m----------------------------\033[0m"
本文出自 “贵在坚持” 博客,请务必保留此出处http://whlai51.blog.51cto.com/2164371/1739525
标签:mysql
原文地址:http://whlai51.blog.51cto.com/2164371/1739525