zoukankan      html  css  js  c++  java
  • Mydumper介绍

    Mydumper是一个针对MySQL和Drizzle的高性能多线程备份和恢复工具。开发人员主要来自MySQL,Facebook,SkySQL公司。目前已经在一些线上使用了Mydumper。


    一、Mydumper主要特性:
      -执行并行(速度快)、性能提升
      -易于管理
      -一致性:在所有的threads之间维护快照,提供master和slave日志的准确位置等
      -管理型:支持PCRE

    默认是关闭了binlog的dump功能,要想开启,需要在cmke编译的时候添加-DWITH_BINLOG=ON

    二、如何获取一致性快照的:
      -server上正在运行的慢查询或中断dump,或者慢查询被kill掉
      -需要施加全局写锁("flush tables with read lock")
      -读取不同的元数据("show slave status","show master status")
      -具有事务性和非事务性表一致的快照(0.2.2+)
      -一旦所有的工作现成通知已经创建好快照,master会执行"unlock tables",开始运行队列中的job

     三、mydumper的工作原理:

    mydumper的主要工作步骤:
    1 主线程 flush tables with read lock, 施加全局只读锁,以阻止dml语句写入,保证数据的一致性
    2 读取当前时间点的二进制日志文件名和日志写入的位置并记录在metadata文件中,以供恢复使用
    3 start transaction with consistent snapshot; 开启读一致事务
    4 启用n个(线程数可以指定,默认是4)dump线程导出表和表结构
    5 备份非事务类型的表
    6 主线程 unlock tables,备份完成非事务类型的表之后,释放全局只读锁
    7 基于事务dump innodb tables
    8 事务结束

    四、mydumper的安装:

    # yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel
    # wget http://launchpad.net/mydumper/0.9/0.9.1/+download/mydumper-0.9.1.tar.gz
    # tar zxvf mydumper-0.9.1.tar.gz -C ../software/
    # cmake .

    #  cmake .
    -- The C compiler identification is GNU 4.8.5
    -- The CXX compiler identification is GNU 4.8.5
    -- Check for working C compiler: /bin/cc
    -- Check for working C compiler: /bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: /bin/c++
    -- Check for working CXX compiler: /bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Using mysql-config: /bin/mysql_config
    -- Found MySQL: /usr/include/mysql, /usr/lib64/mysql/libmysqlclient.so;/usr/lib64/libpthread.so;/usr/lib64/libz.so;/usr/lib64/libm.so;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;/usr/lib64/libdl.so
    -- Found ZLIB: /usr/lib64/libz.so (found version "1.2.7") 
    -- Found PkgConfig: /bin/pkg-config (found version "0.27.1") 
    -- checking for one of the modules 'glib-2.0'
    -- checking for one of the modules 'gthread-2.0'
    -- checking for module 'libpcre'
    --   found libpcre, version 8.32
    -- Found PCRE: /usr/include  
    
    CMake Warning at docs/CMakeLists.txt:9 (message):
      Unable to find Sphinx documentation generator
    
    
    -- ------------------------------------------------
    -- MYSQL_CONFIG = /bin/mysql_config
    -- CMAKE_INSTALL_PREFIX = /usr/local
    -- BUILD_DOCS = ON
    -- WITH_BINLOG = OFF
    -- RUN_CPPCHECK = OFF
    -- Change a values with: cmake -D<Variable>=<Value>
    -- ------------------------------------------------
    -- 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /root/mydumper-0.9.1
    

    # make

    # make 
    Scanning dependencies of target mydumper
    [ 25%] Building C object CMakeFiles/mydumper.dir/mydumper.c.o
    [ 50%] Building C object CMakeFiles/mydumper.dir/server_detect.c.o
    [ 75%] Building C object CMakeFiles/mydumper.dir/g_unix_signal.c.o
    Linking C executable mydumper
    [ 75%] Built target mydumper
    Scanning dependencies of target myloader
    [100%] Building C object CMakeFiles/myloader.dir/myloader.c.o
    Linking C executable myloader
    [100%] Built target myloader
    

    # make install

    # make install
    [ 75%] Built target mydumper
    [100%] Built target myloader
    Install the project...
    -- Install configuration: ""
    -- Installing: /usr/local/bin/mydumper
    -- Removed runtime path from "/usr/local/bin/mydumper"
    -- Installing: /usr/local/bin/myloader
    -- Removed runtime path from "/usr/local/bin/myloader"
    

    安装好之后 ,会生成两个文件:

    /usr/local/bin/mydumper  
    /usr/local/bin/myloader
    

     

    五、参数说明:

      -B, --database              要导出的数据库名
      -T, --tables-list           要导出的表名,多个表用逗号分隔。不支持正则表达式
      -o, --outputdir             导出数据文件存放的目录,mydumper会自动创建
      -s, --statement-size        生成插入语句的字节数, 默认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              压缩导出的文件
      -e, --build-empty-files     即使是空表也为表创建文件
      -x, --regex                 使用正则表达式匹配'db.table'
      -i, --ignore-engines        忽略的存储引擎,多个存储引擎使用逗号分隔
      -m, --no-schemas            只导出数据,不导出建库建表语句
      -d, --no-data               仅仅导出建表结构,创建db的语句,不导出表的数据
      -G, --triggers              导出触发器
      -E, --events                导出events
      -R, --routines              导出存储过程和函数
      -k, --no-locks              不施加临时的共享读锁,会导致备份不一致
      --less-locking              最小化在innodb表上的锁表时间
      -l, --long-query-guard      设置长查询定时器,单位是秒,默认是60
      -K, --kill-long-queries     Kill掉运行时间长的查询
      -D, --daemon                以守护进程的方式执行
      -I, --snapshot-interval     创建导出快照的时间间隔,默认是 60s ,该参数只有在守护进程执行的时候有用
      -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减少对元数据锁定的问题,需要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                套接字文件
      -t, --threads               所使用的线程数,默认是4
      -C, --compress-protocol     压缩协议
      -V, --version               显示版本后退出
      -v, --verbose               输出模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为2
    

      

    六、mydump导出的文件类型

    metadata 			:包含导出开始和结束时间,如果开启binlog会记录日志位置信息;如果启用gtid ,则记录gtid信息。 
    db.table.sql        :数据文件,insert语句
    db.table-schema.sql :包含建表语句
    db-schema.sql       :包含建库语句
    

      

  • 相关阅读:
    关于博客园创始人的心路历程,感触很深!
    Django中的ORM相关操作:F查询,Q查询,事物,ORM执行原生SQL
    在Django中运行脚本文件以及打印出SQL语句。
    Django中的跨表查询,多表查询。
    Django中的ORM介绍,字段以及字段的参数。
    9.2安全的 Web API 与 Web API 2.2 个人帐户
    9.1WebApi的身份验证和授权
    3.1创建项目
    2.4使用属性在 ASP.NET Web API 2 路由创建一个 REST API
    2.3属性在 ASP.NET Web API 2 路由
  • 原文地址:https://www.cnblogs.com/abclife/p/7755031.html
Copyright © 2011-2022 走看看