关闭 x
IT技术网
    技 采 号
    ITJS.cn - 技术改变世界
    • 实用工具
    • 菜鸟教程
    IT采购网 中国存储网 科技号 CIO智库

    IT技术网

    IT采购网
    • 首页
    • 行业资讯
    • 系统运维
      • 操作系统
        • Windows
        • Linux
        • Mac OS
      • 数据库
        • MySQL
        • Oracle
        • SQL Server
      • 网站建设
    • 人工智能
    • 半导体芯片
    • 笔记本电脑
    • 智能手机
    • 智能汽车
    • 编程语言
    IT技术网 - ITJS.CN
    首页 » MySQL »TB级mysql数据之xtrabackup压缩备份迁移方案分享

    TB级mysql数据之xtrabackup压缩备份迁移方案分享

    2015-03-29 00:00:00 出处:ITJS
    分享

    开始迁移数据了,因为历史遗留的问题,又因为部门的数据统一性,多个不同的库表都在一个节点上,然后后面好多个从…..

    首先看下我们数据库的大小… , 再加上一个binlog日志,会更大的…. 当然对于咱们数据迁移来说,只需要把数据就可以了. 既然是迁移,

    那么大家一定想做到无缝的迁移… 首先在mysql master做备份,我们在上海机房搭建一个从服务节点,把文件pull下来,然后跟master做同步… 当数据校验ok后,修改所有配置的ip地址。

    老规矩,日前爬虫太狠,经常爬了我的页面,然后作者换成他们自己的….. http://xiaorui.cc/ p=1755

    3.4T,可以说是我见过的最大的数据量了,我们公司本身就是大数据相关的,但大数据基本是在hbase和Elasticsearch、solr中。 可能有人问了,为毛分库分表,因为以前的应用实在太多,不可能把每个select的逻辑都做分库分表的逻辑查询 …. 其实最好的方法是中间件来承担语句的时间range切分,但是这同样需要开发的成本,一些开源的mysql proxy,也是无法做到这样语句切分,是需要一定程度的二次开发的…. 话说开源的各种mysql 中间件,貌似还没有给力到完美支持语句分库分表…..

    废话不多说,这是我们数据库的大小….

    [chinastor.com-root@bj-buzz-db01 ssd]# du -sh mysql/ .4T mysql/ 

    mysql的备份肯定不会用mysqldump这种锁表的渣渣,必须用Percona的备份工具.

    XtraBackup 有两个工具:xtrabackup 和 innobackupex:

    xtrabackup 本身只能备份 InnoDB 和 XtraDB ,不能备份 MyISAM;

    innobackupex 本身是 Hot Backup 脚本修改而来,同时可以备份 MyISAM 和 InnoDB,但是备份 MyISAM 需要加读锁。

    官网:http://www.percona.com/software/percona-xtrabackup

    文档:http://www.percona.com/doc/percona-xtrabackup/2.2/index.html

    因为考虑到文件是在太大,必须要做好压缩,不然 不管scp和rsync都是很痛苦的一件事情。

    首先用的是gzip进行压缩,但是发现速度有些慢,linux 管道的速度没啥好质疑的…. 那瓶颈应该是处在gzip压缩上…

    innobackupex –defaults-file=/etc/mysql/my.cnf –stream=tar /data/7_15 | gzip > /data/7_15.tar.gz

    查了下percona关于压缩的话题,官方是推荐用上面的方法的。 但是问题我刚才也说明白了,gzip只是个单进程的应用,如何跑满cpu… 其实xtrabackup本身也有压缩的功能参数.

    # 压缩

    –compress # 开启压缩,目前只支持quicklz算法 压缩级别在0-9.1快速压缩,9最佳压缩,0不压缩。默认为1.

    –compress-threads=5 # 并发压缩线程,默认为1

    –compress-chunk-size=64K # 每个压缩线程使用的buffer,默认64K

    percona也是有加密的功能….

    # 加密

    –encrypt=AES256 # 开启加密,目前支持的算法有AES128, AES192 和 AES256

    –encrypt-key=3c0efcea569021b49245e47b5d6a0e28 # 32位密钥,不过不推荐这么使用,最好将密钥存放在文件中,用encrypt-key-file参数引用

    –encrypt-threads=5 # 加密线程数,默认为1

    使用tar模式

    innobackupex –defaults-file=/etc/mysql/my.cnf –stream=tar –compress ./ > 7_15

    使用xbstream

    innobackupex –defaults-file=/etc/mysql/my.cnf –stream=xbstream /tmp >/backup/bak.xbstream

    用了压缩,也用了多线程,速度貌似不是很给力…

    紧接着,在xtrabackup help里面看到了 –parallel这个参数,他是用来控制并发的… 但是经过我的测试,效果一点都不明显,说白了就是没啥效果…. 当然也有可能我的场景不对付 或者是使用方法不对

    默认情况下 xtrabackup 备份时只会开启一个进程进行数据文件的备份,若配置参数 –parallel=N 可以让 xtrabackup 开启 N 个子进程对多个数据文件进行并发备份,这样可以加快备份的速度。当然服务器的 IO 处理能力以及对服务器的影响也是要考虑的,所以另一个参数 –throttle=IOS 会与它同时使用,这个参数用来限制备份过程中每秒读写的 IO 次数,对服务器的 IO 是一个保护。

    innobackupex –defaults-file=/etc/mysql/my.cnf –parallel=10 –stream=tar /data/7_15 | gzip > /data/7_15.tar.gz

    这是最后的方式…. 既然是gzip速度慢,那么就用pigz这种gzip的多线程加强版来改造他,加强他…. 个人觉得 –parallel –compress-threads 看起来不错,但是性能提升不是很满意..

    innobackupex –defaults-file=/etc/mysql/my.cnf –stream=tar /data/7_15 | pigz -9 -p 32 > /data/7_15.tar.gz

    这是pigz的安装方式.

    wget http://zlib.net/pigz/pigz-2.3.3.tar.gz tar zxvf pigz-2.3.3.tar.gz cd pigz-2.3.3/ make 

    遇到一个make问题。

    [chinastor.com-root@bj-buzz-db01 pigz-2.3.3]# make

    cc -O3 -Wall -Wextra -c -o pigz.o pigz.c

    pigz.c:365:73: error: zlib.h: No such file or directory

    pigz.c:372:4: error: #error Need zlib version 1.2.3 or later

    pigz.c: In function ‘put_header’:

    pigz.c:1000: error: ‘Z_DEFAULT_COMPRESSION’ undeclared (first use in this function)

    pigz.c:1000: error: (Each undeclared identifier is reported only once

    pigz.c:1000: error: for each function it appears in.)

    pigz.c: At top level:

    pigz.c:1459: error: expected ‘)’ before ‘*’ token

    pigz.c: In function ‘compress_thread’:

    pigz.c:1495: error: ‘z_stream’ undeclared (first use in this function)

    pigz.c:1495: error: expected ‘;’ before ‘strm’

    pigz.c:1502: error: ‘strm’ undeclared (first use in this function)

    pigz.c:1502: error: ‘Z_NULL’ undeclared (first use in this function)

    pigz.c:1505: warning: implicit declaration of function ‘deflateInit2’

    pigz.c:1505: error: ‘Z_DEFLATED’ undeclared (first use in this function)

    pigz.c:1505: error: ‘Z_DEFAULT_STRATEGY’ undeclared (first use in this function)

    pigz.c:1506: error: ‘Z_MEM_ERROR’ undeclared (first use in this function)

    pigz.c:1508: error: ‘Z_OK’ undeclared (first use in this function)

    pigz.c:1530: warning: implicit declaration of function ‘deflateReset’

    pigz.c:1531: warning: implicit declaration of function ‘deflateParams’

    pigz.c:1546: warning: implicit declaration of function ‘deflateSetDictionary’

    pigz.c:1595: warning: implicit declaration of function ‘deflate_engine’

    pigz.c:1595: error: ‘Z_NO_FLUSH’ undeclared (first use in this function)

    pigz.c:1620: error: ‘Z_SYNC_FLUSH’ undeclared (first use in this function)

    pigz.c:1624: error: ‘Z_FINISH’ undeclared (first use in this function)

    pigz.c:1687: warning: implicit declaration of function ‘adler32’

    pigz.c:1687: warning: implicit declaration of function ‘crc32’

    pigz.c:1706: warning: implicit declaration of function ‘deflateEnd’

    pigz.c: In function ‘write_thread’:

    pigz.c:1737: error: ‘Z_NULL’ undeclared (first use in this function)

    pigz.c: In function ‘single_compress’:

    pigz.c:2039: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

    pigz.c:2039: error: ‘strm’ undeclared (first use in this function)

    pigz.c:2062: error: ‘z_stream’ undeclared (first use in this function)

    pigz.c:2063: error: ‘Z_NULL’ undeclared (first use in this function)

    pigz.c:2066: error: ‘Z_DEFLATED’ undeclared (first use in this function)

    pigz.c:2066: error: ‘Z_DEFAULT_STRATEGY’ undeclared (first use in this function)

    pigz.c:2067: error: ‘Z_MEM_ERROR’ undeclared (first use in this function)

    pigz.c:2069: error: ‘Z_OK’ undeclared (first use in this function)

    pigz.c:2173: warning: implicit declaration of function ‘deflate’

    pigz.c:2173: error: ‘Z_NO_FLUSH’ undeclared (first use in this function)

    pigz.c:2198: error: ‘Z_SYNC_FLUSH’ undeclared (first use in this function)

    pigz.c:2202: error: ‘Z_FINISH’ undeclared (first use in this function)

    pigz.c: In function ‘infchk’:

    pigz.c:3044: error: ‘z_stream’ undeclared (first use in this function)

    pigz.c:3044: error: expected ‘;’ before ‘strm’

    pigz.c:3054: error: ‘Z_NULL’ undeclared (first use in this function)

    pigz.c:3055: error: ‘strm’ undeclared (first use in this function)

    pigz.c:3058: warning: implicit declaration of function ‘inflateBackInit’

    pigz.c:3059: error: ‘Z_MEM_ERROR’ undeclared (first use in this function)

    pigz.c:3061: error: ‘Z_OK’ undeclared (first use in this function)

    pigz.c:3067: warning: implicit declaration of function ‘inflateBack’

    pigz.c:3068: warning: implicit declaration of function ‘inflateBackEnd’

    pigz.c:3069: error: ‘Z_DATA_ERROR’ undeclared (first use in this function)

    pigz.c:3072: error: ‘Z_BUF_ERROR’ undeclared (first use in this function)

    pigz.c:3074: error: ‘Z_STREAM_END’ undeclared (first use in this function)

    pigz.c: In function ‘defaults’:

    pigz.c:3828: error: ‘Z_DEFAULT_COMPRESSION’ undeclared (first use in this function)

    make: *** [pigz.o] Error 1

    提示错误,是因为没有zlib开发包原因….

    yum -y install zlib-devel

    然后我们再次用pigz进行压缩,下面是cpu的使用率。

    Tasks: 446 total, 1 running, 444 sleeping, 0 stopped, 1 zombie

    Cpu0 : 69.2%us, 2.6%sy, 0.0%ni, 23.5%id, 4.6%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu1 : 45.4%us, 1.0%sy, 0.0%ni, 53.6%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu2 : 51.0%us, 5.0%sy, 0.0%ni, 29.1%id, 14.6%wa, 0.0%hi, 0.3%si, 0.0%st

    Cpu3 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu4 : 34.0%us, 3.0%sy, 0.0%ni, 60.4%id, 2.6%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu5 : 69.3%us, 0.7%sy, 0.0%ni, 30.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu6 : 33.4%us, 15.4%sy, 0.0%ni, 27.4%id, 17.4%wa, 0.0%hi, 6.4%si, 0.0%st

    Cpu7 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu8 : 55.6%us, 1.3%sy, 0.0%ni, 36.8%id, 6.3%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu9 : 87.8%us, 0.3%sy, 0.0%ni, 11.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu10 : 99.3%us, 0.0%sy, 0.0%ni, 0.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu11 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu12 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu13 : 99.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu14 : 99.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu15 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu16 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu17 : 99.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu18 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu19 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu20 : 99.7%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st

    Cpu21 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    Cpu22 : 98.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 1.0%si, 0.0%st

    Cpu23 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

    我们再来看看磁盘,毫无压力…. 我这边就不贴图了,刚要想起把iostat -x 1的结果贴出来,发现备份已经完成。。。 在下午xtrabackup备份压缩的过程中,其他的访问没感受到有性能的影响…..

    www.itjs.cn

    我们再来看看大小…. 965G…… 压缩的效果还是比较的满意…. 消耗的时间是,7:38 – 1:18 ,将近6个半小时。。。。。

    www.itjs.cn

    那么我又在读取mysql数据文件的时候,增加了并发,使用了–parallel参数让 xtrabackup 开启 N 个子进程对多个数据文件进行并发备份。

    innobackupex –defaults-file=/etc/mysql/my.cnf –user=root –password=xxx –parallel=5 –stream=tar /data/7_15_p | pigz -8 -p 15 > /data/7_15_p.tar.gz

    首先看下他的io情况. 我们会发现,数据盘无压力,但是备份的存储盘io已经是报了…. 这说明啥 说明xtrabackup在增加了并发读取文件的时候,不仅考虑mysql数据盘的io,也要考虑目标存储盘的io是否能抗住。。。。

    Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util sda               0.00    35.00    0.00    7.00     0.00   328.00    46.86     0.01    1.43   1.43   1.00 sdb               0.00    31.00  460.00   15.00 172944.00   368.00   364.87     1.51    3.16   2.08  98.90 dm-0              0.00     0.00    0.00   41.00     0.00   328.00     8.00     0.23    5.51   0.24   1.00 dm-1              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00 dm-2              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00 memdiska          0.00     0.00   63.00   37.00  2672.00   296.00    29.68     0.01    0.07   0.06   0.60 

    上一篇返回首页 下一篇

    声明: 此文观点不代表本站立场;转载务必保留本文链接;版权疑问请联系我们。

    别人在看

    hiberfil.sys文件可以删除吗?了解该文件并手把手教你删除C盘的hiberfil.sys文件

    Window 10和 Windows 11哪个好?答案是:看你自己的需求

    盗版软件成公司里的“隐形炸弹”?老板们的“法务噩梦” 有救了!

    帝国CMS7.5编辑器上传图片取消宽高的三种方法

    帝国cms如何自动生成缩略图的实现方法

    Windows 12即将到来,将彻底改变人机交互

    帝国CMS 7.5忘记登陆账号密码怎么办?可以phpmyadmin中重置管理员密码

    帝国CMS 7.5 后台编辑器换行,修改回车键br换行为p标签

    Windows 11 版本与 Windows 10比较,新功能一览

    Windows 11激活产品密钥收集及专业版激活方法

    IT头条

    智能手机市场风云:iPhone领跑销量榜,华为缺席引争议

    15:43

    大数据算法和“老师傅”经验叠加 智慧化收储粮食尽显“科技范”

    15:17

    严重缩水!NVIDIA将推中国特供RTX 5090 DD:只剩24GB显存

    00:17

    无线路由大厂 TP-Link突然大裁员:补偿N+3

    02:39

    Meta 千万美金招募AI高级人才

    00:22

    技术热点

    windows 7应用程序无法启动出现窗口提示找不到应用程序

    SQL中数据类型转换函数的使用

    MySQL使用变量的注意事项

    SQL Server 锁自定义的示例演示

    如何在Linux命令行中创建以及展示演示稿

    windows 7任务栏显示标题的方法(windows 7任务栏缩略图不显示出

      友情链接:
    • IT采购网
    • 科技号
    • 中国存储网
    • 存储网
    • 半导体联盟
    • 医疗软件网
    • 软件中国
    • ITbrand
    • 采购中国
    • CIO智库
    • 考研题库
    • 法务网
    • AI工具网
    • 电子芯片网
    • 安全库
    • 隐私保护
    • 版权申明
    • 联系我们
    IT技术网 版权所有 © 2020-2025,京ICP备14047533号-20,Power by OK设计网

    在上方输入关键词后,回车键 开始搜索。Esc键 取消该搜索窗口。