MySQL incremental backup binary log shell script

Source: Internet
Author: User

#!/bin/bash#? date:2017-10#? Description:backup?mysql?binary?logs#? version:0.1db_user= "root" myisam_db= "MySQL" db_passwd= "123456" host= "localhost" export? Path= "/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" backup_dir= " /opt/backup/mysql/bin "log_file="/opt/backup/mysql/bin/bin_log_file.log "bin_index="/mydata/data/mysql-bin.index "Data_dir="/mydata/data "mysql=" $ (which?mysql) "$mysql?-u$db_user?-h$host?-p$db_passwd?-e?" Flush?logs "num=$ (awk?) End{print? NR} '? $bin _index) counter=0start_time=$ (date?+ "%f?%h:%m:%s") [?!? -d? $backup _dir?]? &&?mkdir?-p? $backup _dir[?!? F. $log _file?]? &&?touch? $log _fileecho? " Starting?backup?mysql?binary?logs?at? $start _time "?>> $log _filefor?file?in? ' Cat? $bin _index ' do?? Base= ' basename? $file '?? counter=$ (expr $counter? +?1)?? If? [$counter?-eq $num?]; Then???? Echo? " Skip $base "?>> $log _file?? else???? If? [?!? -F $backup _dir/$base?]; Then?????? Cp?-a $data _dir/$base $backup _dir?2>> $log _file?????? If? [?$?? -eq?0?]; Then???????? Echo? " Backup $base? Successfully "?>> $log _file?????? else???????? Echo? " Backup $base? Failed "?>> $log _file???????? Echo? " Backup? $base to $backup _dir?failed "|mail?-s?" Mysql?binary?logs?backup?failed "[email protected]?????? Fi???? Fi?? fidonestop_time=$ (date?+ "%f?%h:%m:%s") echo? " End?backup?mysql?binary?logs?at? $stop _time "?>> $log _fileecho?"? >> $log _fileexit?0


MySQL incremental backup binary log shell 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.