阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Percona XtraBackup 压缩备份集

105次阅读
没有评论

共计 5788 个字符,预计需要花费 15 分钟才能阅读完成。

压缩备份集

stream 模式支持且只支持:tar 和 xbstream 两种格式,后者是 xtrabackup 提供的专有格式,解包时需要同名的专用命令处理

innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup' --stream=tar /tmp | gzip -> /data/mysqldata/backup/xtra_full.tar.gz

innobackupex: Created backup directory /tmp

这段信息表明,流格式标准输出的数据会被临时保存到我们指定的 /tmp 目录

innobackupex: You must use -i (--ignore-zeros) option for extraction of the tar stream.

最后这条提示我们,解包时必须使用 -i参数

[mysql@master backup]$ du -sh *
2.8G    2015-07-07_17-11-03
14M     xtra_full.tar.gz
打包压缩后的差距是很大的
mkdir xbstream
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup' --stream=xbstream ./ > /data/mysqldata/backup/xbstream/incremental.xbstream
./ 是以当前目录作为临时存放备份的目录

解包
[mysql@master backup]$ cd xbstream/
[mysql@master xbstream]$ xbstream -x < incremental.xbstream
[mysql@master xbstream]$ ls
backup-my.cnf  ibdata1               mysql               sakila  xtrabackup_binlog_info  xtrabackup_info
fandb          incremental.xbstream  performance_schema  test    xtrabackup_checkpoints  xtrabackup_logfile

Incremental Streaming Backups using xbstream and tar Incremental streaming backups can be performed with the xbstream streaming option. Currently backups are packed in custom xbstream format. With this feature taking a BASE backup is needed as well.

Taking a base backup:
innobackupex /data/backups

Taking a local backup:
innobackupex –incremental –incremental-lsn=LSN-number –stream=xbstream ./ > incremental.xbstream

Unpacking the backup:
xbstream -x < incremental.xbstream

Taking a local backup and streaming it to the remote server and unpacking it:

innobackupex  --incremental --incremental-lsn=LSN-number --stream=xbstream ./ | /
ssh user@hostname "cat - | xbstream -x -C > /backup-dir/"

测试:

[mysql@master xbstream]$ xbstream -x -v < incremental.xbstream
[mysql@master xbstream]$ ls
backup-my.cnf  ibdata1               mysql               sakila  xtrabackup_binlog_info  xtrabackup_info
fandb          incremental.xbstream  performance_schema  test    xtrabackup_checkpoints  xtrabackup_logfile

可以是用 - C 指定解压到哪个目录
xbstream -x -v < incremental.xbstream -C /tmp

[mysql@master xbstream]$ more xtrabackup_checkpoints 
backup_type = full-backuped
from_lsn = 0
to_lsn = 143684677
last_lsn = 143684677
compact = 0
recover_binlog_info = 0

官方文档示例有问题, 最后改成这样:

innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup' --incremental --incremental-lsn=143684677 --stream=xbstream ./ | ssh mysql@192.168.255.202 "xbstream -x -C  /data/mysqldata/backup/"

远程端:
[mysql@slave backup]$ ls
backup-my.cnf  ibdata1.delta  mysql               sakila  xtrabackup_binlog_info  xtrabackup_info
fandb          ibdata1.meta   performance_schema  test    xtrabackup_checkpoints  xtrabackup_logfile

Compact Backups

当备份 innodb 表时, 可以忽略 secondary index pages. 这回缩小备份集的大小. 负面影响是, 这回增加 prepare 用时, 因为要重建 secondary index
Compact Backups 需开启 innodb-file-per-table

innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup' --compact /data/mysqldata/backup/

查看 xtrabackup_checkpoints 可以看到 compact = 1

[mysql@master 2016-08-22_22-50-51]$ more xtrabackup_checkpoints 
backup_type = full-backuped
from_lsn = 0
to_lsn = 143789687
last_lsn = 143789687
compact = 1
recover_binlog_info = 0

Preparing Compact Backups

prepare compact backup 需要指定 –reduild-indexes 参数

innobackupex --apply-log --rebuild-indexes /data/mysqldata/backup/2016-08-2_22-50-51/ 

Restoring Compact Backups

innobackupex --copy-back /path/to/BACKUP-DIR

compress 备份

通过 –compress 压缩备份, 指定该参数后实际会传递给 xtrabackup 命令, 故只能备份 innodb 文件, 通过 ’quicklz’ 算法压缩
可以使用 –compress-threads 增加压缩并发, 提高速度
使用这种方式备份会生成以.qp 结尾的压缩文件, 实测 2.9G 的备份压缩后 52M

开始备份

innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup' --stream=xbstream --compress --compress-threads=4 ./ > /data/mysqldata/backup/backup.xbstream

解压 xbstream

xbstream -x < backup.xbstream -C /data/mysqldata/backup/fan

解压后,qpress 文件并没有解压, 在 xtrabackup2.1.4 之前使用命令进行解压

 for bf in `find . -iname "*\.qp"`; do qpress -d $bf $(dirname $bf) && rm $bf; done

xtrabackup2.1.4 之后可以使用 –decompress 参数解压, 这个参数实际调用了 qpress 命令, 所以需要先安装 qpress, 下面通过 percona 的 yum 源来安装

自动安装 percona yum 源

rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm

[root@master ~]# rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
获取 http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
准备中...                             ################################# [100%]
正在升级 / 安装...
   1:percona-release-0.0-1            ################################# [100%]

手动配置 percona yum 源

[percona]
name = CentOS $releasever - Percona
baseurl=http://repo.percona.com/centos/$releasever/os/$basearch/
enabled = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-percona
gpgcheck = 1

安装

[root@master ~]# yum install qpress
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.neusoft.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 qpress.x86_64.0.11-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==================================================================================================================================================
 Package                           架构                              版本                                源                                  大小
==================================================================================================================================================
正在安装:
 qpress                            x86_64                            11-1.el7                            percona                             31 k

事务概要
==================================================================================================================================================
安装  1 软件包

总计:31 k
安装大小:65 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。正在安装    : qpress-11-1.el7.x86_64                                                                                                        1/1 
  验证中      : qpress-11-1.el7.x86_64                                                                                                        1/1 

已安装:
  qpress.x86_64 0:11-1.el7                                                                                                                        

完毕!

安装完毕, 解压

innobackupex --decompress /data/mysqldata/backup/fan/

之后就可以 prepare 了

更多 XtraBackup 相关教程见以下内容

MySQL 管理之使用 XtraBackup 进行热备 http://www.linuxidc.com/Linux/2014-04/99671.htm

MySQL 开源备份工具 Xtrabackup 备份部署 http://www.linuxidc.com/Linux/2013-06/85627.htm

MySQL Xtrabackup 备份和恢复 http://www.linuxidc.com/Linux/2011-12/50275.htm

用 XtraBackup 实现 MySQL 的主从复制快速部署【主不锁表】http://www.linuxidc.com/Linux/2012-10/71919p2.htm

安装和使用 Percona 推出的 Xtrabackup 备份 MySQL http://www.linuxidc.com/Linux/2011-10/44451.htm

XtraBackup 的详细介绍:请点这里
XtraBackup 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-08/134535.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计5788字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中