#!/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
mysql增量备份二进制日志shell脚本
原创
©著作权归作者所有:来自51CTO博客作者zzjiwang的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
shell脚本--自动备份应用日志
shell脚本--自动备份应用日志
shell 日志备份