1. 程式人生 > >XtraBackup的流式和壓縮備份

XtraBackup的流式和壓縮備份

導讀

譯者:張藝齡

知數堂MySQL DBA班第11期學員

微訊號:Randolph_ZYL,歡迎交流、拍轉smiley_13.png?wx_lazy=1

原文出處:

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 [email protected] "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 [email protected] \ "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. 使用流式備份可以節省磁碟空間和網路頻寬,快速搭建主從。

640.gif?

掃碼加入知數堂技術交流QQ群

(群號:579036588)

群內可@各位助教了解更多課程資訊

640.png?

640?640?640?640?

知數堂

葉金榮與吳炳錫聯合打造

領跑IT精英培訓

行業資深專家強強聯合,傾心定製

MySQL實戰/MySQL優化 /大資料實戰/ Python/ SQL優化

數門精品課程

緊隨技術發展趨勢,定期優化培訓教案

融入大量生產案例,貼合企業一線需求

社群陪伴學習,一次報名,可學3期

DBA、開發工程師必修課

上千位學員已華麗轉身,薪資翻番,職位提升

改變已悄然發生,你還在等什麼?

640.png?

掃碼或“閱讀原文”下載知數堂精品課程試聽視訊

(MySQL 實戰/優化、大資料實戰、Python開發,及SQL優化等課程)

密碼:hg3h

640?wx_fmt=png

640.png?640.png?