微信号:iMySQL_WX

介绍:叶金荣,ORACLE MySQL ACE,专注MySQL十余年,分享MySQL技术及工作心得. 个人站点:http://imysql.com,QQ群:272675472. ACMUG(http://acmug.com)官方指定运营公众号.

XtraBackup的流式和压缩备份

2018-01-31 23:25 张艺龄

导读

译者:张艺龄

知数堂MySQL DBA班第11期学员

微信号:Randolph_ZYL,欢迎交流、拍转

原文出处:

https://www.percona.com/doc/percona-xtrabackup/LATEST/innobackupex/streaming_backups_innobackupex.html

1、前言

  • Create hot InnoDB backups without pausing your database

  • Make incremental backups of MySQL

  • Stream compressed MySQL backups to another server

  • Move tables between MySQL servers on-line

  • Create new MySQL replication slaves easily

  • Backup MySQL without adding load to the serve

2、流式和压缩备份

Streaming mode, supported by Percona XtraBackup, sends backup to STDOUT in special tar or xbstream format instead of copying files to the backup directory.

Percona XtraBackup支持流式备份,将备份以指定的tarxbstream格式发送到STDOUT,而不是直接将文件复制到备份目录。

This allows you to use other programs to filter the output of the backup, providing greater flexibility for storage of the backup. For example, compression is achieved by piping the output to a compression utility. One of the benefits of streaming backups and using Unix pipes is that the backups can be automatically encrypted.

这允许您使用其他程序来过滤备份的输出,为备份的存储提供更大的灵活性。例如,压缩是通过将输出管道输送到压缩实用程序来实现的。流式备份和使用Unix管道的优点之一:备份可以被自动加密。

To use the streaming feature, you must use the --stream, providing the format of the stream (tar or xbstream ) and where to store the temporary files:

使用流式备份,您需要使用--stream参数,指定流式备份格式(tar或xbstream)以及存储临时文件的绝对路径:

$ innobackupex --stream=tar /tmp

innobackupex starts xtrabackup in --log-stream mode in a child process, and redirects its log to a temporary file. It then uses xbstream to stream all of the data files to STDOUT, in a special xbstream format. See The xbstream binary for details. After it finishes streaming all of the data files to STDOUT, it stops xtrabackup and streams the saved log file too.

innobackupex在子进程中启动xtrabackup --log-stream模式,并将其日志重定向到临时文件。然后,使用xbstream将所有数据文件以xbstream格式传输到STDOUT。有关详细信息,请参阅xbstream二进制文件(详见:

https://www.percona.com/doc/percona-xtrabackup/LATEST/xbstream/xbstream.html)。在将所有的数据文件流到STDOUT之后,停止xtrabackup,并将保存的日志文件进行备份。

When compression is enabled, xtrabackup compresses all output data, except the meta and non-InnoDB files which are not compressed, using the specified compression algorithm. The only currently supported algorithm is quicklz. The resulting files have the qpress archive format, i.e. every *.qp file produced by xtrabackup is essentially a one-file qpress archive and can be extracted and uncompressed by the qpress file archiver which is available from Percona Software repositories.

xtrabackup在压缩过程中,将使用指定的压缩算法,压缩所有输出数据,除了元数据和非innodb文件。目前仅仅支持quicklz算法。结果文件是qpress压缩格式,即每个*.qp,xtrabackup生成的qp文件本质上是一个单文件的qpress压缩文件,可以从Percona软件存储库中获得qpress压缩文件的提取和解压方式。

Using xbstream as a stream option, backups can be copied and compressed in parallel which can significantly speed up the backup process. In case backups were both compressed and encrypted, they’ll need to decrypted first in order to be uncompressed.

使用xbstream作流式备份选项,可以并行复制和压缩备份,从而大大加快备份过程。如果备份是压缩和加密,首先需要解密,以便不被压缩。 

3、xbstream压缩备份实例

Store the complete backup directly to a single file:

将完整备份直接存储到单个文件:

$ innobackupex --stream=xbstream /root/backup/ > /root/backup/backup.xbstream

To stream and compress the backup:

进行流式和压缩备份:

$ innobackupex --stream=xbstream --compress /root/backup/ > /root/backup/backup.xbstream

To unpack the backup to the /root/backup/ directory:

将备份解压到/root/backup/目录:

$ xbstream -x <  backup.xbstream -C /root/backup/

To send the compressed backup to another host and unpack it:

将压缩后的备份发送到另一个主机并解压:

$ innobackupex --compress --stream=xbstream /root/backup/ | ssh user@otherhost "xbstream -x -C /root/backup/"

4、tar压缩备份实例

Store the complete backup directly to a tar archive:

将完整备份直接存储到tar存档文件:

$ innobackupex --stream=tar /root/backup/ > /root/backup/out.tar

To send the tar archive to another host:

将tar存档文件发送到另一个主机:

$ innobackupex --stream=tar ./ | ssh user@destination \ "cat - > /data/backups/backup.tar"

Warning:
To extract Percona XtraBackup's archive you must use tar with -i option:
用tar压缩备份,在解压时必须使用 -i 参数:

$ tar -xizf backup.tar.gz

Compress with your preferred compression tool:

可以选择的压缩方式:

$ innobackupex --stream=tar ./ | gzip - > backup.tar.gz $ innobackupex --stream=tar ./ | bzip2 - > backup.tar.bz2

注意:
Note that the streamed backup will need to be prepared before restoration. Streaming mode does not prepare the backup.

在恢复之前需要prepared备份,因为流式备份不会做prepare


5、总结

 1.  XtraBackup备份可以做到事务处理不间断,恢复速度快而高效;

 2. 使用流式备份可以节省磁盘空间和网络带宽,快速搭建主从。



扫码加入知数堂技术交流QQ群

(群号:579036588)

群内可@各位助教了解更多课程信息




知数堂

叶金荣与吴炳锡联合打造

领跑IT精英培训

行业资深专家强强联合,倾心定制

MySQL实战/MySQL优化 /大数据实战/ Python/ SQL优化

数门精品课程

紧随技术发展趋势,定期优化培训教案

融入大量生产案例,贴合企业一线需求

社群陪伴学习,一次报名,可学3期

DBA、开发工程师必修课

上千位学员已华丽转身,薪资翻番,职位提升

改变已悄然发生,你还在等什么?

扫码或“阅读原文”下载知数堂精品课程试听视频

(MySQL 实战/优化、大数据实战、Python开发,及SQL优化等课程)

密码:hg3h


 
老叶茶馆 更多文章 SQL自动化审核初体验 深入理解MySQL 5.7 GTID系列(五) gtid_executed&a 公开课发布:《分布式消息中间件核心要点》by老胡 分布式消息中间件核心要点 数据库的七种武器
猜您喜欢 “吃饭、睡觉、写代码、周而复始”,何其操蛋的生活 JavaScript 2018: 你需要和不需要深入的 要测试却没有测试机?那都不是事儿! 互联网大佬都曾是程序员,我到底差在哪儿? 当互联网遭遇汽车 缘何如此火热?【深度】