【MySQL】【备份】mydumper安装与使用细节
admin
2023-05-08 17:02:06
0次

mydumper

简介:

由percona公司的Max Bubenick与facebook公司的Domas Mituzas共同维护开发,也是个10年历史的工具了,
与同为逻辑备份的mysqldump工具而言,其特性在于多线程并行备份,与官方同类型的mysqlpump相比,其优点
在于一张表可以分到好几个线程上进行备份。

安装:

很多博客都推荐使用编译的方式进行安装 ,在这里点一下坑,由于mydumper依赖了 glib2-devel 
mysql-devel zlib-devel pcre-devel openssl-devel等第三方库,而这些库之前并没有按系统默认方式安装
到各个默认位置,那么将会产生编译安装的连锁指定编译位置的问题。我在Cent7系统上安装时,就遇到
很多编译不通过或者编译后使用报错的问题,检查环境后发现系统运维的同事使用编译安装的方式安装了
MySQL 5.6与pcre库。后面我尝试使用yum安装库后,还是无法排除问题。

 在这里我推荐使用开发者编译好的rpm包进行安装,配合yum可以自动补齐依赖,避免很多坑。

 地址:https://github.com/maxbube/mydumper/releases,请根据自己的系统类型选择下载版本。

`yum -y install https://github.com/maxbube/mydumper/releases/download/v0.9.3/mydumper-0.9.3-41.el7.x86_64.rpm`

使用:

$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
  -W, --no-views              Do not dump VIEWs
  -k, --no-locks              Do not execute the temporary shared read lock.  WARNING: This will cause inconsistent backups
  --no-backup-locks           Do not use Percona backup locks
  --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
  --complete-insert           Use complete INSERT statements that include column names
  -h, --host                  The host to connect to
  -u, --user                  Username with the necessary privileges
  -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
  --defaults-file             Use a specific defaults file

这里给出我最常用的备份方式:

mydumper -h 192.168.1.109 -P 3109 -u root -p 123456 -G -E -R -t 4 -c -o /data/bak/mysql/3109

说明:-h 指定地址

   -P 指定备份端口

   -u 指定备份用户

   -p 密码

   -G 备份触发器

   -E  备份定时事件

   -R  备份存储过程和函数

   -t  备份时并发的线程数(不包含备份主线程)

       -c  对备份文件进行压缩(gz方式)

   -o  指定备份存储位置

原理与过程:

与mysqldump工具类似,先FTWRL(flush table with read lock),查询自己本身的事务执行位置(show 
master status),然后开启一个一致性快照事务,再启动若干个子线程分别开启一致性可重复读快照事务,
使用子线程开启事务并读取数据和视图,函数,存储过程,定时事件等。由于实例中可能有非事务型表的
存在,为保持一致性,待各个子线程全部备份完非事务型的表后才会释放FTWRL。

这里重点说明下`--trx-consistency-only`参数,很多博客都是粗粗点过甚至不翻译。上一步中我们说到
mydumper为了获取整个实例级别的一致性备份,会在开始备份时加上FTWRL,待各个线程都备份完非事务
表后,才会释放FTWRL。这是考虑到5.7及之前的版本中mysql库的部分表是MyISAM引擎,不具备事务特
性,或者业务上还存在非事务表。但8.0之后的版本中mysql库全部改成了InnoDB引擎,或者用户选择不备
份mysql库,或者实例中一张非事务表都没有,这时mydumper会在创建完所有子线程并分别开启一致性可
重复读快照事务后就释放FTWRL.因为这个时候根据事务特性已经可以保证备份一致了。

若你确定没有备份非事务型表,或者没有备份mysql库,或者实例中非事务表的一致性无关紧要,在你非常
介意备份时加的读锁对业务造成的影响的话,可以考虑加上`--trx-consistency-only`参数强制在创建完备的
子线程后就释放锁,减小备份对业务造成的写堵塞

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...