mydumper/myloader使用详解

 
 
 
一、mydumper备份
 
1、开启16个备份进程,备份出所有的库以及二进制日志文件,到指定目录/docker/mydumper/all_backup
mydumper -u root -p root123 --threads=16 -o /docker/mydumper/all_backup
这里的--threads=16指定开启16个备份线程数,这个可以在MySQL里面show processlist看出来。
备份完成后,每个表都会有两个文件:
一个是表结构文件database.table-schema.sql;
一个是表数据文件database.table.sql。
此外还有一次二进制日志文件metadata。
$ cat metadata
Started dump at: 2017-06-15 10:57:24
SHOW MASTER STATUS:
    Log: mysql-bin.000025
    Pos: 681395159
    GTID:6fbc72af-348e-11e7-865c-fa163e5807c3:1-22,
ad9b2529-348d-11e7-bef0-fa163e9e3c14:1-2663607
 
SHOW SLAVE STATUS:
    Host: 10.157.24.87
    Log: mysql-bin.000047
    Pos: 144635857
    GTID:6fbc72af-348e-11e7-865c-fa163e5807c3:1-22,
ad9b2529-348d-11e7-bef0-fa163e9e3c14:1-2663607
 
Finished dump at: 2017-06-15 10:58:50
 
注:如果没有指定输出的目录:mydumper -u root -p root123
则默认自动生成export-20170615-105920目录(export-年月日-时分秒)
 
2、备份出所有的库到指定文件夹下并压缩备份文件(这个备份压缩过程会消耗过多的时间)
mydumper -u root -p root123 -c -o /docker/mydumper/all_backup_compress
会将表结构文件和表数据文件都压缩,二进制日志文件不变,如下,文件大小从17G压缩到了7.7G。
     root@dpsvstadbs05 11:20:02:mydumper$ du -sh *
     17G    all_backup
     7.7G   all_backup_compress
 
3、备份出sampson库所有表的表结构,不备份数据,到指定输出的目录/docker/mydumper/sampson-d
mydumper -u root -p root123 -B sampson -d -o /docker/mydumper/sampson-d
则/docker/mydumper/sampson-d目录下只有metadata和sampson.table-schema.sql文件。
 
4、备份出sampson库所有表的数据,不备份表结构,到指定输出的目录/docker/mydumper/sampson-m
mydumper -u root -p root123 -B sampson -m -o /docker/mydumper/sampson-m
则/docker/mydumper/sampson-m目录下只有metadata和sampson.table.sql文件。
 
5、备份出sampson库所有dsns和t1表到指定输出的目录/docker/mydumper/sampson-T
mydumper -u root -p root123 -B sampson -T dsns,t1  -o /docker/mydumper/sampson-T
则/docker/mydumper/sampson-T目录下有metadata和sampson建库文件以及dsns和t1表的备份文件。
 
注:如果备份需要后台运行,可以加--daemon实现后台执行导出命令。
 
二、myloader恢复
 
1、从全备的目录中恢复sampson库:
myloader -u root -p root123 --threads=16 --database=sampson -d /docker/mydumper/all_backup
 
2、从只备份了表结构的目录中恢复sampson库表结构到sampson-d库中去
myloader -u root -p root123 --database=sampson-d -d /docker/mydumper/sampson-d
 
3、从全备的文件夹中恢复sampson库到samp库中去:
myloader -u root -p root123  --database=samp --source-db=sampson  -d /docker/mydumper/all_backup
 
