Percona XtraBackup 压缩备份集

【广告位】文章头部(标题下方、正文上方)

压缩备份集

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参数

【广告位】文章正文中间
本文已展示 50% · 完整内容需验证码解锁

关注公众号,解锁完整文章

微信扫码关注 星哥玩云, 在公众号对话框回复关键词 星哥玩云博客 获取验证码。输入后即可阅读全文, 一次解锁全站文章通用。

星哥玩云 微信公众号二维码
微信扫一扫 / 长按识别,关注「星哥玩云」
【广告位】文章底部(正文结束、评论区上方)
评论功能已在静态化后停用 · 返回顶部 ↑