#!/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