注意:建议备份恢复的时候加参数-v 3,显示详细的日志。
root@dpsvstadbs05 12:13:35:mydumper$ myloader -u root -p root123  -d /docker/mydumper/all_backup --database=huihui --source-db=lizhi -v 3
** Message: 4 threads created
** Message: Creating database `huihui`
** Message: Creating table `huihui`.`my1`
** Message: Creating table `huihui`.`my2`
** Message: Creating table `huihui`.`my3`
** Message: Creating table `huihui`.`my4`
** Message: Creating table `huihui`.`my5`
** Message: Creating table `huihui`.`my6`
** Message: Creating table `huihui`.`my7`
** Message: Creating table `huihui`.`t1`
** Message: Thread 1 restoring `lizhi`.`my1` part 0
** Message: Thread 3 restoring `lizhi`.`my2` part 0
** Message: Thread 2 restoring `lizhi`.`my3` part 0
** Message: Thread 4 restoring `lizhi`.`my4` part 0
** Message: Thread 3 restoring `lizhi`.`my5` part 0
** Message: Thread 1 restoring `lizhi`.`my6` part 0
** Message: Thread 4 restoring `lizhi`.`my7` part 0
** Message: Thread 2 restoring `lizhi`.`t1` part 0
** Message: Thread 2 shutting down
** Message: Thread 1 shutting down
** Message: Thread 4 shutting down
** Message: Thread 3 shutting down
 
附:
 
mydumper参数详解
 
$ mydumper --help
Usage:
  mydumper [OPTION...] multi-threaded MySQL dumping

Help Options:
  -?, --help                  Show help options

Application Options:
  -B, --database              要备份的数据库,不指定则备份所有库
  -T, --tables-list           需要备份的表,名字用逗号隔开
  -o, --outputdir             备份文件输出的目录
  -s, --statement-size        生成的insert语句的字节数,默认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     如果表数据是空,还是产生一个空文件(默认无数据则只有表结构文件)
  -x, --regex                 Regular expression for 'db.table' matching 使用正则表达式匹配'db.table'
  -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              不使用临时共享只读锁,使用这个选项会造成数据不一致
  --less-locking              Minimize locking time on InnoDB tables.减少对InnoDB表的锁施加时间
  -l, --long-query-guard      设定阻塞备份的长查询超时时间,单位是秒,默认是60秒(超时后默认mydumper将会退出)
  -K, --kill-long-queries     Kill long running queries (instead of aborting)杀掉长查询 (不退出)
  -D, --daemon                Enable daemon mode启用守护进程模式,守护进程模式以某个间隔不间断对数据库进行备
  -I, --snapshot-interval     dump快照间隔时间,默认60s,需要在daemon模式下
  -L, --logfile               使用的日志文件名(mydumper所产生的日志), 默认使用标准输出
  --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            使用savepoints来减少采集metadata所造成的锁时间,需要 SUPER 权限
  --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                  连接的主机名
  -u, --user                  用来备份的用户名
  -p, --password              用户密码
  -P, --port                  连接端口
  -S, --socket                使用socket通信时的socket文件
  -t, --threads               开启的备份线程数,默认是4
  -C, --compress-protocol     压缩与mysql通信的数据
  -V, --version               显示版本号
  -v, --verbose               输出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为2

 

myloader参数详解

 

$ 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每次事物执行的查询数量,默认是1000
  -o, --overwrite-tables            Drop tables if they already exist如果要恢复的表存在,则先drop掉该表,使用该参数,需要备份时候要备份表结构
  -B, --database                    An alternative database to restore into还原到指定的数据库
  -s, --source-db                   Database to restore选择被还原的数据库,将这个数据库数据还原到--database指定的数据库里
  -e, --enable-binlog               Enable binary logging of the restore data启用还原数据的二进制日志
  -h, --host                        连接的主机名
  -u, --user                        用来备份的用户名
  -p, --password                    用户密码
  -P, --port                        连接端口
  -S, --socket                      使用socket通信时的socket文件
  -t, --threads                     开启的备份线程数,默认是4
  -C, --compress-protocol           压缩与mysql通信的数据
  -V, --version                     显示版本号
  -v, --verbose                     输出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为2

 

posted on 2017-06-15 16:04  lzfj  阅读(4598)  评论(0编辑  收藏  举报

导航