Skip to content

Create a compressed backup

Percona XtraBackup supports compressed backups. A local or streaming backup can be compressed or decompressed with xbstream.

To make a compressed backup, use the --compress option along with the --backup and --target-dir options.

Version updates

Percona XtraBackup 8.0.34-29 and later

Percona XtraBackup removes qpress/QuickLZ and moves the ZSTD compression method to General Availability. With this version ZSTD becomes the default compression method for the --compress option.

The following compression algorithms are supported:

Zstandard (ZSTD)

ZSTD is a fast lossless compression algorithm that targets real-time compression scenarios and better compression ratios. ZSTD is the default compression method for the --compress option.

To compress files using the ZSTD compression algorithm, run the following command:

$ xtrabackup --backup --compress --target-dir=/data/backup

You can specify ZSTD compression level with the --compress-zstd-level(=#) option. The default value is 1.

$ xtrabackup --backup --compress --compress-zstd-level=1 --target-dir=/data/backup

If you want to speed up the compression you can use the parallel compression, which can be enabled with --compress-threads option. Following example will use four threads for compression:

$ xtrabackup --backup --compress --compress-threads=4 \
--target-dir=/data/compressed/

The expected output:

...
170223 13:00:38 [01] Compressing ./test/sbtest1.frm to /tmp/compressed/test/sbtest1.frm.qp
170223 13:00:38 [01]        ...done
170223 13:00:38 [01] Compressing ./test/sbtest2.frm to /tmp/compressed/test/sbtest2.frm.qp
170223 13:00:38 [01]        ...done
...
170223 13:00:39 [00] Compressing xtrabackup_info
170223 13:00:39 [00]        ...done
xtrabackup: Transaction log of lsn (9291934) to (9291934) was copied.
170223 13:00:39 completed OK!

lz4

To compress files using the lz4 compression algorithm, set --compress option to lz4:

$ xtrabackup --backup --compress=lz4 --target-dir=/data/backup

To decompress files, use the --decompress option.

Percona XtraBackup 8.0.31-24 to 8.0.34-29

Using qpress/QuickLZ to compress backups is deprecated and may be removed in future versions. We recommend using either LZ4 or Zstandard (ZSTD) compression algorithms. ZSTD compression algorithm is in tech preview.

Before Percona XtraBackup 8.0.31-24

By default, the --compress option uses the qpress tool that you can install with the percona-release package configuration tool as follows:

$ sudo percona-release enable tools
$ sudo apt update
$ sudo apt install qpress

Note

Enable the repository: percona-release enable-only tools release.

If Percona XtraBackup is intended to be used in combination with the upstream MySQL Server, you only need to enable the tools repository: percona-release enable-only tools.

The following compression algorithms are supported:

quicklz

To compress files using the quicklz compression algorithm, use --compress option:

$ xtrabackup --backup --compress --target-dir=/data/backup

lz4

To compress files using the lz4 compression algorithm, set --compress option to lz4:

$ xtrabackup --backup --compress=lz4 --target-dir=/data/backup

Zstandard (ZSTD)

The Zstandard (ZSTD) compression algorithm is a tech preview feature. Before using ZSTD in production, we recommend that you test restoring production from physical backups in your environment, and also use the alternative backup method for redundancy.

Percona XtraBackup 8.0.30-23 adds support for the Zstandard (ZSTD) compression algorithm. ZSTD is a fast lossless compression algorithm that targets real-time compression scenarios and better compression ratios.

To compress files using the ZSTD compression algorithm, set --compress option to zstd:

$ xtrabackup --backup --compress=zstd --target-dir=/data/backup

You can specify ZSTD compression level with the --compress-zstd-level(=#) option. The default value is 1.

$ xtrabackup --backup --compress --compress-zstd-level=1 --target-dir=/data/backup

If you want to speed up the compression you can use the parallel compression, which can be enabled with --compress-threads option. Following example will use four threads for compression:

$ xtrabackup --backup --compress --compress-threads=4 \
--target-dir=/data/compressed/

The expected output:

...
170223 13:00:38 [01] Compressing ./test/sbtest1.frm to /tmp/compressed/test/sbtest1.frm.qp
170223 13:00:38 [01]        ...done
170223 13:00:38 [01] Compressing ./test/sbtest2.frm to /tmp/compressed/test/sbtest2.frm.qp
170223 13:00:38 [01]        ...done
...
170223 13:00:39 [00] Compressing xtrabackup_info
170223 13:00:39 [00]        ...done
xtrabackup: Transaction log of lsn (9291934) to (9291934) was copied.
170223 13:00:39 completed OK!

Using --encrypt might create larger backups than expected when used with InnoDB Page Compression.

To avoid this issue with compressed backups, use the --compress option with the --xbstream option in Percona XtraBackup 8.0.31-24 and later.

The next step is to prepare the backup in order to restore it.

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services.


Last update: 2024-04-30