mydumper 特性

(1)多线程备份(和mysqlpump的多线程不同,mysqlpump多线程备份的粒度是表,mydumper多线程备份的粒度是行,这对于备份大表特别有用)
(2)因为是多线程逻辑备份,备份后会生成多个备份文件
(3)备份时对 MyISAM 表施加 FTWRL (FLUSH TABLES WITH READ LOCK), 会阻塞 DML 语句
(4)保证备份数据的一致性
(5)支持文件压缩
(6)支持导出binlog
(7)支持多线程恢复
(8)支持以守护进程模式工作,定时快照和连续二进制日志
(9)支持将备份文件切块

下载安装包
mydumper-0.9.1.tar.gz
安装依赖包:
yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel cmake
tar zxvf mydumper-0.9.1.tar.gz
cd mydumper-0.9.1
cmake .
make
make install

mydumper主要流程概括:

0、连接目标数据库
1、通过show processlist来判断是否有长查询,根据参数long-query-guard和kill-long-queries决定退出或杀掉长查询
2、主线程,针对MyISAM引擎表,FLUSH TABLES WITH READ LOCK, 施加全局只读锁,以阻止DML语句写入,保证数据的一致性
3、主线程,针对InnoDB引擎表,开启事务,start transaction,读取当前时间点的二进制日志文件名和日志写入的位置并记录在metadata文件中,以供即使点恢复使用
4、创建worker子线程,N个(线程数可以指定,默认是4)dump线程 START TRANSACTION WITH CONSISTENT SNAPSHOT; 开启读一致的事务
5、确定候选表,根据类别分别插入innodb_table,non_innodb_table以及table_schemas链表(表结构)
6、将候选表通过g_async_queue_push加入任务队列(队列最后元素是thread shutdown),由worker子线程从队列中读取表信息并执行数据导出
7、dump non-InnoDB tables, 首先导出非事务引擎的表
8、主线程 UNLOCK TABLES 非 事务引擎备份完后,释放全局只读锁
9、dump InnoDB tables, 基于 事务导出InnoDB表
10、事务结束
11、等待worker退出

mydumper使用--less-locking可以减少锁等待时间,此时mydumper的执行机制大致为
1、主线程 FLUSH TABLES WITH READ LOCK (全局锁)
2、Dump线程 START TRANSACTION WITH CONSISTENT SNAPSHOT;
3、LL Dump线程 LOCK TABLES non-InnoDB (线程内部锁)
4、主线程UNLOCK TABLES
5、LL Dump线程 dump non-InnoDB tables
6、LL DUmp线程 UNLOCK non-InnoDB
7、Dump线程 dump InnoDB tables

备份文件相关信息:

1、所有的备份文件在一个目录中,未指定时为当前目录,且自动生成备份日志时间文件夹,如export-20150703-145806
2、如果是在从库进行备份,还会记录备份时同步至主库的二进制日志文件及写入位置
3、每个表有两个备份文件:database.table-schema.sql表结构文件,database.table.sql表数据文件
4、如果对表文件分片,将生成多个备份数据文件,可以指定行数或指定大小分片

# mydumper --help
Usage:
  mydumper [OPTION...] multi-threaded MySQL dumping
Help Options:
  -?, --help                  Show help options
