下文主要给大家带来使用二进制日志shell脚本该如何增量备份mysql,希望这些内容能够带给大家实际用处,这也是我编辑使用二进制日志shell脚本该如何增量备份mysql这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。
#!/bin/bash # Date:2017-10 # Description:backup mysql binary logs # Version:0.1 db_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=0 start_time=$(date +"%F %H:%M:%S") [ ! -d $backup_dir ] && mkdir -p $backup_dir [ ! -f $log_file ] && touch $log_file echo "Starting backup mysql binary logs at $start_time" >>$log_file for 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" root@localhost fi fi fi done stop_time=$(date +"%F %H:%M:%S") echo "End backup mysql binary logs at $stop_time" >>$log_file echo " " >>$log_file exit 0
对于以上关于使用二进制日志shell脚本该如何增量备份mysql,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。