MySQL automatically backs up the entire library script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.