How to incrementally back up mysql using the binary log shell script
The following mainly brings you how to incrementally back up mysql using the binary log shell script. I hope this content can bring you practical use, which is also the main purpose of my article on how to incrementally back up mysql using the binary log shell script. All right, don't talk too much nonsense, let's just read the following.
#! / bin/bash# Date:2017-1 "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_fileecho "Backup $base to $backup_dir failed" | mail-s "MySQL binary logs backup failed" root@localhost fi fi fidonestop_time=$ (date + "% F% H:%M:%S") echo "End backup mysql binary logs at $stop_time" > > $log_fileecho "> > $log_fileexit 0
Do you find it very helpful to use the binary log shell script to back up mysql incrementally? If you need to know more, please continue to follow our industry information. I'm sure you'll like it.