Application Options:
  -B, --database              Database to dump
  -T, --tables-list           Comma delimited table list to dump (does not exclude regex option)
  -o, --outputdir             Directory to output files to
  -s, --statement-size        Attempted size of INSERT statement in bytes, default 1000000
  -r, --rows                  Try to split tables into chunks of this many rows. This option turns off --chunk-filesize
  -F, --chunk-filesize        Split tables into chunks of this output file size. This value is in MB
  -c, --compress              Compress output files
  -e, --build-empty-files     Build dump files even if no data available from table
  -x, --regex                 Regular expression for 'db.table' matching
  -i, --ignore-engines        Comma delimited list of storage engines to ignore
  -m, --no-schemas            Do not dump table schemas with the data
  -d, --no-data               Do not dump table data
  -G, --triggers              Dump triggers
  -E, --events                Dump events
  -R, --routines              Dump stored procedures and functions
  -k, --no-locks              Do not execute the temporary shared read lock.  WARNING: This will cause inconsistent backups
  --less-locking              Minimize locking time on InnoDB tables.
  -l, --long-query-guard      Set long query timer in seconds, default 60
  -K, --kill-long-queries     Kill long running queries (instead of aborting)
  -D, --daemon                Enable daemon mode
  -I, --snapshot-interval     Interval between each dump snapshot (in minutes), requires --daemon, default 60
  -L, --logfile               Log file name to use, by default stdout is used
  --tz-utc                    SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones, defaults to on use --skip-tz-utc to disable.
  --skip-tz-utc              
  --use-savepoints            Use savepoints to reduce metadata locking issues, needs SUPER privilege
  --success-on-1146           Not increment error count and Warning instead of Critical in case of table doesn't exist
  --lock-all-tables           Use LOCK TABLE for all, instead of FTWRL
  -U, --updated-since         Use Update_time to dump only tables updated in the last U days
  --trx-consistency-only      Transactional consistency only
  -h, --host                  The host to connect to
  -u, --user                  Username with privileges to run the dump
  -p, --password              User password
  -P, --port                  TCP/IP port to connect to
  -S, --socket                UNIX domain socket file to use for connection
  -t, --threads               Number of threads to use, default 4
  -C, --compress-protocol     Use compression on the MySQL connection
  -V, --version               Show the program version and exit
  -v, --verbose               Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
 
# myloader --help
Usage:
  myloader [OPTION...] multi-threaded MySQL loader
Help Options:
  -?, --help                        Show help options
Application Options:
  -d, --directory                   Directory of the dump to import
  -q, --queries-per-transaction     Number of queries per transaction, default 1000
  -o, --overwrite-tables            Drop tables if they already exist
  -B, --database                    An alternative database to restore into
  -s, --source-db                   Database to restore
  -e, --enable-binlog               Enable binary logging of the restore data
  -h, --host                        The host to connect to
  -u, --user                        Username with privileges to run the dump
  -p, --password                    User password
  -P, --port                        TCP/IP port to connect to
  -S, --socket                      UNIX domain socket file to use for connection
  -t, --threads                     Number of threads to use, default 4
  -C, --compress-protocol           Use compression on the MySQL connection
  -V, --version                     Show the program version and exit
  -v, --verbose                     Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
 
备份 test 库到 /tmp/backup/01 文件夹中,并压缩备份文件 
mydumper -u dba_user -p msds007 -h 192.168.1.101 -P 3306 -B mytest -c -o /tmp/backup/01 
备份所有数据库,备份至 /tmp/backup/02 文件夹 
mydumper -u root -p msds007 -h 192.168.1.101 -P 3306 -o /tmp/backup/02 
 
备份 test.wx_edu_homework 表,且不备份表结构,备份至 /tmp/backup/03 文件夹 
mydumper -u root -p msds007 -h 127.0.0.1 -P 3306 -B test -T wx_edu_homework -m -o /tmp/backup/03
恢复test库,如果恢复的表存在则先删除 
myloader -u dba_user -p msds007 -h 192.168.1.101 -P 3306 -e -o -d /tmp/backup/01
-e参数会把恢复数据时的SQL写进binlog
 

打开general log执行

mydumper -u root -p msds007 -h 192.168.1.101 -P 3306 -o /tmp/backup/02

myloader -u dba_user -p msds007 -h 192.168.1.101 -P 3306 -e -o -d /tmp/backup/01

看general log的详细信息

 

原理图

mydumper和mysqldump原理类似,最大的区别在于多线程复制。并发的粒度可以到行级别,还是通过线程分别调用FTWRL并获取一致性点位。

