#Mysql备份脚本
#脚本说明
---------
This script defines the databases that need to be backed up according to different scenarios, and periodically deletes more than 30 days of data from the backup directory. The script is very simple, can take away the direct use, welcome colleagues to make comments. Thank you ~
#!/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"
This article is from the "You Insist" blog, please be sure to keep this source http://whlai51.blog.51cto.com/2164371/1739525
MySQL backup script