mysqldump+binlog备份脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysqldump+binlog备份脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3200字,纯文字阅读大概需要5分钟。
内容图文
![mysqldump+binlog备份脚本](/upload/InfoBanner/zyjiaocheng/898/0e9420834e7f49ca8814706de291ee1c.jpg)
## 注意 各种目录创建及相关参数设置
## 设置 /root/dba/binlog_control.txt,记录binlog文件时间,获取时间命令:stat -c %y mysql_mmm_01-bin.000013
## 设置 /root/dba/fullbak_file.txt,记录全备目录,第一次执行时,需设置一个目录来存放备份前产生的binlog,之后每次全备会自动更新该文件
---------------------------full_backup:mysql_full_backup.sh----------------------------------------
#!/bin/bash
#mysql param
user="root"
passwd="123456"
socket="/data/mysql/run/mysql.sock"
port=3306
bk_options="--single-transaction --flush-logs -u$user -p$passwd --master-data=2 --all-databases --socket=$socket --port=$port"
#log file
dtime=`date +%Y%m%d%H%M%S`
log_base="/root/dba/logs"
log_file="$log_base/full_backup_${dtime}.log"
#control file
contr_file="/root/dba/binlog_control.txt"
fullbak_file="/root/dba/fullbak_file.txt"
#full backup dir
bk_dir_suffix=`date +%Y%m%d`
full_dir="/backup/mysql_bak/mysql_$bk_dir_suffix"
[ -d ${full_dir} ] || mkdir -p ${full_dir}
echo "mkdir full backup dir : $full_dir" >> $log_file
#full backup file
full_bk_file="mysql_full_$bk_dir_suffix.sql"
#mysqldump
cd $full_dir
mysqldump $bk_options > $full_bk_file
echo "full backup file : $full_bk_file" >> $log_file
#backup flush logs--binlog to previous full backup
/root/dba/mysql_binlog_backup_new.sh
#update fullbak_file control file
echo $full_dir > $fullbak_file
---------------------------binlog_backup:mysql_binlog_backup_new.sh-------------------------------------------------------
#!/bin/bash
#mysql
user="root"
passwd="123456"
socket="/data/mysql/run/mysql.sock"
port=3306
#log file
dtime=`date +%Y%m%d%H%M%S`
log_base="/root/dba/logs"
log_file="$log_base/binlog_backup_${dtime}.log"
#control file
contr_file="/root/dba/binlog_control.txt"
fullbak_file="/root/dba/fullbak_file.txt"
#binlog path
binlog_path="/data/mysql/binlog/"
#binlog file format
binlog_format="mysql_mmm_01-bin.*[0-9]*"
#binlog backup dir
dest_dir=`cat $fullbak_file`
#current binlog
curr_binlog=`mysql -u$user -p$passwd --socket=$socket --port=$port -e 'show master status\G'|grep "File"|awk '{print $2}'`
echo "Current binlog : $curr_binlog">>$log_file
#current binglog file time
currbinlog_time=`stat -c %y $binlog_path$curr_binlog`
echo "Current binlog time : $currbinlog_time">>$log_file
#lastest backup binlog file time
previous_time=`cat $contr_file`
echo "Previous time : $previous_time">>$log_file
# ! -name "*$curr_binlog*" exclude current binglog
bk_count=`find -L $binlog_path -name "$binlog_format" ! -name "*$curr_binlog*" -newermt "$previous_time" ! -newermt "$currbinlog_time"|wc -l`
echo "backup files count : $bk_count">>$log_file
if [ $bk_count -gt 0 ];then
find -L $binlog_path -name "$binlog_format" ! -name "*$curr_binlog*" -newermt "$previous_time" ! -newermt "$currbinlog_time"|xargs ls -t>>$log_file
#find the newest bakup file
last_file=`find -L $binlog_path -name "$binlog_format" ! -name "*$curr_binlog*" -newermt "$previous_time" ! -newermt "$currbinlog_time"|xargs ls -t|head -n 1`
#newest backup file time
last_file_time=`stat -c %y $last_file`
echo $last_file_time > $contr_file
#cp files
find -L $binlog_path -name "$binlog_format" ! -name "*$curr_binlog*" -newermt "$previous_time" ! -newermt "$currbinlog_time" -exec cp {} $dest_dir \;
fi
find $log_base -mtime +15 -exec rm -f {} \;
内容总结
以上是互联网集市为您收集整理的mysqldump+binlog备份脚本全部内容,希望文章能够帮你解决mysqldump+binlog备份脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。