mydumper,myloader原理及实战的更多相关文章

  1. myloader原理0

    开源MySQL多线程逻辑导入工具myloader原理与改进 在上一篇中,介绍了多线程备份工具mydumper的实现及网易对其所做的优化,本篇聊聊与mydumper配合使用的myloader工具. my ...

  2. MYSQL mydumper & myloader

    第三方逻辑备份工具myduper和myloader | xiaoyu的数据库小窝-技术交流http://www.dbaxiaoyu.com/archives/1643 myloader原理0 - ze ...

  3. mydumper/myloader使用详解

      mydumper安装:http://www.cnblogs.com/lizhi221/p/7010174.html mydumper原理:http://www.cnblogs.com/lizhi2 ...

  4. jQuery源码:从原理到实战

    jQuery源码:从原理到实战 jQuery选择器对象 $(".my-class"); document.querySelectorAll*".my-class" ...

  5. Keepalived原理与实战精讲--VRRP协议

    . 前言 VRRP(Virtual Router Redundancy Protocol)协议是用于实现路由器冗余的协议,最新协议在RFC3768中定义,原来的定义RFC2338被废除,新协议相对还简 ...

  6. Spark MLlib特征处理:OneHotEncoder OneHot编码 ---原理及实战

    http://m.blog.csdn.net/wangpei1949/article/details/53140372 Spark MLlib特征处理:OneHotEncoder OneHot编码 - ...

  7. Istio 流量治理功能原理与实战

    一.负载均衡算法原理与实战 负载均衡算法(load balancing algorithm),定义了几种基本的流量分发方式,在Istio中共有4种标准负载均衡算法. •Round_Robin: 轮询算 ...

  8. Oracle特殊恢复原理与实战(DSI系列)

    1.深入浅出Oracle(DSI系列Ⅰ) 2.Oracle特殊恢复原理与实战(DSI系列Ⅱ) 3.Oracle SQL Tuning(DSI系列Ⅲ)即将开设 4.Oracle DB Performan ...

  9. Java并发编程原理与实战五:创建线程的多种方式

    一.继承Thread类 public class Demo1 extends Thread { public Demo1(String name) { super(name); } @Override ...

随机推荐

  1. ie和vuex的兼容

    vuex requires a Promise polyfill in this browser. 在ie中的报错 需要安卓babel-polyfill,  然后在webpack.base.confi ...

  2. HDU 2859 Phalanx ——(DP)

    感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...

  3. jQuery源代码学习之十——动画Animate

    一.Animate模块的代码结构 // 定义了一些变量 tweeners = {}; function createFxNow() {} function createTween() {} funct ...

  4. windows环境下启动mongodb服务

    方法一1.打开命令窗口,切换到mongodb安装目录下的“bin”目录中. 输入命令:cd E:\software\MongoDB\Server\3.4\bin 2.启动服务.输入命令:”mongod ...

  5. docker-compose ELK+Filebeat查看docker及容器的日志

    我目前所在公司开发团队比较小,为集团下面的工厂开发了一套小的系统,跑在一台CentOS服务器上,服务器搭建了docker环境,安装了docker-compose,但在日志处理方面,暂时没有一个好的方法 ...

  6. Linux ubuntu centos 下 grep显示前后几行信息

    标准unix/linux下的grep通过下面参数控制上下文 grep -C 5 foo file 显示file文件里匹配foo字串那行以及上下5行grep -B 5 foo file 显示foo及前5 ...

  7. Flutter移动电商实战 --(21)分类页_类别信息接口调试

    先解决一个坑 取消上面的GridVIew的回弹效果.就是在拖这个gridview的时候有一个滚动的效果 physics: NeverScrollableScrollPhysics(), 大R刷新后,点 ...

  8. UML期末复习题——2.6:Package Diagram

    第六题 包图 重要概念: 1.包图(package Diagram) 由若干个包以及包之间的关系组成.包是一种分组机制,其将一些相关的类集合为一个包,形成高内聚,低耦合的类集合,可以说,一个包相当于一 ...

  9. VUE数组操作方法的局限

    1.不能通过索引值直接设置一个项: vm.items[indexOfItem] = newValue 但是可以用set方法设置: Vue.set(example1.items,indexOfItem, ...

  10. Android:动态库(.so)调试技巧

    一.反汇编定位crash ①查看crash log: 上图已标出crash发生在 libdeflicker_gpu.so 库中的 default_fail_func() 函数,但是 libdeflic ...