Skip to content
logo
Percona XtraBackup
Compressed backup
Initializing search
    percona/pxb-docs
    percona/pxb-docs
    • Home
      • About Percona XtraBackup
      • How Percona XtraBackup works
      • Understand version numbers
      • Install Percona XtraBackup 8.0
      • Use an APT repo to install Percona XtraBackup
      • Use a YUM repo to install Percona XtraBackup
      • Use DEB or RPM downloaded packages to install Percona XtraBackup
      • Install Percona XtraBackup from a Binary Tarball
      • Compile and install Percona XtraBackup from source code
      • What’s in the packages
      • Uninstall Percona XtraBackup
      • Run Percona XtraBackup in a Docker container
      • Implementation details
      • Connection and privileges needed
      • Configure xtrabackup
      • Server version and backup version comparison
      • xtrabackup exit codes
      • The backup cycle - full backups
      • Incremental backup
      • Compressed backup
        • Create compressed backups
          • Prepare the backup
          • Restore the backup
      • Partial backups
      • Percona XtraBackup user manual
      • Throttling backups
      • Encrypted InnoDB tablespace backups
      • Encrypt backups
      • LRU dump backup
      • Point-in-time recovery
      • Smart memory estimation
      • Work with binary logs
      • Improved log statements
      • Work with SELinux
      • Work with AppArmor
      • Enable the server to communicate via TCP/IP
      • Install and configure an SSH server
      • Analyze table statistics
      • FLUSH TABLES WITH READ LOCK option
      • lock-ddl-per-table option improvements
      • Take an incremental backup using page tracking
      • The xbcloud binary
      • Use the xbcloud binary with Swift
      • Use xbcloud Binary with Amazon S3
      • Use the xbcloud binary with MinIO
      • Use the xbcloud with Google Cloud Storage
      • Exponential backoff
      • Use the xbcloud binary with Microsoft Azure Cloud Storage
      • How-tos and recipes
      • Release notes index
      • Percona XtraBackup 8.0.30-23 (2022-11-14)
      • Percona XtraBackup 8.0.29-22 (2022-07-19)
      • Percona XtraBackup 8.0.28-21 (2022-05-25)
      • Percona XtraBackup 8.0.28-20
      • Percona XtraBackup 8.0.27-19
      • Percona XtraBackup 8.0.26-18.0
      • Percona XtraBackup 8.0.25-17.0
      • Percona XtraBackup 8.0.23-16.0
      • Percona XtraBackup 8.0.22-15.0
      • Percona XtraBackup 8.0.14
      • Percona XtraBackup 8.0.13
      • Percona XtraBackup 8.0.12
      • Percona XtraBackup 8.0.11
      • Percona XtraBackup 8.0.10
      • Percona XtraBackup 8.0.9
      • Percona XtraBackup 8.0.8
      • Percona XtraBackup 8.0.7
      • Percona XtraBackup 8.0.6
      • Percona XtraBackup 8.0.5
      • Percona XtraBackup 8.0.4
      • Percona XtraBackup 8.0-3-rc1
      • Error Message: Found tables with row versions due to INSTANT ADD/DROP columns
      • The xtrabackup option reference
      • The xbcrypt binary
      • The xbstream binary
      • Frequently asked questions
      • Glossary
      • Index of files created by Percona XtraBackup
      • Trademark policy
      • Copyright and licensing information
      • Version checking

    • Create compressed backups
      • Prepare the backup
      • Restore the backup

    Compressed backup¶

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

    Create compressed backups¶

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

    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.

    Percona XtraBackup supports the following compression algorithms:

    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-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/
    
    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!
    

    Prepare the backup¶

    Before you can prepare the backup you’ll need to uncompress all the files. Percona XtraBackup has implemented --decompress option that can be used to decompress the backup.

    $ xtrabackup --decompress --target-dir=/data/compressed/
    

    Note

    --parallel can be used with --decompress option to decompress multiple files simultaneously.

    Percona XtraBackup does not automatically remove the compressed files. In order to clean up the backup directory you should use --remove-original option. Even if they’re not removed these files will not be copied/moved over to the datadir if --copy-back or --move-back are used.

    When the files are uncompressed you can prepare the backup with the --prepare option:

    $ xtrabackup --prepare --target-dir=/data/compressed/
    
    Confirmation message
    InnoDB: Starting shutdown...
    InnoDB: Shutdown completed; log sequence number 9293846
    170223 13:39:31 completed OK!
    

    Now the files in /data/compressed/ are ready to be used by the server.

    Restore the backup¶

    xtrabackup has a --copy-back option, which performs the restoration of a backup to the server’s datadir:

    $ xtrabackup --copy-back --target-dir=/data/backups/
    

    It will copy all the data-related files back to the server’s datadir, determined by the server’s my.cnf configuration file. You should check the last line of the output for a success message:

    Expected output
    170223 13:49:13 completed OK!
    

    You should check the file permissions after copying the data back. You may need to adjust them with something like:

    $ chown -R mysql:mysql /var/lib/mysql
    

    Now that the datadir contains the restored data. You are ready to start the server.

    Contact us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2022-12-12
    Back to top
    Previous Incremental backup
    Next Partial backups
    Percona LLC and/or its affiliates, © 2023
    Made with Material for MkDocs