The script supports automatic backup, automatically upload to FTP server, backup failed to send alert message automatically
#!/bin/sh#create by jianglei. yu on 20160421# the use of test scripts requires the installation of the Mutt Mail sending tool. #使用使用自动化安装. For more information, please refer to http://yujianglei.blog.51cto.com/7215578/1765938#define mysql environmentshostname= ' 192.168.0.141 ' port= ' 3306 ' username= ' root ' password= ' 123456 ' mysqldump=$ (which mysqldump) gzip=$ (which gzip) destinaion_dir= '/home/bak/database/data ' timestamp=$ (date +%y%m%d%h%m%s) database= ' virtual ' Alarm_User= "[email protected]" file_name= "$Timestamp-$Database. sql.gz" #File_Name = "20160421110453-virtualsdk.sql.gz" # define ftp environmentsftp_host= ' 192.168.0.136 ' ftp_port= ' ftp_user= ' yujianglei ' Ftp_Pass= ' Yujianglei ' rpm=$ (which rpm) function check_result () { if [ $? != 0 ];then echo "Backup database failed" | mutt -s "$Database backup&Nbsp;database failed " ${Alarm_User} exit 1 else echo "Backup database successful " | mutt -s " $Database backup database successful " ${Alarm_User} fi}function bakcup () { [ ! -d ${ Destinaion_dir} ] && mkdir -p ${destinaion_dir} cmd= "$ Mysqldump -h$hostname -p$port -u$username -p$password " parameter="- -flush-privileges --opt -r -e --triggers --single-transaction -f " $CMD $Parameter $Database | gzip >${Destinaion_dir}/${File_Name} Check_result $?} Function upload_ftp () { $RPM -q ftp [ $? != 0 ] && yum install ftp -y ftp -n ${ftp_host} ${ftp_port} << end user ${ ftp_user} $FTP _pass lcd ${destinaion_dir} cd database put ${File_Name} quitEND check_result $? exit 0}bakcupupload_ftp
This article from the "Do not ask for the best, only better" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1766182
MySQL automatically backs up the entire library script