#!/bin/sh
#备份主机
remote_ip=10.2.142.161
Master_ip=10.2.142.148
VIP=103.2.132.136
#备份用户
user='root'
#密码
password='123456'
# 返回年月日
backup_date=`date +%F`
# 返回时分秒
backup_time=`date +%H-%M-%S`
# 返回今天是这周的第几天
backup_week_day=`date +%u`
backup_ok=0
#备份目录
socket=/data/mysql/mysql.sock
# 备份路径
backup_dir=/data/xtrabackup
backup_dir_local=/data/xtrabackup_local
# 数据目录
datadir=/data/mysql
# percona-xtrabackup 备份软件路径
xtrabackup_dir=/usr/bin
# 全备是在一周的第几天
full_backup_week_day=6
#周期性全量增量开始日期# 全量备信息名称前缀
full_backup_prefix=full
# 增量备信息名称前缀
increment_prefix=incr
# mysql配置文件
mysql_conf_file=/etc/my.cnfcycle=$backup_date
cycle_record=$backup_dir/cycle_record.txtif [ ! -f $backup_dir/cycle_record.txt ];thenindex=$backup_date
elseif [ "$full_backup_week_day" -eq `date +%u` ]; thenindex=$backup_dateelseindex=`cat $backup_dir/cycle_record.txt`fi
fi
index_file=$backup_dir/backup_$index.index
index_file_local=$backup_dir_local/backup_$index.indexlog_dir=$backup_dir/log
if [ ! -d "$backup_dir" ];thenmkdir -p $backup_dir
fi
if [ ! -d "$backup_dir_local" ];thenmkdir -p $backup_dir_local
fi
if [ ! -d "$log_dir" ];thenmkdir -p $log_dir
fifunction append_index_to_file() {echo "{week_day:$backup_week_day, \dir:${1}_${backup_date}_${backup_time}_${backup_week_day}, \type:${1}, \date:${backup_date}}" >> $index_file
}
function append_index_to_file_local() {echo "{week_day:$backup_week_day, \dir:${1}_${backup_date}_${backup_time}_${backup_week_day}, \type:${1}, \date:${backup_date}}" >> $index_file_local
}
# 判断是应该全备还是增量备份
# 0:full, 1:incr
function get_backup_type() {full_backup_week_day=$full_backup_week_daybackup_type=0if [ ! -f "$index_file" ]; thentouch "$index_file"fiif [ "$full_backup_week_day" -eq `date +%u` ]; thenbackup_type=0elsebackup_type=1fiif [ ! -n "`cat $index_file`" ]; thenbackup_type=0fireturn $backup_type
}
#推送远程全量备份
function full_backup (){backup_folder=${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day}if [ ! -d $backup_dir_local/$cycle/ ]; thenmkdir $backup_dir/$cycle/fiecho $cycle>$backup_dir/cycle_record.txtssh $user@$remote_ip  "if [ ! -d $backup_dir/$cycle/ ];then mkdir -p $backup_dir/$cycle; fi "innobackupex --defaults-file=$mysql_conf_file --no-timestamp --user=$user \--password=$password --host=${VIP} --port=3306 --extra-lsndir=$backup_dir/$cycle/$backup_folder  --compress \--stream=xbstream $backup_dir  | ssh $user@$remote_ip  "gzip ->$backup_dir/$cycle/$backup_folder.tar.gz" if [ $? -eq 0 ];thenappend_index_to_file  $full_backup_prefixlog_info 0 fullelselog_info 1 fullfi
}#推送远程增量备份{week_day:1,dir:full/incr_2015-12-29_00-00-00_7,type:full/incr}
incremental (){backup_folder=${increment_prefix}_${backup_date}_${backup_time}_${backup_week_day}incr_record=`cat $backup_dir/cycle_record.txt`echo $backup_dir/$incr_record#cd $backup_dir/$incr_recordincr_base_folder=`sed -n '$p' $index_file | \awk -F '[, {}]*' '{print $3}' | \awk -F ':' '{print $2}'`echo $backup_dir/$incr_record/${incr_base_folder}innobackupex --defaults-file=$mysql_conf_file \--no-timestamp --user=$user --password=$password --host=${VIP} --port=3306  \--stream=xbstream --compress --extra-lsndir=$backup_dir/$incr_record/$backup_folder \--incremental backup_folder --incremental-basedir=$backup_dir/$incr_record/${incr_base_folder} \|ssh $user@$remote_ip  "gzip ->$backup_dir/$incr_record/$backup_folder.tar.gz" \if [ $? -eq 0 ];thenlog_info 0 incrappend_index_to_file  $increment_prefixelselog_info 1 incrfi
}function full_backup_local (){backup_folder=${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day}if [ ! -d $backup_dir_local/$cycle/ ]; thenmkdir $backup_dir_local/$cycle/fiecho $cycle>$backup_dir_local/cycle_record.txtinnobackupex --defaults-file=$mysql_conf_file --no-timestamp --user=$user \--password=$password --host=${VIP} --port=3306 $backup_dir_local/$cycle/$backup_folderif [ $? -eq 0 ];thenecho "全量备份成功"append_index_to_file_local  $full_backup_prefixlog_info_local 0 fullelselog_info_local 1 fullfi
}#本地增量备份{week_day:1,dir:full/incr_2015-12-29_00-00-00_7,type:full/incr}
incremental_local (){backup_folder=${increment_prefix}_${backup_date}_${backup_time}_${backup_week_day}incr_record=`cat $backup_dir_local/cycle_record.txt`echo $backup_dir_local/$incr_record#cd $backup_dir/$incr_recordincr_base_folder=`sed -n '$p' $index_file_local | \awk -F '[, {}]*' '{print $3}' | \awk -F ':' '{print $2}'`echo  $incr_base_folderecho $backup_dir_local/$incr_record/${incr_base_folder}innobackupex --defaults-file=$mysql_conf_file \--no-timestamp --user=$user --password=$password --host=${VIP} --port=3306  \--incremental $backup_dir_local/$incr_record/$backup_folder --incremental-basedir=$backup_dir_local/$incr_record/$incr_base_folder   if [ $? -eq 0 ];thenlog_info_local 0 incrappend_index_to_file_local  $increment_prefixelselog_info_local 1 incrfi
}
function log_info (){
if [[ "$1" = "0" ]];thenif [ "$2" = "full" ];thenecho "全量备份成功" >$backup_dir/successelseecho "增量备份成功" >$backup_dir/failfi
elseif [ "$2" = "full" ];thenecho "全量备份失败" >$backup_dir/successelseecho "增量备份失败" >$backup_dir/failfi
fi
}
function log_info_local ()
{
echo "全量备份成功"
if [[ "$1" = "0" ]];thenif [ "$2" = "full" ];thenecho "全量备份成功" >$backup_dir/successelseecho "增量备份成功" >$backup_dir/failfi
elseif [ "$2" = "full" ];thenecho "全量备份失败" >$backup_dir/successelseecho "增量备份失败" >$backup_dir/failfi
fi
}
function run_auto() {get_backup_typebackup_type=$?echo $backup_typecase $backup_type in0)full_backup              ;;1)incremental               ;;*)echo "Please  use it this way. Usage:$0 {0|1}";;esac
}
function run_manual() {case $1 infull)full_backup;;incremental)incremental;;*)echo "Please  use it this way. Usage:$0 {Full|incremental}";;esac
}
function run_auto_local() {get_backup_typebackup_type=$?case backup_type in0)full_backup_local;;1)incremental_local;;*)echo "Please  use it this way. Usage:$0 {Full|incremental}";;esac
}
function run_manual_local() {#echo $1case $1 infull)full_backup_local;;incremental)incremental_local;;*)echo "Please  use it this way. Usage:$0 {full|incremental}";;esac
}
run_auto
#run_auto_local
#run_manual_local $1
#run_manual $1
What’s the problem with FTWRL anyway?
A lot has been written on what FLUSH TABLES WITH READ LOCK really does. Here’s yet another walk-through in a bit more detail than described elsewhere:It first invalidates the Query Cache.
It then waits for all in-flight updates to complete and at the same time it blocks all incoming updates. This is one problem for busy servers.
It then closes all open tables (the FLUSH part) and expels them from the table cache. This is also whenFTWRL has to wait for all SELECT queries to complete. And this is another, even bigger problem for busy servers, because that wait happens to occur with all updates blocked. What’s even worse, the server at this stage is essentially offline, because even incoming SELECT queries will get blocked.
Finally, it blocks COMMITs.
1.它首先使查询缓存无效。
2.然后,等待所有更新完成,并在同一时间,它阻止所有的更新。这对于繁忙的服务器是一个问题。
3.然后,它关闭所有打开的表(冲洗表)并且从表中的高速缓存刷出。这也是当FTWRL必须等待所有的SELECT查询完成。这是另一个更大的问题为繁忙的服务器,因为等待恰好发生这将堵塞所有的更新。更糟的是,服务器在这个阶段基本上是离线状态,因为即使进入的SELECT查询将被封锁。
4.最后,它会阻止事务提交。Percona已经提供了解决方案(2.1版本开始):设置一个超时时间,避免无限期的等待。Xtrabackup提供了以下参数实现该功能:--lock-wait-timeout=SECONDS, ,一旦Flush table with read lock被阻塞超过预定时间,则XtraBackup出错返回退出,该值默认为0,也就是说一旦阻塞,立即返回失败。
--lock-wait-query-type=all|update,该参数允许用户指定,哪类的SQL语句是需要Flush table with read lock等待的,同时用户可以通过--lock-wait-threshold=SECONDS设置等待的时间,如果不在query-type指定的类型范围内或者超过了wait-threshold指定的时间,XtraBackup均返回错误。如果指定update类型,则UPDATE/ALTER/REPLACE/INSERT 均会等待,ALL表示所有的SQL语句。kill 其他阻塞线程
Kill掉所有阻塞Flush table with read lock的线程:
--kill-long-queries-timeout=SECONDS参数允许用户指定了超过该阈值时间的查询会被Kill,同时也允许用户指定KillSQL语句的类型。
--kill-long-query-type=all|select
默认值为ALL,如果选择Select,只有Select语句会被Kill,如果Flush table with read lock是被Update语句阻塞,则XtraBackup不会处理。

innobackupex远程备份脚本相关推荐

  1. innobackupex自动备份脚本

    2019独角兽企业重金招聘Python工程师标准>>> 全量备份脚本 #!/bin/bashfulldir=/mysql/full/`date "+%Y-%m-%d&quo ...

  2. mysql 自动热备份_mysql(mariadb)定时自动热备份+增量+远程备份脚本

    优点:热备份,不影响业务,增量备份,远程备份. 目的:自动打包备份到远程10.0.0.111备份服务器 前提: 1.安装xtrabackup yum install http://www.percon ...

  3. XtraBackup/innobackupex 远程备份MySQL

    XtraBackup2.2 暂时不支持最新的mysql-5.7 远程备份方法来源https://www.percona.com/forums/questions-discussions/percona ...

  4. 手把手教你实现Gitlab远程备份(超详细,图文并茂)

    为防止服务器的磁盘损坏数据无法取出,因此我们得做好代码的备份工作,因此除了每天在Gitlab那台服务器上自动备份之外,还需要将每天的备份文件copy到另外一台文件备份服务器上,已达到双保险的要求. 1 ...

  5. linux 远程备份mysql数据库_使用脚本自动化远程备份MySQL数据库

    通常情况下.MySQL都需要备份,备份的方法有很多种.下面是我用脚本配合计划任务完成的自动备份远程的数据库. 一. 确认备份方案: 备份机:ip192.168.8.51 数据库服务器:ip192.16 ...

  6. LinuxShell脚本之利用rsync+ssh实现Linux文件系统远程备份

    功能介绍: 该脚本用于定期(结合crontab一起使用)将本地目录通过rsync+ssh传输到远程服务器,每次执行都生成一个带有以时间命名的目录,并且当前最新版本的数据链接到一个名字叫current的 ...

  7. vestacp 远程mysql_vestacp面板远程ftp备份脚本 | 叽叽歪歪

    vestacp面板是俄罗斯人开发的一个免费的vps控制面板,我使用了近一个月,感觉还不错.它提供了自动备份数据功能,但仅限于备份到vps上,为了保险,我们需要把数据也备份到远程空间上,于是就有了这个脚 ...

  8. mysql 集群备份脚本_MysqlBackup

    #MYSQL 多方式备份脚本 简单介绍 xtrabackupex: 200G数据:在线1小时备份并完成恢复,innodb不锁表 mydumper: 多线程备份,会锁表,备份快,恢复慢 mysqldum ...

  9. mysql用sql语句怎么做个脚本备份_mysql备份脚本

    一.介绍两种日志 1.redo log是InnoDB存储引擎层的日志,又称重做日志文件,用于记录事务操作的变化,记录的是数据修改之后的值,不管事务是否提交都会记录下来.在实例和介质失败(media f ...

最新文章

  1. php删除空标签_PHP如何去除Html所有标签、空格以及空白
  2. [AI开发]目标跟踪之行为分析
  3. codesmith学习总结
  4. Android学习笔记-----一个很好用的搜索网站,你懂的
  5. PHP服务器环境打开配置文件
  6. Jarvis OJ web(一)
  7. Mybatis generator 1.4.x 入门教程--转载
  8. JMS学习(3):--ActiveMQ简单的HelloWorld实例
  9. 同一网段计算机无法共享打印机,Win7同一个局域网内共享打印机不成功的修复方法...
  10. Qt文档阅读笔记-对JSON Save Game官方实例解析
  11. 关于计算机组件游戏,Windows系统运行库/游戏运行库组件怎么补全?
  12. 戴尔电脑安装win 7
  13. Mysql及SQLyog安装教程
  14. 鲜花销售管理系统jsp全部代码_基于Java的鲜花销售管理系统设计与实现.zip
  15. uniapp MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 upgrade listeners
  16. LSM树 Log-Structured Merge Tree
  17. B2B从销售到深度协作
  18. Python包装网页微信API并实现简单自动回复
  19. 台式安装nas系统_从0开始使用“矿渣”低成本打造家庭NAS,黑群晖系统安装(中)...
  20. Python datetime.datetime.isoweekday和date.weekday()

热门文章

  1. python制作远程桌面控制_Python 远程桌面协议RDPY简介
  2. python安装pyserial模块_Python使用模块Pyserial模块报
  3. Python oct 函数 - Python零基础入门教程
  4. Python min 函数 - Python零基础入门教程
  5. jq之$(“p:first“)
  6. jenkins 手动执行_Jenkins Git client插件命令执行漏洞(CVE201910392)
  7. mysql 换服务器_更换MYSQL后数据库连接问题
  8. layer中嵌套的页面如何操作父页面_vue中8种组件通信方式,值得收藏
  9. python操作json字符串,超详细的Python文件操作知识
  10. 苹果电脑更改sd卡只读_SD卡变为只读系统