diff --git a/8.0/search/search_index.json b/8.0/search/search_index.json index 26184cdaa..8fce0ea80 100644 --- a/8.0/search/search_index.json +++ b/8.0/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-,:!=\\[\\]()\"`/]+|\\.(?!\\d)|&[lg]t;|(?!\\b)(?=[A-Z][a-z])","pipeline":["stopWordFilter"]},"docs":[{"location":"index.html","title":"Percona XtraBackup - Documentation","text":"

This documentation is for the latest release: Percona XtraBackup 8.0.33-28 (Release Notes).

Percona XtraBackup is an open source hot backup utility, for MySQL - based servers, that keeps your database fully available during planned maintenance windows.

Whether it is a 24x7 highly loaded server or a low-transaction-volume environment, Percona XtraBackup is designed to make backups a seamless procedure without disrupting the performance of the server in a production environment. Percona XtraBackup (PXB) is a 100% open source backup solution with a commercial support available for organizations who want to benefit from comprehensive, responsive, and cost-flexible database support for MySQL.

"},{"location":"index.html#supported-storage-engines","title":"Supported storage engines","text":"

Percona XtraBackup can back up data from InnoDB, XtraDB, MyISAM, and MyRocks tables on MySQL 8.0 servers as well as Percona Server for MySQL with XtraDB, Percona Server for MySQL 8.0, and Percona XtraDB Cluster 8.0.

Version updates

Version 8.0.6 and later supports the MyRocks storage engine. An incremental backup on the MyRocks storage engine does not determine if an earlier full or incremental backup contains the same files. Percona XtraBackup copies all MyRocks files each time it takes a backup. Percona XtraBackup does not support the TokuDB storage engine. Find more information in Percona TokuBackup.

"},{"location":"index.html#limitations","title":"Limitations","text":"

Percona XtraBackup 8.0 does not support making backups of databases created in versions prior to 8.0 of MySQL, Percona Server for MySQL or Percona XtraDB Cluster. As the changes that MySQL 8.0 introduced in data dictionaries, redo log and undo log are incompatible with previous versions, it is currently impossible for Percona XtraBackup 8.0 to also support versions prior to 8.0.

Due to changes in MySQL 8.0.20 released by Oracle at the end of April 2020, Percona XtraBackup 8.0, up to version 8.0.11, is not compatible with MySQL version 8.0.20 or higher, or Percona products that are based on it: Percona Server for MySQL and Percona XtraDB Cluster.

For more information, see Percona XtraBackup 8.x and MySQL 8.0.20

Learn more about other Percona products

Percona Distribution for MySQL 8.0

"},{"location":"404.html","title":"404 - Not Found","text":"

We can\u2019t find the page you are looking for. Try using the Search or return to the homepage.

"},{"location":"about-xtrabackup.html","title":"About Percona XtraBackup","text":"

Percona XtraBackup is the world\u2019s only open source, free MySQL hot backup software that performs non-blocking backups for InnoDB and XtraDB databases.

With Percona XtraBackup, you can achieve the following benefits:

Percona XtraBackup makes MySQL hot backups for all versions of Percona Server for MySQL, and MySQL. It performs streaming, compressed, and incremental MySQL backups.

Important

Percona XtraBackup 2.4 supports MySQL and Percona Server for MySQL 5.6 and 5.7 databases. Due to changes in the MySQL redo log and data dictionary formats, the Percona XtraBackup 8.0.x versions are only compatible with MySQL 8.0.x, Percona Server for MySQL 8.0.x, and compatible versions.

Percona\u2019s enterprise-grade commercial MySQL Support contracts include support for Percona XtraBackup. We recommend support for critical production deployments. Percona XtraDB Backup supports encryption.

"},{"location":"about-xtrabackup.html#supported-storage-engines","title":"Supported storage engines","text":"

Percona XtraBackup can back up data from InnoDB, XtraDB, MyISAM, and MyRocks tables on MySQL 8.0 servers as well as Percona Server for MySQL with XtraDB, Percona Server for MySQL 8.0, and Percona XtraDB Cluster 8.0.

Version updates

Version 8.0.6 and later supports the MyRocks storage engine. An incremental backup on the MyRocks storage engine does not determine if an earlier full or incremental backup contains the same files. Percona XtraBackup copies all MyRocks files each time it takes a backup. Percona XtraBackup does not support the TokuDB storage engine.

See also

Percona TokuBackup

"},{"location":"about-xtrabackup.html#limitations","title":"Limitations","text":"

Percona XtraBackup 8.0 does not support making backups of databases created in versions prior to 8.0 of MySQL, Percona Server for MySQL or Percona XtraDB Cluster. As the changes that MySQL 8.0 introduced in data dictionaries, redo log and undo log are incompatible with previous versions, it is currently impossible for Percona XtraBackup 8.0 to also support versions prior to 8.0.

Due to changes in MySQL 8.0.20 released by Oracle at the end of April 2020, Percona XtraBackup 8.0, up to version 8.0.11, is not compatible with MySQL version 8.0.20 or higher, or Percona products that are based on it: Percona Server for MySQL and Percona XtraDB Cluster.

For more information, see Percona XtraBackup 8.x and MySQL 8.0.20

"},{"location":"about-xtrabackup.html#what-are-the-features-of-percona-xtrabackup","title":"What are the features of Percona XtraBackup?","text":"

Here is a short list of the Percona XtraBackup features. See the documentation for more.

See also

How Percona XtraBackup works

"},{"location":"about-xtrabackup.html#additional-information","title":"Additional information","text":"

The InnoDB tables are locked while copying non-InnoDB data.

"},{"location":"accelerate-backup-process.html","title":"Accelerate the backup process","text":""},{"location":"accelerate-backup-process.html#copy-with-the-parallel-and-compress-threads-options","title":"Copy with the --parallel and --compress-threads options","text":"

When making a local or streaming backup with xbstream option, multiple files can be copied at the same time when using the --parallel option. This option specifies the number of threads created by xtrabackup to copy data files.

To take advantage of this option either the multiple tablespaces option must be enabled (innodb_file_per_table) or the shared tablespace must be stored in multiple ibdata files with the innodb_data_file_path option. Having multiple files for the database (or splitting one into many) doesn\u2019t have a measurable impact on performance.

As this feature is implemented at the file level, concurrent file transfer can sometimes increase I/O throughput when doing a backup on highly fragmented data files, due to the overlap of a greater number of random read requests. You should consider tuning the filesystem also to obtain the maximum performance (e.g. checking fragmentation).

If the data is stored on a single file, this option will have no effect.

To use this feature, simply add the option to a local backup, for example:

$ xtrabackup --backup --parallel=4 --target-dir=/path/to/backup\n

By using the xbstream in streaming backups, you can additionally speed up the compression process with the --compress-threads option. This option specifies the number of threads created by xtrabackup for for parallel data compression. The default value for this option is 1.

To use this feature, simply add the option to a local backup, for example:

$ xtrabackup --backup --stream=xbstream --compress --compress-threads=4 --target-dir=./ > backup.xbstream\n

Before applying logs, compressed files will need to be uncompressed.

"},{"location":"accelerate-backup-process.html#the-rsync-option","title":"The --rsync option","text":"

In order to speed up the backup process and to minimize the time FLUSH TABLES WITH READ LOCK is blocking the writes, the option --rsync should be used. When this option is specified, xtrabackup uses rsync to copy all non-InnoDB files instead of spawning a separate cp for each file, which can be much faster for servers with a large number of databases or tables. xtrabackup will call the rsync twice, once before the FLUSH TABLES WITH READ LOCK and once during to minimize the time the read lock is being held. During the second rsync call, it will only synchronize the changes to non-transactional data (if any) since the first call performed before the FLUSH TABLES WITH READ LOCK. Note that Percona XtraBackup will use Backup locks where available as a lightweight alternative to FLUSH TABLES WITH READ LOCK. This feature is available in Percona Server for MySQL 5.6+. Percona XtraBackup uses this automatically to copy non-InnoDB data to avoid blocking DML queries that modify InnoDB tables.

Note

This option cannot be used together with the --stream option.

"},{"location":"analyze-table-statistics.html","title":"Analyze table statistics","text":"

Note

As of Percona XtraBackup 8.0.30 the --stats option is deprecated and may be removed in future releases. We no longer support using the --stats option in Percona XtraBackup 8.0.29 and older versions.

The xtrabackup binary can analyze InnoDB data files in read-only mode to give statistics about them. To do this, you should use the --stats option. You can combine this with the --tables option to limit the files to examine. It also uses the --use-memory option.

You can perform the analysis on a running server, with some chance of errors due to the data being changed during analysis. Or, you can analyze a backup copy of the database. Either way, to use the statistics feature, you need a clean copy of the database including correctly sized log files, so you need to execute with --prepare twice to use this functionality on a backup.

The result of running on a backup might look like the following:

Expected output
<INDEX STATISTICS>\n  table: test/table1, index: PRIMARY, space id: 12, root page 3\n  estimated statistics in dictionary:\n    key vals: 25265338, leaf pages 497839, size pages 498304\n  real statistics:\n     level 2 pages: pages=1, data=5395 bytes, data/pages=32%\n     level 1 pages: pages=415, data=6471907 bytes, data/pages=95%\n        leaf pages: recs=25958413, pages=497839, data=7492026403 bytes, data/pages=91%\n

This can be interpreted as follows:

A more detailed example is posted as a MySQL Performance Blog post.

"},{"location":"analyze-table-statistics.html#script-to-format-output","title":"Script to format output","text":"

The following script can be used to summarize and tabulate the output of the statistics information:

Expected output
tabulate-xtrabackup-stats.pl\n\n#!/usr/bin/env perl\nuse strict;\nuse warnings FATAL => 'all';\nmy $script_version = \"0.1\";\n\nmy $PG_SIZE = 16_384; # InnoDB defaults to 16k pages, change if needed.\nmy ($cur_idx, $cur_tbl);\nmy (%idx_stats, %tbl_stats);\nmy ($max_tbl_len, $max_idx_len) = (0, 0);\nwhile ( my $line = <> ) {\n   if ( my ($t, $i) = $line =~ m/table: (.*), index: (.*), space id:/ ) {\n      $t =~ s!/!.!;\n      $cur_tbl = $t;\n      $cur_idx = $i;\n      if ( length($i) > $max_idx_len ) {\n         $max_idx_len = length($i);\n      }\n      if ( length($t) > $max_tbl_len ) {\n         $max_tbl_len = length($t);\n      }\n   }\n   elsif ( my ($kv, $lp, $sp) = $line =~ m/key vals: (\\d+), \\D*(\\d+), \\D*(\\d+)/ ) {\n      @{$idx_stats{$cur_tbl}->{$cur_idx}}{qw(est_kv est_lp est_sp)} = ($kv, $lp, $sp);\n      $tbl_stats{$cur_tbl}->{est_kv} += $kv;\n      $tbl_stats{$cur_tbl}->{est_lp} += $lp;\n      $tbl_stats{$cur_tbl}->{est_sp} += $sp;\n   }\n    elsif ( my ($l, $pages, $bytes) = $line =~ m/(?:level (\\d+)|leaf) pages:.*pages=(\\d+), data=(\\d+) bytes/ ) {\n      $l ||= 0;\n      $idx_stats{$cur_tbl}->{$cur_idx}->{real_pages} += $pages;\n      $idx_stats{$cur_tbl}->{$cur_idx}->{real_bytes} += $bytes;\n      $tbl_stats{$cur_tbl}->{real_pages} += $pages;\n      $tbl_stats{$cur_tbl}->{real_bytes} += $bytes;\n   }\n}\n\nmy $hdr_fmt = \"%${max_tbl_len}s %${max_idx_len}s %9s %10s %10s\\n\";\nmy @headers = qw(TABLE INDEX TOT_PAGES FREE_PAGES PCT_FULL);\nprintf $hdr_fmt, @headers;\n\nmy $row_fmt = \"%${max_tbl_len}s %${max_idx_len}s %9d %10d %9.1f%%\\n\";\nforeach my $t ( sort keys %tbl_stats ) {\n  my $tbl = $tbl_stats{$t};\n  printf $row_fmt, $t, \"\", $tbl->{est_sp}, $tbl->{est_sp} - $tbl->{real_pages},\n      $tbl->{real_bytes} / ($tbl->{real_pages} * $PG_SIZE) * 100;\n   foreach my $i ( sort keys %{$idx_stats{$t}} ) {\n      my $idx = $idx_stats{$t}->{$i};\n      printf $row_fmt, $t, $i, $idx->{est_sp}, $idx->{est_sp} - $idx->{real_pages},\n         $idx->{real_bytes} / ($idx->{real_pages} * $PG_SIZE) * 100;\n   }\n}\n
"},{"location":"analyze-table-statistics.html#sample-script-output","title":"Sample script output","text":"

The output of the above Perl script, when run against the sample shown in the previously mentioned blog post, will appear as follows:

Expected output
      TABLE           INDEX TOT_PAGES FREE_PAGES   PCT_FULL\nart.link_out104                    832383      38561      86.8%\nart.link_out104         PRIMARY    498304         49      91.9%\nart.link_out104       domain_id     49600       6230      76.9%\nart.link_out104     domain_id_2     26495       3339      89.1%\nart.link_out104 from_message_id     28160        142      96.3%\nart.link_out104    from_site_id     38848       4874      79.4%\nart.link_out104   revert_domain    153984      19276      71.4%\nart.link_out104    site_message     36992       4651      83.4%\n

The columns are the table and index, followed by the total number of pages in that index, the number of pages not actually occupied by data, and the number of bytes of real data as a percentage of the total size of the pages of real data. The first line in the above output, in which the INDEX column is empty, is a summary of the entire table.

"},{"location":"apt-download-deb.html","title":"Install Percona XtraBackup 8.0 using downloaded DEB packages","text":"

Download DEB packages of the desired series for your architecture from Percona Product Downloads.

The following example downloads Percona XtraBackup 8.0.26-18 release package for Ubuntu 20.04:

$ wget https://downloads.percona.com/downloads/Percona-XtraBackup-LATEST/Percona-XtraBackup-8.0.26-18/binary/debian/focal/x86_64/percona-xtrabackup-80_8.0.26-18-1.focal_amd64.deb\n

Install Percona XtraBackup by using dpkg. Run this command as root or use the sudo command:

$ sudo dpkg -i percona-xtrabackup-80_8.0.26-18-1.focal_amd64.deb\n

Warning

When installing packages manually like this, resolve all the dependencies and install missing packages yourself.

"},{"location":"apt-files.html","title":"Files in the DEB package built for Percona XtraBackup 8.0","text":"

The following tables show what data each DEB package contains.

Package Contains percona-xtrabackup-80 The latest Percona XtraBackup GA binaries and associated files percona-xtrabackup-dbg-80 The debug symbols for binaries in percona-xtrabackup-80 percona-xtrabackup-test-80 The test suite for Percona XtraBackup percona-xtrabackup The older version of the Percona XtraBackup"},{"location":"apt-pinning.html","title":"Apt pinning the Percona XtraBackup 8.0 packages","text":"

In some cases you might need to pin the selected packages to avoid the upgrades from the distribution repositories.

The pinning takes place in the preference file. To pin a package, set the Pin-Priority to higher numbers.

Make a new file /etc/apt/preferences.d/00percona.pref. For example, add the following to the preference file:

Package:\nPin: release o=Percona Development Team\nPin-Priority: 1001\n

For more information about the pinning, check the official debian wiki.

"},{"location":"apt-repo.html","title":"Use an APT repository to install Percona XtraBackup 8.0","text":"

Ready-to-use packages are available from the Percona XtraBackup software repositories and the download page.

Specific information on the supported platforms, products, and versions is described in Percona Release Lifecycle Overview.

Important

To prevent intermittent backup failures, update the curl utility in Debian 10.

"},{"location":"apt-repo.html#install-percona-xtrabackup-through-percona-release","title":"Install Percona XtraBackup through percona-release","text":"

Percona XtraBackup, like many other Percona products, is installed with the percona-release package configuration tool.

  1. Download a DEB package for percona-release the repository packages from Percona web:

    $ wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb\n
  2. Install the downloaded package with dpkg. To do that, run the following commands as root or with sudo: dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb

    Once you install this package the Percona repositories should be added. You can check the repository setup in the /etc/apt/sources.list.d/percona-release.list file.

  3. 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.

  4. Refresh the local cache to update the package information:

    $ sudo apt update\n
  5. Install the percona-xtrabackup-80 package:

    $ sudo apt install percona-xtrabackup-80\n
  6. To decompress backups made using LZ4 or ZSTD compression algorithm, install the corresponding package:

    Install the lz4 packageInstall the zstd package
    $ sudo apt install lz4\n
    $ sudo apt install zstd\n

Note

For AppArmor profile information, see Working with AppArmor.

See also

To install Percona XtraBackup using downloaded deb packages, see Install Percona XtraBackup 8.0.

To uninstall Percona XtraBackup, see Uninstall Percona XtraBackup 8.0

"},{"location":"apt-uninstall-xtrabackup.html","title":"Uninstall Percona XtraBackup 8.0 on Debian and Ubuntu","text":"

To completely uninstall Percona XtraBackup, remove all the installed packages:

$ sudo apt remove percona-xtrabackup-80\n
"},{"location":"binaries-overiew.html","title":"Percona XtraBackup binaries overview","text":"

Percona XtraBackup is a set of the following binaries:

The recommended way to take the backup is by using the xtrabackup script. For more information on script options, see xtrabackup.

"},{"location":"binaries-overview.html","title":"Percona XtraBackup binaries overview","text":"

Percona XtraBackup is a set of the following binaries:

The recommended way to take the backup is by using the xtrabackup script. For more information on script options, see xtrabackup.

"},{"location":"binary-tarball-names.html","title":"Binary tarball file names available","text":"

Download the binary tarballs from Percona Product Downloads.

The following table lists the tarball types available in Linux - Generic. Select the Percona XtraBackup 8.0 version, the software or the operating system, and the type of tarball for your installation. Binary tarballs support all distributions.

After you have downloaded the binary tarballs, extract the tarball in the file location of your choice.

Type Name Operating systems Description Full percona-xtrabackup--Linux.x86_64.glibc2.12.tar.gz Built for CentOS 6 Contains binary files, libraries, test files, and debug symbols Minimal percona-xtrabackup--Linux.x86_64.glibc2.12-minimal.tar.gz Built for CentOS 6 Contains binary files, and libraries but does not include test files, or debug symbols Full percona-xtrabackup--Linux.x86_64.glibc2.17.tar.gz Compatible with any operating system except for CentOS 6 Contains binary files, libraries, test files, and debug symbols Minimal percona-xtrabackup--Linux.x86_64.glibc2.17-minimal.tar.gz Compatible with any operating system except for CentOS 6 Contains binary files, and libraries but does not include test files, or debug symbols

Select a different software, such as Ubuntu 20.04 (Focal Fossa), for a tarball for that operating system. You can download the packages together or separately.

"},{"location":"binary-tarball.html","title":"Install Percona XtraBackup 8.0 from a binary tarball","text":"

Binary tarballs contain precompiled executable files, libraries, and other dependencies and are compressed tar archives. Extract the binary tarballs to any path.

You can download the binary tarballs from the Linux - Generic section on the Percona Product Downloads.

The following command is an example of downloading the full tarball for Linux/Generic:

$ wget https://downloads.percona.com/downloads/Percona-XtraBackup-LATEST/Percona-XtraBackup-8.0.23-16/binary/tarball/percona-xtrabackup-8.0.23-16-Linux-x86_64.glibc2.17.tar.gz\n
"},{"location":"compile-xtrabackup.html","title":"Compile and install Percona XtraBackup 8.0 from source","text":"

The following instructions install Percona XtraBackup 8.0.

"},{"location":"compile-xtrabackup.html#1-install-percona-xtrabackup-from-the-git-source-tree","title":"1. Install Percona XtraBackup from the Git Source Tree","text":"

Percona uses the Github revision control system for development. To build the latest Percona Server for MySQL from the source tree, you will need git installed on your system.

You can now fetch the latest Percona XtraBackup 8.0 sources:

$ git clone https://github.com/percona/percona-xtrabackup.git\n$ cd percona-xtrabackup\n$ git checkout 8.0\n$ git submodule update --init --recursive\n
"},{"location":"compile-xtrabackup.html#2-installation-prerequisites","title":"2. Installation prerequisites","text":"

The following packages and tools must be installed to compile Percona XtraBackup from source. These might vary from system to system.

Important

To build **Percona XtraBackup 8.0 from source, you must use cmake version 3. To check which version is currently installed, run cmake --version at a command prompt. If the version is not 3, install cmake3.

This cmake version may be available in your distribution as a separate package cmake3. For more information, see cmake.org

Debian or Ubuntu using aptCentOS or Red Hat using yum
sudo apt install bison pkg-config cmake devscripts debconf \\\ndebhelper automake bison ca-certificates libprocps-dev \\\nlibcurl4-openssl-dev cmake debhelper libaio-dev \\\nlibncurses-dev libssl-dev libtool libz-dev libgcrypt-dev libev-dev libprocps-dev \\\nlsb-release build-essential rsync libdbd-mysql-perl \\\nlibnuma1 socat librtmp-dev libtinfo5 vim-common \\\nliblz4-tool liblz4-1 liblz4-dev zstd python-docutils qpress\n

To install the man pages, install the python3-sphinx package first:

$ sudo apt install python3-sphinx\n

Percona Xtrabackup requires GCC version 5.3 or higher. If the version of GCC installed on your system is lower then you may need to install and enable the Developer Toolset on RPM-based distributions to make sure that you use the latest GCC compiler and development tools. Then, install cmake and other dependencies:

$ sudo yum install cmake openssl-devel libaio libaio-devel automake autoconf \\\nbison libtool ncurses-devel libgcrypt-devel libev-devel libcurl-devel zlib-devel \\\nzstd vim-common procps-ng-devel\n

To install the man pages, install the python3-sphinx package first:

$ sudo yum install python3-sphinx\n
"},{"location":"compile-xtrabackup.html#3-generate-the-build-pipeline","title":"3. Generate the build pipeline","text":"

At this step, you have cmake run the commands in the CMakeList.txt file to generate the build pipeline, i.e., a native build environment that will be used to compile the source code).

  1. Change to the directory where you cloned the Percona XtraBackup repository

    $ cd percona-xtrabackup\n
  2. Create a directory to store the compiled files and then change to that directory:

    $ mkdir build\n$ cd build\n
  3. Run cmake or cmake3. In either case, the options you need to use are the same.

Note

You can build Percona XtraBackup with man pages but this requires python-sphinx package which isn\u2019t available from that main repositories for every distribution. If you installed the python-sphinx package you need to remove the -DWITH_MAN_PAGES=OFF from previous command.

$ cmake -DWITH_BOOST=PATH-TO-BOOST-LIBRARY -DDOWNLOAD_BOOST=ON \\\n-DBUILD_CONFIG=xtrabackup_release -DWITH_MAN_PAGES=OFF -B ..\n
"},{"location":"compile-xtrabackup.html#parameter-information","title":"Parameter Information","text":"Parameter Description -DWITH_BOOST For the -DWITH_BOOST parameter, specify the name of a directory to download the boost library to. This directory is created automatically in your current directory. -DWITH_MAN_PAGES To build Percona XtraBackup man pages, use ON or remove this parameter from the command line (it is ON by default). To install the man pages, install the python3-sphinx package first. -B (--build) Percona XtraBackup is configured to forbid generating the build pipeline for make in the same directory where you store your sources. The -B parameter refers to the directory that contains the source code. In this example, we use the relative path to the parent directory (..).

Important

CMake Error at CMakeLists.txt:367 (MESSAGE): Please do not build in-source. Out-of source builds are highly recommended: you can have multiple builds for the same source, and there is an easy way to do cleanup, simply remove the build directory (note that \u2018make clean\u2019 or \u2018make distclean\u2019 does not work)

You can force in-source build by invoking cmake with -DFORCE_INSOURCE_BUILD=1.

"},{"location":"compile-xtrabackup.html#4-compile-the-source-code","title":"4. Compile the source code","text":"

To compile the source code in your build directory, use the make command.

  1. Change to the build directory (created at Step 2: Generating the build pipeline).

  2. Run the make command. This command may take a long time to complete.

    $ make\n

    To use all CPU threads and make compilation faster please use:

    $ make -j$(nproc --all)\n
"},{"location":"compile-xtrabackup.html#5-install-on-the-target-system","title":"5. Install on the target system","text":"

The following command installs all Percona XtraBackup binaries xtrabackup and tests to default location on the target system: /usr/local/xtrabackup.

Run make install to install Percona XtraBackup to the default location.

$ sudo make install\n
"},{"location":"compile-xtrabackup.html#install-to-a-non-default-location","title":"Install to a non-default location","text":"

You may use the DESTDIR parameter with make install to install Percona XtraBackup to another location. Make sure that the effective user is able to write to the destination you choose.

$ sudo make DESTDIR=<DIR_NAME> install\n

In fact, the destination directory is determined by the installation layout (-DINSTALL_LAYOUT) that cmake applies (see Step 2: Generating the build pipeline). In addition to the installation directory, this parameter controls a number of other destinations that you can adjust for your system.

By default, this parameter is set to STANDALONE, which implies the installation directory to be /usr/local/xtrabackup.

See also

MySQL Documentation: -DINSTALL_LAYOUT

"},{"location":"compile-xtrabackup.html#6-run-percona-xtrabackup","title":"6. Run Percona XtraBackup","text":"

After Percona XtraBackup is installed on your system, you may run it by using the full path to the xtrabackup command:

$ /usr/local/xtrabackup/bin/xtrabackup\n

Update your PATH environment variable if you would like to use the command on the command line directly.

$# Setting $PATH on the command line\n$ PATH=$PATH:/usr/local/xtrabackup/bin/xtrabackup\n\n$# Run xtrabackup directly\n$ xtrabackup\n

Alternatively, you may consider placing a soft link (using ln -s) to one of the locations listed in your PATH environment variable.

To view the documentation with man, update the MANPATH variable.

"},{"location":"configure-xtrabackup.html","title":"Configure xtrabackup","text":"

All the xtrabackup configuration is done through options, which behave exactly like standard MySQL program options: they can be specified either at the command-line, or through a file such as /etc/my.cnf.

The xtrabackup binary reads the [mysqld] and [xtrabackup] sections from any configuration files, in that order. That is so that it can read its options from your existing MySQL installation, such as the datadir or some of the InnoDB options. If you want to override these, just specify them in the [xtrabackup] section, and because it is read later, it will take precedence.

You don\u2019t need to put any configuration in your my.cnf if you don\u2019t want to. You can simply specify the options on the command-line. Normally, the only thing you might find convenient to place in the [xtrabackup] section of your my.cnf file is the target_dir option to default the directory in which the backups will be placed, for example:

[xtrabackup]\ntarget_dir = /data/backups/mysql/\n

This manual will assume that you do not have any file-based configuration for xtrabackup, so it will always show command-line options being used explicitly. Please see the option and variable reference for details on all the configuration options.

The xtrabackup binary does not accept exactly the same syntax in the my.cnf file as the mysqld server binary does. For historical reasons, the mysqld server binary accepts parameters with a --set-variable=<variable>=<value> syntax, which xtrabackup does not understand. If your my.cnf file has such configuration directives, you should rewrite them in the --variable=value syntax.

"},{"location":"configure-xtrabackup.html#system-configuration-and-nfs-volumes","title":"System configuration and NFS volumes","text":"

The xtrabackup tool requires no special configuration on most systems. However, the storage where the --target-dir is located must behave properly when fsync() is called. In particular, we have noticed that if you mount the NFS volume without the sync option the NFS volume does not sync the data. As a result, if you back up to an NFS volume mounted with the async option, and then try to prepare the backup from a different server that also mounts that volume, the data might appear to be corrupt. You can use the sync mount option to avoid this problem.

"},{"location":"copyright-and-licensing-information.html","title":"Copyright and licensing information","text":""},{"location":"copyright-and-licensing-information.html#documentation-licensing","title":"Documentation licensing","text":"

Percona XtraBackup documentation is (C)2009-2023 Percona LLC and/or its affiliates and is distributed under the Creative Commons Attribution 4.0 International License.

"},{"location":"create-compressed-backup.html","title":"Create a compressed backup","text":"

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

Note

Starting with Percona XtraBackup 8.0.31-24 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.

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

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\n$ sudo apt update\n$ sudo apt install qpress\n

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\n

lz4

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

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

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\n

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\n

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 \\\n--target-dir=/data/compressed/\n
Expected output
...\n170223 13:00:38 [01] Compressing ./test/sbtest1.frm to /tmp/compressed/test/sbtest1.frm.qp\n170223 13:00:38 [01]        ...done\n170223 13:00:38 [01] Compressing ./test/sbtest2.frm to /tmp/compressed/test/sbtest2.frm.qp\n170223 13:00:38 [01]        ...done\n...\n170223 13:00:39 [00] Compressing xtrabackup_info\n170223 13:00:39 [00]        ...done\nxtrabackup: Transaction log of lsn (9291934) to (9291934) was copied.\n170223 13:00:39 completed OK!\n

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

"},{"location":"create-full-backup.html","title":"Create a full backup","text":"

To create a backup, run xtrabackup with the --backup option. You also need to specify the --target-dir option, which is where the backup will be stored, if the InnoDB data or log files are not stored in the same directory, you might need to specify the location of those, too. If the target directory does not exist, xtrabackup creates it. If the directory does exist and is empty, xtrabackup will succeed.

xtrabackup will not overwrite existing files, it will fail with operating system error 17, file exists.

To start the backup process run:

$ xtrabackup --backup --target-dir=/data/backups/\n

This will store the backup at /data/backups/. If you specify a relative path, the target directory will be relative to the current directory.

During the backup process, you should see a lot of output showing the data files being copied, as well as the log file thread repeatedly scanning the log files and copying from it. Here is an example that shows the log thread scanning the log in the background, and a file copying thread working on the ibdata1 file:

Expected output
160906 10:19:17 Finished backing up non-InnoDB tables and files\n160906 10:19:17 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...\nxtrabackup: The latest check point (for incremental): '62988944'\nxtrabackup: Stopping log copying thread.\n.160906 10:19:18 >> log scanned up to (137343534)\n160906 10:19:18 Executing UNLOCK TABLES\n160906 10:19:18 All tables unlocked\n160906 10:19:18 Backup created in directory '/data/backups/'\n160906 10:19:18 [00] Writing backup-my.cnf\n160906 10:19:18 [00]        ...done\n160906 10:19:18 [00] Writing xtrabackup_info\n160906 10:19:18 [00]        ...done\nxtrabackup: Transaction log of lsn (26970807) to (137343534) was copied.\n160906 10:19:18 completed OK!\n

The last thing you should see is something like the following, where the value of the <LSN> will be a number that depends on your system:

$ xtrabackup: Transaction log of lsn (<SLN>) to (<LSN>) was copied.\n

Note

Log copying thread checks the transactional log every second to see if there were any new log records written that need to be copied, but there is a chance that the log copying thread might not be able to keep up with the amount of writes that go to the transactional logs, and will hit an error when the log records are overwritten before they could be read.

After the backup is finished, the target directory will contain files such as the following, assuming you have a single InnoDB table test.tbl1 and you are using MySQL\u2019s innodb_file_per_table option:

$ ls -lh /data/backups/\n

The result should look like this:

Expected output
total 182M\ndrwx------  7 root root 4.0K Sep  6 10:19 .\ndrwxrwxrwt 11 root root 4.0K Sep  6 11:05 ..\n-rw-r-----  1 root root  387 Sep  6 10:19 backup-my.cnf\n-rw-r-----  1 root root  76M Sep  6 10:19 ibdata1\ndrwx------  2 root root 4.0K Sep  6 10:19 mysql\ndrwx------  2 root root 4.0K Sep  6 10:19 performance_schema\ndrwx------  2 root root 4.0K Sep  6 10:19 sbtest\ndrwx------  2 root root 4.0K Sep  6 10:19 test\ndrwx------  2 root root 4.0K Sep  6 10:19 world2\n-rw-r-----  1 root root  116 Sep  6 10:19 xtrabackup_checkpoints\n-rw-r-----  1 root root  433 Sep  6 10:19 xtrabackup_info\n-rw-r-----  1 root root 106M Sep  6 10:19 xtrabackup_logfile\n

The backup can take a long time, depending on how large the database is. It is safe to cancel at any time, because xtrabackup does not modify the database.

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

"},{"location":"create-gtid-replica.html","title":"How to create a new (or repair a broken) GTID-based replica","text":"

MySQL 5.6 introduced the Global Transaction ID (GTID) support in replication. Percona XtraBackup automatically stores the GTID value in the xtrabackup_binlog_info when doing the backup of MySQL and Percona Server for MySQL 5.7 with the GTID mode enabled. This information can be used to create a new (or repair a broken) GTID-based replica.

"},{"location":"create-gtid-replica.html#1-take-a-backup-from-any-server-on-the-replication-environment-source-or-replica","title":"1. Take a backup from any server on the replication environment, source or replica","text":"

The following command takes a backup and saves it in the /data/backups/$TIMESTAMP folder:

$ xtrabackup --backup --target-dirs=/data/backups/\n

In the destination folder, there will be a file with the name xtrabackup_binlog_info. This file contains both binary log coordinates and the GTID information.

$ cat xtrabackup_binlog_info\n
The result could look like this:

Expected output
mysql-bin.000002    1232        c777888a-b6df-11e2-a604-080027635ef5:1-4\n

That information is also printed by xtrabackup after taking the backup:

Expected output
xtrabackup: MySQL binlog position: filename 'mysql-bin.000002', position 1232, GTID of the last change 'c777888a-b6df-11e2-a604-080027635ef5:1-4'\n
"},{"location":"create-gtid-replica.html#2-prepare-the-backup","title":"2. Prepare the backup","text":"

The backup will be prepared with the following command on the Source:

$ xtrabackup --prepare --target-dir=/data/backup\n

You need to select the path where your snapshot has been taken, for example /data/backups/2013-05-07_08-33-33. If everything is ok you should get the same OK message. Now, the transaction logs are applied to the data files, and new ones are created: your data files are ready to be used by the MySQL server.

"},{"location":"create-gtid-replica.html#3-move-the-backup-to-the-destination-server","title":"3. Move the backup to the destination server","text":"

Use rsync or scp to copy the data to the destination server. If you are synchronizing the data directly to the already running replica\u2019s data directory it is advised to stop the MySQL server there.

$ rsync -avprP -e ssh /path/to/backupdir/$TIMESTAMP NewSlave:/path/to/mysql/\n

After you copy the data over, make sure MySQL has proper permissions to access them.

$ chown mysql:mysql /path/to/mysql/datadir\n
"},{"location":"create-gtid-replica.html#4-configure-and-start-replication","title":"4. Configure and start replication","text":"

Set the gtid_purged variable to the GTID from xtrabackup_binlog_info. Then, update the information about the source node and, finally, start the replica. Run the following commands on the replica if you are using a version before 8.0.22:

# Using the mysql shell\n> SET SESSION wsrep_on = 0;\n> RESET MASTER;\n> SET SESSION wsrep_on = 1;\n> SET GLOBAL gtid_purged='<gtid_string_found_in_xtrabackup_binlog_info>';\n> CHANGE MASTER TO\n             MASTER_HOST=\"$masterip\",\n             MASTER_USER=\"repl\",\n             MASTER_PASSWORD=\"$slavepass\",\n             MASTER_AUTO_POSITION = 1;\n> START SLAVE;\n

If you are using version 8.0.22 or later, use START REPLICA instead of START SLAVE. START SLAVE is deprecated as of that release. If you are using version 8.0.21 or earlier, use START SLAVE.

If you are using a version 8.0.23 or later, run the following commands:

# Using the mysql shell\n> SET SESSION wsrep_on = 0;\n> RESET MASTER;\n> SET SESSION wsrep_on = 1;\n> SET GLOBAL gtid_purged='<gtid_string_found_in_xtrabackup_binlog_info>';\n> CHANGE REPLICATION SOURCE TO\n             SOURCE_HOST=\"$masterip\",\n             SOURCE_USER=\"repl\",\n             SOURCE_PASSWORD=\"$slavepass\",\n             SOURCE_AUTO_POSITION = 1;\n> START REPLICA;\n

If you are using version 8.0.23 or later, use CHANGE_REPLICATION_SOURCE_TO and the appropriate options. CHANGE_MASTER_TO is deprecated as of that release.

Note

The example above is applicable to Percona XtraDB Cluster. The wsrep_on variable is set to 0 before resetting the source (RESET MASTER). The reason is that Percona XtraDB Cluster will not allow resetting the source if wsrep_on=1.

"},{"location":"create-gtid-replica.html#5-check-the-replication-status","title":"5. Check the replication status","text":"

The following command returns the replica status:

mysql> SHOW REPLICA STATUS\\G\n
The results should be similar to the following:

Expected output
[..]\nSlave_IO_Running: Yes\nSlave_SQL_Running: Yes\n[...]\nRetrieved_Gtid_Set: c777888a-b6df-11e2-a604-080027635ef5:5\nExecuted_Gtid_Set: c777888a-b6df-11e2-a604-080027635ef5:1-5\n

Note

The command SHOW SLAVE STATUS is deprecated. Use SHOW REPLICA STATUS.

We can see that the replica has retrieved a new transaction with number 5, so transactions from 1 to 5 are already on this slave.

We have created a new replica in our GTID based replication environment.

"},{"location":"create-incremental-backup.html","title":"Create an incremental backup","text":"

xtrabackup supports incremental backups, which means that they can copy only all the data that has changed since the last backup.

Note

Incremental backups on the MyRocks storage engine do not determine if an earlier full backup or incremental backup contains the same files. Percona XtraBackup copies all the MyRocks files each time it takes a backup.

You can perform many incremental backups between each full backup, so you can set up a backup process such as a full backup once a week and an incremental backup every day, or full backups every day and incremental backups every hour.

Incremental backups work because each InnoDB page contains a log sequence number, or LSN. The LSN is the system version number for the entire database. Each page\u2019s LSN shows how recently it was changed.

An incremental backup copies each page which LSN is newer than the previous incremental or full backup\u2019s LSN. An algorithm finds the pages that match the criteria. The algorithm reads the data pages and checks the page LSN.

"},{"location":"create-incremental-backup.html#use-the-changed-page-tracking-algorithm","title":"Use the changed page tracking algorithm","text":"

Percona XtraBackup 8.0.30 removes the algorithm that used the changed page tracking feature in Percona Server for MySQL. Percona Server for MySQL 8.0.27 deprecated the changed page tracking feature.

With PXB 8.0.27 or earlier, another algorithm enabled the Percona Server for MySQL changed page tracking feature. The algorithm generates a bitmap file. The xtrabackup binary uses that bitmap file to read only those pages needed for the incremental backup. This method potentially saves resources. The backup enables the algorithm by default if the xtrabackup binary discovers the bitmap file. You can override the algorithm with --incremental-force-scan which forces a read of all pages even if the bitmap file is available.

"},{"location":"create-incremental-backup.html#create-an-incremental-backup_1","title":"Create an incremental backup","text":"

To make an incremental backup, begin with a full backup as usual. The xtrabackup binary writes a file called xtrabackup_checkpoints into the backup\u2019s target directory. This file contains a line showing the to_lsn, which is the database\u2019s LSN at the end of the backup. Create the full backup with a following command:

$ xtrabackup --backup --target-dir=/data/backups/base\n

If you look at the xtrabackup_checkpoints file, you should see similar content depending on your LSN nuber:

Expected output
backup_type = full-backuped\nfrom_lsn = 0\nto_lsn = 1626007\nlast_lsn = 1626007\ncompact = 0\nrecover_binlog_info = 1\n

Now that you have a full backup, you can make an incremental backup based on it. Use the following command:

$ xtrabackup --backup --target-dir=/data/backups/inc1 \\\n--incremental-basedir=/data/backups/base\n

The /data/backups/inc1/ directory should now contain delta files, such as ibdata1.delta and test/table1.ibd.delta. These represent the changes since the LSN 1626007. If you examine the xtrabackup_checkpoints file in this directory, you should see similar content to the following:

Expected output
backup_type = incremental\nfrom_lsn = 1626007\nto_lsn = 4124244\nlast_lsn = 4124244\ncompact = 0\nrecover_binlog_info = 1\n

from_lsn is the starting LSN of the backup and for incremental it has to be the same as to_lsn (if it is the last checkpoint) of the previous/base backup.

It\u2019s now possible to use this directory as the base for yet another incremental backup:

$ xtrabackup --backup --target-dir=/data/backups/inc2 \\\n--incremental-basedir=/data/backups/inc1\n

This folder also contains the xtrabackup_checkpoints:

Expected output
backup_type = incremental\nfrom_lsn = 4124244\nto_lsn = 6938371\nlast_lsn = 7110572\ncompact = 0\nrecover_binlog_info = 1\n

Note

In this case you can see that there is a difference between the to_lsn (last checkpoint LSN) and last_lsn (last copied LSN), this means that there was some traffic on the server during the backup process.

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

"},{"location":"create-individual-partition-backup.html","title":"Create an individual partitions backup","text":"

Percona XtraBackup lets you back up individual partitions because partitions are regular tables with specially formatted names. The only requirement for this feature is to enable the innodb_file_per_table option on the server.

There is one caveat about using this kind of backup: you can not copy back the prepared backup. Restoring partial backups should be done by importing the tables.

There are three ways of specifying which part of the whole data will be backed up: regular expressions ( --tables), enumerating the tables in a file (--tables) or providing a list of databases (--databases).

The regular expression provided to this option will be matched against the fully qualified database name and table name, in the form of database-name.table-name.

If the partition 0 is not backed up, Percona XtraBackup cannot generate a .cfg file. MySQL 8.0 stores the table metadata in partition 0.

For example, this operation takes a back-up of the partition p4 from the table name located in the database imdb:

$ xtrabackup --tables=^imdb[.]name#p#p4 --backup\n

If partition 0 is not backed up, the following errors may occur:

The error message
xtrabackup: export option not specified\nxtrabackup: error: cannot find dictionary record of table imdb/name#p#p4\n

Note that this option is passed to xtrabackup --tables and is matched against each table of each database, the directories of each database will be created even if they are empty.

"},{"location":"create-partial-backup.html","title":"Create a partial backup","text":"

xtrabackup supports taking partial backups when the innodb_file_per_table option is enabled. There are three ways to create partial backups:

  1. matching the tables names with a regular expression

  2. providing a list of table names in a file

  3. providing a list of databases

Warning

Do not copy back the prepared backup.

Restoring partial backups should be done by importing the tables, not by using the \u2013copy-back option. It is not recommended to run incremental backups after running a partial backup.

Although there are some scenarios where restoring can be done by copying back the files, this may lead to database inconsistencies in many cases and it is not a recommended way to do it.

For the purposes of this manual page, we will assume that there is a database named test which contains tables named t1 and t2.

Warning

If any of the matched or listed tables is deleted during the backup, xtrabackup will fail.

There are multiple ways of specifying which part of the whole data is backed up:

"},{"location":"create-partial-backup.html#the-tables-option","title":"The \u2013-tables option","text":"

The first method involves the xtrabackup \u2013tables option. The option\u2019s value is a regular expression that is matched against the fully-qualified database name and table name using the databasename.tablename format.

To back up only tables in the test database, use the following command:

$ xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/data/backups/ \\\n--tables=\"^test[.].*\"\n

To back up only the test.t1 table, use the following command:

$ xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/data/backups/ \\\n--tables=\"^test[.]t1\"\n
"},{"location":"create-partial-backup.html#the-tables-file-option","title":"The -\u2013tables-file option","text":"

The --tables-file option specifies a file that can contain multiple table names, one table name per line in the file. Only the tables named in the file will be backed up. Names are matched exactly, case-sensitive, with no pattern or regular expression matching. The table names must be fully-qualified in databasename.tablename format.

$ echo \"mydatabase.mytable\" > /tmp/tables.txt\n$ xtrabackup --backup --tables-file=/tmp/tables.txt\n
"},{"location":"create-partial-backup.html#the-databases-and-databases-file-options","title":"The --databases and -\u2013databases-file options","text":"

The ` \u2013databases` option accepts a space-separated list of the databases and tables to backup in the databasename[.tablename] format. In addition to this list, make sure to specify the mysql, sys, and

performance_schema databases. These databases are required when restoring the databases using xtrabackup \u2013copy-back.

Note

Tables processed during the \u2013prepare step may also be added to the backup even if they are not explicitly listed by the parameter if they were created after the backup started.

$ xtrabackup --databases='mysql sys performance_schema test ...'\n
"},{"location":"create-partial-backup.html#the-databases-file-option","title":"The --databases-file option","text":"

The \u2013databases-file option specifies a file that can contain multiple databases and tables in the databasename[.tablename] format, one element name per line in the file. Names are matched exactly, case-sensitive, with no pattern or regular expression matching.

Note

Tables processed during the \u2013prepare step may also be added to the backup even if they are not explicitly listed by the parameter if they were created after the backup started.

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

"},{"location":"dictionary-cache.html","title":"Dictionary cache","text":"

Percona XtraBackup is based on how crash recovery works. Percona XtraBackup copies the InnoDB data files, which results in data that is internally inconsistent; then the prepare phase performs crash recovery on the files to make a consistent, usable database again.

The --prepare phase has the following operations:

As a physical operation, the changes from the redo log modifications are applied to a page. In the redo log operation, there is no concept of row or transaction. The redo apply operation does not make the database consistent with a transaction. An uncommitted transaction can be flushed or written to the redo log by the server. Percona XtraBackup applies changes recorded in the redo log.

Percona XtraBackup physically modifies a specific offset of a page within a tablespace (IBD file) when applying a redo log.

As a logical operation, Percona XtraBackup applies the undo log on a specific row. When the redo log completes, XtraBackup uses the undo log to roll back changes from uncommitted transactions during the backup.

"},{"location":"dictionary-cache.html#undo-log","title":"Undo log","text":"

There are two types of undo log records:

An undo log record contains a table_id. Percona XtraBackup uses this table_id to find the table definition, and then uses that information to parse the records on an index page. The transaction rollback reads the undo log records and applies the changes.

After initializing the data dictionary engine and the data dictionary cache, the storage engine can request the table_id and uses this ID to fetch the table schema. An index search tuple (key) is created from the table schema and key fields from the undo log record. The server finds the record using the search tuple (key) and performs the undo operation.

For example, InnoDB uses the table_id (also known as the se_private_id) for a table definition. Percona XtraBackup does not behave like a server and does not have access to the data dictionary. XtraBackup initializes the InnoDB engine and uses the InnoDB table object (dict_table_t) when needed. XtraBackup relies on Serialized Dictionary Information (SDI) that is stored in the tablespace. SDI is a JSON representation of a table.

"},{"location":"dictionary-cache.html#version-changes","title":"Version changes","text":"

Prior to Percona XtraBackup 8.0.33-28, XtraBackup loads the SDI from every .IBD file and all tables into cache as non-evictable. Making the tables non-evictable essentially disables the LRU cache. Every table remains in memory until the operation ends.

This method has the following issues:

Percona XtraBackup 8.0.33-28 implements a new design and tables are loaded as evictable. XtraBackup scans the B-tree index of the data dictionary tables mysql.indexes and mysql.index_partitions to establish a relationship between the table_id and the tablespace(space_id). XtraBackup uses this relationship during transaction rollback. XtraBackup does not load user tables unless there is a transaction rollback on them.

A background thread or a Percona XtraBackup main thread handles the cache eviction when the cache size limit is reached.

This new design provides the following benefits during the --prepare phase:

"},{"location":"docker.html","title":"Run Percona XtraBackup 8.0 in a Docker container","text":"

Docker allows you to run applications in a lightweight unit called a container.

You can run Percona XtraBackup in a Docker container without installing the product. All required libraries are available in the container. Being a lightweight execution environment, Docker containers enable creating configurations where each program runs in a separate container. You may run Percona Server for MySQL in one container and Percona XtraBackup in another. Docker images offer a range of options.

Create a Docker container based on a Docker image. Docker images for Percona XtraBackup are hosted publicly on Docker Hub.

$ sudo docker create ... percona/percona-xtrabackup --name xtrabackup ...\n
"},{"location":"docker.html#scope-of-this-section","title":"Scope of this section","text":"

This section demonstrates how to back up data on a Percona Server for MySQL running in another Dockers container.

"},{"location":"docker.html#1-install-docker","title":"1. Install Docker","text":"

Your operating system may already provide a package for docker. However, the versions of Docker provided by your operating system are likely to be outdated.

Use the installation instructions for your operating system available from the Docker site to set up the latest version of docker.

"},{"location":"docker.html#2-connect-to-a-percona-server-for-mysql-container","title":"2. Connect to a Percona Server for MySQL container","text":"

Percona XtraBackup works in combination with a database server. When running a Docker container for Percona XtraBackup, you can make backups for a database server either installed on the host machine or running in a separate Docker container.

To set up a database server on a host machine or in Docker container, follow the documentation of the supported product that you intend to use with Percona XtraBackup.

See also

Docker volumes as container persistent data storage

More information about containers

$ sudo docker run -d --name percona-server-mysql \\\n-e MYSQL_ROOT_PASSWORD=root percona/percona-server:8.0\n

As soon as Percona Server for MySQL runs, add some data to it. Now, you are ready to make backups with Percona XtraBackup.

Important

When running Percona XtraBackup from a container and connecting to a MySQLserver container, we recommend using the \u2013user root option in the Docker command.

"},{"location":"docker.html#3-create-a-docker-container-from-percona-xtrabackup-image","title":"3. Create a Docker container from Percona XtraBackup image","text":"

You can create a Docker container based on Percona XtraBackup image with either docker create or the docker run command. docker create creates a Docker container and makes it available for starting later.

Docker downloads the Percona XtraBackup image from the Docker Hub. If it is not the first time you use the selected image, Docker uses the image available locally.

$ sudo docker create --name percona-xtrabackup --volumes-from percona-server-mysql \\\npercona/percona-xtrabackup  \\\nxtrabackup --backup --datadir=/var/lib/mysql/ --target-dir=/backup \\\n--user=root --password=mysql\n

With parameter name you give a meaningful name to your new Docker container so that you could easily locate it among your other containers.

The volumes-from flag refers to Percona Server for MySQL and indicates that you intend to use the same data as the Percona Server for MySQL container.

Run the container with exactly the same parameters that were used when the container was created:

$ sudo docker start -ai percona-xtrabackup\n

This command starts the percona-xtrabackup container, attaches to its input/output streams, and opens an interactive shell.

The docker run is a shortcut command that creates a Docker container and then immediately runs it.

$ sudo docker run --name percona-xtrabackup --volumes-from percona-server-mysql \\\npercona/percona-xtrabackup\nxtrabackup --backup --data-dir=/var/lib/mysql --target-dir=/backup --user=root --password=mysql\n
"},{"location":"encrypt-backups.html","title":"Encrypt backups","text":"

Percona XtraBackup supports encrypting and decrypting local and streaming backups with xbstream option adding another layer of protection. The encryption is implemented using the libgcrypt library from GnuPG.

"},{"location":"encrypt-backups.html#create-encrypted-backups","title":"Create encrypted backups","text":"

To make an encrypted backup the following options need to be specified (options --encrypt-key and --encrypt-key-file are mutually exclusive, i.e. just one of them needs to be provided):

Both the --encrypt-key option and --encrypt-key-file option can be used to specify the encryption key. An encryption key can be generated with a command like openssl rand -base64 24

U2FsdGVkX19VPN7VM+lwNI0fePhjgnhgqmDBqbF3Bvs=\n

This value then can be used as the encryption key

"},{"location":"encrypt-backups.html#the-encrypt-key-option","title":"The --encrypt-key option","text":"

Example of the xtrabackup command using the --encrypt-key should look like this:

$  xtrabackup --backup --encrypt=AES256 --encrypt-key=\"U2FsdGVkX19VPN7VM+lwNI0fePhjgnhgqmDBqbF3Bvs=\" --target-dir=/data/backup\n
"},{"location":"encrypt-backups.html#the-encrypt-key-file-option","title":"The --encrypt-key-file option","text":"

Use the --encrypt-key-file option as follows:

$ xtrabackup --backup --encrypt=AES256 --encrypt-key-file=/data/backups/keyfile --target-dir=/data/backup\n

Note

Depending on the text editor that you use to make the KEYFILE, the editor can automatically insert the CRLF (end of line) character. This will cause the key size to grow and thus making it invalid. The suggested way to create the file is by using the command line: echo -n \u201cU2FsdGVkX19VPN7VM+lwNI0fePhjgnhgqmDBqbF3Bvs=\u201d > /data/backups/keyfile.

"},{"location":"encrypt-backups.html#optimize-the-encryption-process","title":"Optimize the encryption process","text":"

Two new options are available for encrypted backups that can be used to speed up the encryption process. These are --encrypt-threads and --encrypt-chunk-size. By using the --encrypt-threads option multiple threads can be specified to be used for encryption in parallel. Option --encrypt-chunk-size can be used to specify the size (in bytes) of the working encryption buffer for each encryption thread (default is 64K).

"},{"location":"encrypt-backups.html#decrypt-encrypted-backups","title":"Decrypt encrypted backups","text":"

Backups can be decrypted with The xbcrypt binary. The following one-liner can be used to encrypt the whole folder:

$ for i in `find . -iname \"*\\.xbcrypt\"`; do xbcrypt -d --encrypt-key-file=/root/secret_key --encrypt-algo=AES256 < $i > $(dirname $i)/$(basename $i .xbcrypt) && rm $i; done\n

Percona XtraBackup --decrypt option has been implemented that can be used to decrypt the backups:

$ xtrabackup --decrypt=AES256 --encrypt-key=\"U2FsdGVkX19VPN7VM+lwNI0fePhjgnhgqmDBqbF3Bvs=\" --target-dir=/data/backup/\n

Percona XtraBackup doesn\u2019t automatically remove the encrypted files. In order to clean up the backup directory users should remove the \\*.xbcrypt files.

Note

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

When the files are decrypted, the backup can be prepared.

"},{"location":"encrypt-backups.html#prepare-encrypted-backups","title":"Prepare encrypted backups","text":"

After the backups have been decrypted, they can be prepared in the same way as the standard full backups with the --prepare option:

$ xtrabackup --prepare --target-dir=/data/backup/\n
"},{"location":"encrypt-backups.html#restore-encrypted-backups","title":"Restore encrypted backups","text":"

xtrabackup offers the --copy-back option to restore a backup to the server\u2019s datadir:

$ xtrabackup --copy-back --target-dir=/data/backup/\n

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

Expected output
150318 11:08:13  xtrabackup: completed OK!\n
"},{"location":"encrypted-innodb-tablespace-backups.html","title":"Encrypted InnoDB tablespace backups","text":"

InnoDB supports data encryption for InnoDB tables stored in file-per-table tablespaces. This feature provides an at-rest encryption for physical tablespace data files.

For an authenticated user or application to access an encrypted tablespace, InnoDB uses the master encryption key to decrypt the tablespace key. The master encryption key is stored in a keyring. xtrabackup supports two keyring plugins: keyring_file, and keyring_vault. These plugins are installed into the plugin directory.

"},{"location":"encrypted-innodb-tablespace-backups.html#version-updates","title":"Version updates","text":"

Percona XtraBackup 8.0.25-17 adds support for the keyring_file component, which is part of the component-based infrastructure MySQL which extends the server capabilities. The component is stored in the plugin directory.

See a comparison of keyring components and keyring plugins for more information.

Percona XtraBackup 8.0.27-19 adds support for the Key Management Interoperability Protocol (KMIP) which enables the communication between the key management system and encrypted database server.

Percona XtraBackup 8.0.28-21 adds support for the Amazon Key Management Service (AWS KMS). AWS KMS is cloud-based encryption and key management service. The keys and functionality can be used for other AWS services or your applications that use AWS. No configuration is required to back up a server with AWS KMS-enabled encryption.

"},{"location":"encrypted-innodb-tablespace-backups.html#use-keyring_file-plugin","title":"Use keyring_file plugin","text":"

In order to back up and prepare a database containing encrypted InnoDB tablespaces, specify the path to a keyring file as the value of the --keyring-file-data option.

$ xtrabackup --backup --target-dir=/data/backup/ --user=root \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

After xtrabackup takes the backup, the following message confirms the action:

Confirmation message
xtrabackup: Transaction log of lsn (5696709) to (5696718) was copied.\n160401 10:25:51 completed OK!\n

Warning

xtrabackup does not copy the keyring file into the backup directory. To prepare the backup, you must copy the keyring file manually.

"},{"location":"encrypted-innodb-tablespace-backups.html#prepare-the-backup-with-the-keyring_file-plugin","title":"Prepare the backup with the keyring_file plugin","text":"

To prepare the backup specify the keyring-file-data.

$ xtrabackup --prepare --target-dir=/data/backup \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

After xtrabackup takes the backup, the following message confirms the action:

Confirmation message
InnoDB: Shutdown completed; log sequence number 5697064\n160401 10:34:28 completed OK!\n

The backup is now prepared and can be restored with the --copy-back option. In case the keyring has been rotated, you must restore the keyring used when the backup was taken and prepared.

"},{"location":"encrypted-innodb-tablespace-backups.html#use-keyring_vault-plugin","title":"Use keyring_vault plugin","text":"

Keyring vault plugin settings are described here.

"},{"location":"encrypted-innodb-tablespace-backups.html#create-a-backup-with-the-keyring_vault-plugin","title":"Create a backup with the keyring_vault plugin","text":"

The following command creates a backup in the /data/backup directory:

$ xtrabackup --backup --target-dir=/data/backup --user=root\n

After xtrabackup completes the action, the following message confirms the action:

Confirmation message
xtrabackup: Transaction log of lsn (5696709) to (5696718) was copied.\n160401 10:25:51 completed OK!\n
"},{"location":"encrypted-innodb-tablespace-backups.html#prepare-the-backup-with-the-keyring_vault-plugin","title":"Prepare the backup with the keyring_vault plugin","text":"

To prepare the backup, xtrabackup must access the keyring. xtrabackup does not communicate with the MySQL server or read the default my.cnf configuration file. Specify the keyring settings in the command line:

$ xtrabackup --prepare --target-dir=/data/backup \\\n--keyring-vault-config=/etc/vault.cnf\n

Review using the keyring vault plugin for a description of keyring vault plugin settings.

After xtrabackup completes the action, the following message confirms the action:

Confirmation message
InnoDB: Shutdown completed; log sequence number 5697064\n160401 10:34:28 completed OK!\n

The backup is now prepared and can be restored with the --copy-back option:

$ xtrabackup --copy-back --target-dir=/data/backup --datadir=/data/mysql\n
"},{"location":"encrypted-innodb-tablespace-backups.html#use-the-keyring_file-component","title":"Use the keyring_file component","text":"

A component is not loaded with the --early_plugin_load option. The server uses a manifest to load the component and the component has its own configuration file. See the MySQL documentation on the component installation for more information.

An example of a manifest and a configuration file follows:

An example of ./bin/mysqld.my:

{\n\"components\": \"file://component_keyring_file\"\n}\n

An example of /lib/plugin/component_keyring_file.cnf:

{\n\"path\": \"/var/lib/mysql-keyring/keyring_file\", \"read_only\": false\n}\n

For more information, see Keyring Component Installation and Using the keyring_file File-Based Keyring Plugin.

With the appropriate privilege, you can SELECT on the performance_schema.keyring_component_status table to view the attributes and status of the installed keyring component when in use.

The component has no special requirements for backing up a database that contains encrypted InnoDB tablespaces.

$ xtrabackup --backup --target-dir=/data/backup --user=root\n

After xtrabackup completes the action, the following message confirms the action:

Confirmation message
xtrabackup: Transaction log of lsn (5696709) to (5696718) was copied.\n160401 10:25:51 completed OK!\n

Warning

xtrabackup does not copy the keyring file into the backup directory. To prepare the backup, you must copy the keyring file manually.

"},{"location":"encrypted-innodb-tablespace-backups.html#prepare-the-backup-with-the-keyring_file-component","title":"Prepare the backup with the keyring_file component","text":"

xtrabackup reads the keyring_file component configuration from xtrabackup_component_keyring_file.cnf. You must specify the keyring_file data path if the keyring-file-data is not located in the attribute PATH from the xtrabackup_component_keyring_file.cnf.

The following is an example of adding the location for the keyring-file-data:

$ xtrabackup --prepare --target-dir=/data/backup \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

xtrabackup attempts to read xtrabackup_component_keyring_file.cnf. You can assign another keyring file component configuration by passing the --component-keyring-file-config option.

After xtrabackup completes preparing the backup, the following message confirms the action:

Confirmation message
InnoDB: Shutdown completed; log sequence number 5697064\n160401 10:34:28 completed OK!\n

The backup is prepared. To restore the backup use the --copy-back option. If the keyring has been rotated, you must restore the specific keyring used to take and prepare the backup.

"},{"location":"encrypted-innodb-tablespace-backups.html#incremental-encrypted-innodb-tablespace-backups-with-keyring_file","title":"Incremental encrypted InnoDB tablespace backups with keyring_file","text":"

The process of taking incremental backups with InnoDB tablespace encryption is similar to taking the Incremental Backups with unencrypted tablespace. The keyring-file component should not used in production or for regulatory compliance.

"},{"location":"encrypted-innodb-tablespace-backups.html#create-an-incremental-backup","title":"Create an incremental backup","text":"

To make an incremental backup, begin with a full backup. The xtrabackup binary writes a file called xtrabackup_checkpoints into the backup\u2019s target directory. This file contains a line showing the to_lsn, which is the database\u2019s LSN at the end of the backup. First you need to create a full backup with the following command:

$ xtrabackup --backup --target-dir=/data/backups/base \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

In order to prepare the backup, you must make a copy of the keyring file yourself. xtrabackup does not copy the keyring file into the backup directory. Restoring the backup after the keyring has been changed causes errors like ERROR 3185 (HY000): Can't find master key from keyring, please check keyring plugin is loaded. when the restore process tries accessing an encrypted table.

If you look at the xtrabackup_checkpoints file, you should see the output similar to the following:

Expected output
backup_type = full-backuped\nfrom_lsn = 0\nto_lsn = 7666625\nlast_lsn = 7666634\ncompact = 0\nrecover_binlog_info = 1\n

Now that you have a full backup, you can make an incremental backup based on it. Use a command such as the following:

$ xtrabackup --backup --target-dir=/data/backups/inc1 \\\n--incremental-basedir=/data/backups/base \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

To prepare the backup, you must copy the keyring file manually. xtrabackup does not copy the keyring file into the backup directory.

If the keyring has not been rotated you can use the same as the one you\u2019ve backed-up with the base backup. If the keyring has been rotated, or you have upgraded the plugin to a component, you must back up the keyring file. Otherwise, you cannot prepare the backup.

The /data/backups/inc1/ directory should now contain delta files, such as ibdata1.delta and test/table1.ibd.delta. These represent the changes since the LSN 7666625. If you examine the xtrabackup_checkpoints file in this directory, you should see the output similar to the following:

Expected output
backup_type = incremental\nfrom_lsn = 7666625\nto_lsn = 8873920\nlast_lsn = 8873929\ncompact = 0\nrecover_binlog_info = 1\n

Use this directory as the base for yet another incremental backup:

$ xtrabackup --backup --target-dir=/data/backups/inc2 \\\n--incremental-basedir=/data/backups/inc1 \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n
"},{"location":"encrypted-innodb-tablespace-backups.html#prepare-incremental-backups","title":"Prepare incremental backups","text":"

The --prepare step for incremental backups is not the same as for normal backups. In normal backups, two types of operations are performed to make the database consistent: committed transactions are replayed from the log file against the data files, and uncommitted transactions are rolled back. You must skip the rollback of uncommitted transactions when preparing a backup, because transactions that were uncommitted at the time of your backup may be in progress, and it\u2019s likely that they will be committed in the next incremental backup. You should use the --apply-log-only option to prevent the rollback phase.

If you do not use the --apply-log-only option to prevent the rollback phase, then your incremental backups are useless. After transactions have been rolled back, further incremental backups cannot be applied.

Beginning with the full backup you created, you can prepare it and then apply the incremental differences to it. Recall that you have the following backups:

/data/backups/base\n/data/backups/inc1\n/data/backups/inc2\n

To prepare the base backup, you need to run --prepare as usual, but prevent the rollback phase:

$ xtrabackup --prepare --apply-log-only --target-dir=/data/backups/base \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n
Expected output
InnoDB: Shutdown completed; log sequence number 7666643\nInnoDB: Number of pools: 1\n160401 12:31:11 completed OK!\n

To apply the first incremental backup to the full backup, you should use the following command:

$ xtrabackup --prepare --apply-log-only --target-dir=/data/backups/base \\\n--incremental-dir=/data/backups/inc1 \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

The backup should be prepared with the keyring file and type that was used when backup was being taken. This means that if the keyring has been rotated, or you have upgraded from a plugin to a component between the base and incremental backup that you must use the keyring that was in use when the first incremental backup has been taken.

Preparing the second incremental backup is a similar process: apply the deltas to the (modified) base backup, and you will roll its data forward in time to the point of the second incremental backup:

$ xtrabackup --prepare --target-dir=/data/backups/base \\\n--incremental-dir=/data/backups/inc2 \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n
Use --apply-log-only when merging all incremental backups except the last one. That\u2019s why the previous line does not contain the --apply-log-only option. Even if the --apply-log-only was used on the last step, backup would still be consistent but in that case server would perform the rollback phase.

The backup is now prepared and can be restored with --copy-back option. In case the keyring has been rotated you\u2019ll need to restore the keyring which was used to take and prepare the backup.

"},{"location":"encrypted-innodb-tablespace-backups.html#use-the-key-management-interoperability-protocol-kmip","title":"Use the Key Management Interoperability Protocol (KMIP)","text":"

Percona XtraBackup 8.0.27-19 adds support for the Key Management Interoperability Protocol (KMIP) which enables the communication between the key management system and encrypted database server.

Percona XtraBackup has no special requirements for backing up a database that contains encrypted InnoDB tablespaces.

Percona XtraBackup performs the following actions:

  1. Connects to the MySQL server

  2. Pulls the configuration

  3. Connects to the KMIP server

  4. Fetches the necessary keys from the KMIP server

  5. Stores the KMIP server configuration settings in the xtrabackup_component_keyring_kmip.cnf file in the backup directory

When preparing the backup, Percona XtraBackup connects to the KMIP server with the settings from the xtrabackup_component_keyring_kmip.cnf file.

"},{"location":"encrypted-innodb-tablespace-backups.html#restore-a-backup-when-the-keyring-is-not-available","title":"Restore a backup when the keyring is not available","text":"

While the described restore method works, this method requires access to the same keyring that the server is using. It may not be possible if the backup is prepared on a different server or at a much later time, when keys in the keyring are purged, or, in the case of a malfunction, when the keyring vault server is not available at all.

The --transition-key=<passphrase> option should be used to make it possible for xtrabackup to process the backup without access to the keyring vault server. In this case, xtrabackup derives the AES encryption key from the specified passphrase and will use it to encrypt tablespace keys of tablespaces that are being backed up.

"},{"location":"encrypted-innodb-tablespace-backups.html#create-a-backup-with-a-passphrase","title":"Create a backup with a passphrase","text":"

The following example illustrates how the backup can be created in this case:

$ xtrabackup --backup --user=root -p --target-dir=/data/backup \\\n--transition-key=MySecretKey\n

If --transition-key is specified without a value, xtrabackup will ask for it.

xtrabackup scrapes --transition-key so that its value is not visible in the ps command output.

"},{"location":"encrypted-innodb-tablespace-backups.html#prepare-a-backup-with-a-passphrase","title":"Prepare a backup with a passphrase","text":"

The same passphrase should be specified for the prepare command:

$ xtrabackup --prepare --target-dir=/data/backup \\\n--transition-key=MySecretKey\n

There are no --keyring-vault...,``\u2013keyring-file\u2026``, or --component-keyring-file-config options here, because xtrabackup does not talk to the keyring in this case.

"},{"location":"encrypted-innodb-tablespace-backups.html#restore-a-backup-with-a-generated-key","title":"Restore a backup with a generated key","text":"

When restoring a backup you will need to generate a new master key. Here is the example for keyring_file plugin or component:

$ xtrabackup --copy-back --target-dir=/data/backup --datadir=/data/mysql \\\n--transition-key=MySecretKey --generate-new-master-key \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

In case of keyring_vault, it will look like this:

$ xtrabackup --copy-back --target-dir=/data/backup --datadir=/data/mysql \\\n--transition-key=MySecretKey --generate-new-master-key \\\n--keyring-vault-config=/etc/vault.cnf\n

xtrabackup will generate a new master key, store it in the target keyring vault server and re-encrypt the tablespace keys using this key.

"},{"location":"encrypted-innodb-tablespace-backups.html#make-a-backup-with-a-stored-transition-key","title":"Make a backup with a stored transition key","text":"

Finally, there is an option to store a transition key in the keyring. In this case, xtrabackup will need to access the same keyring file or vault server during prepare and copy-back but does not depend on whether the server keys have been purged.

In this scenario, the three stages of the backup process look as follows.

$ xtrabackup --backup --user=root -p --target-dir=/data/backup \\\n--generate-transition-key\n
"},{"location":"error-message-instant.html","title":"Error Message: Found tables with row versions due to INSTANT ADD/DROP columns","text":"

MySQL 8.0.29 extended the support for ALTER TABLE \u2026 ALGORITHM=INSTANT to allow users to add a column in any table position or drop any column. As part of this update, the redo log format has changed for all server DML operations. This updated redo log format has a design flaw that can cause data corruption for tables with INSTANT ADD/DROP COLUMNS.

The corruption happens when the crash recovery occurs. InnoDB applies redo logs at startup. Xtrabackup copies the redo log during the backup and applies the log as part of the --prepare step to bring the backup to a consistent state.

Percona fixed the corruption issue and several other issues with the INSTANT ADD/DROP column feature in the upcoming Percona Server for MySQL 8.0.29.

For more details, see the following:

Percona XtraBackup 8.0.32-25 allows instant columns in the backup for MySQL 8.0.32. This limitation remains for backing up MySQL 8.0.31 and lower versions. This limitation does not exist for backing up Percona Server for any version.

Percona XtraBackup 8.0.29 is able to take backups of Percona Server for MySQL 8.0.29 with tables that have INSTANT ADD/DROP COLUMNS. However, the issues in MySQL 8.0.29 make this version unsafe to take backups.

It is impossible for XtraBackup to deal with the corrupted redo log generated by MySQL 8.0.29 and, for this reason, XtraBackup 8.0.29 version will not take backups if it detects tables with INSTANT ADD/DROP COLUMNS and generates an error listing the affected tables and providing instructions to convert them to regular tables.

Please avoid ALTER ADD/DROP COLUMN without an explicit ALGORITHM=INPLACE. The default ALGORITHM is INSTANT, so ALTER TABLE without the ALGORITHM keyword uses the newly introduced INSTANT algorithm.

If you already have such tables (information below on how to find such tables), users are advised to do OPTIMIZE TABLE against these tables before taking backups.

To find tables with INSTANT ADD/DROP COLUMNS run the following command:

mysql> SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE TOTAL_ROW_VERSIONS > 0;\n+---------+\n| NAME    |\n+---------+\n| test/t1 |\n| test/t2 |\n| test/t3 |\n+---------+\n3 rows in set (0.02 sec)\n

If this query shows an empty result set, you have no issues. Percona Xtrabackup takes the backup of your MySQL 8.0.29 server. If the results are a list of tables, please run OPTIMIZE TABLE on the list before taking the backup.

"},{"location":"error-message-instant.html#percona-xtrabackup-error-message","title":"Percona XtraBackup Error Message","text":"

If Percona XtraBackup detects that MySQL 8.0.29 server has tables with instant add/drop columns, it aborts with the following error message

2022-07-01T15:18:35.127689+05:30 0 [ERROR] [MY-011825] [Xtrabackup] Found tables with row versions due to INSTANT ADD/DROP columns\n2022-07-01T15:18:35.127714+05:30 0 [ERROR] [MY-011825] [Xtrabackup] This feature is not stable and will cause backup corruption.\n2022-07-01T15:18:35.127723+05:30 0 [ERROR] [MY-011825] [Xtrabackup] Tables found:\n2022-07-01T15:18:35.127730+05:30 0 [ERROR] [MY-011825] [Xtrabackup] test/t1\n2022-07-01T15:18:35.127737+05:30 0 [ERROR] [MY-011825] [Xtrabackup] test/t2\n2022-07-01T15:18:35.127744+05:30 0 [ERROR] [MY-011825] [Xtrabackup] test/t3\n2022-07-01T15:18:35.127752+05:30 0 [ERROR] [MY-011825] [Xtrabackup] Please run OPTIMIZE TABLE or ALTER TABLE ALGORITHM=COPY on all listed tables to fix this issue.\n
"},{"location":"error-message-instant.html#summary","title":"Summary","text":"

The option, ALGORITHM=INSTANT is the default value in MySQL 8.0.29. If you do not specify an algorithm, all ALTER TABLE ADD/DROP COLUMN statements use this algorithm.

The INSTANT algorithm is unstable at this point.

Percona XtraBackup refuses to take backups from MySQL 8.0.29 tables that have used this algorithm. Percona Server users do not suffer the same limitations as the corruption issues are fixed in the upcoming release of Percona Server for MySQL 8.0.29

"},{"location":"faq.html","title":"Frequently asked questions","text":""},{"location":"faq.html#does-percona-xtrabackup-80-support-making-backups-of-databases-in-versions-prior-to-80","title":"Does Percona XtraBackup 8.0 support making backups of databases in versions prior to 8.0?","text":"

Percona XtraBackup 8.0 does not support making backups of databases created in versions prior to 8.0 of MySQL, Percona Server for MySQL or Percona XtraDB Cluster. As the changes that MySQL 8.0 introduced in data dictionaries, redo log and undo log are incompatible with previous versions, it is currently impossible for Percona XtraBackup 8.0 to also support versions prior to 8.0.

Due to changes in MySQL 8.0.20 released by Oracle at the end of April 2020, Percona XtraBackup 8.0, up to version 8.0.11, is not compatible with MySQL version 8.0.20 or higher, or Percona products that are based on it: Percona Server for MySQL and Percona XtraDB Cluster.

For more information, see Percona XtraBackup 8.x and MySQL 8.0.20

"},{"location":"faq.html#why-will-innobackupex-not-run-in-percona-xtrabackup-80","title":"Why will innobackupex not run in Percona XtraBackup 8.0?","text":"

innobackupex has been removed from Percona XtraBackup 8.0 in favor of xtrabackup.

"},{"location":"faq.html#are-you-aware-of-any-web-based-backup-management-tools-commercial-or-not-built-around-percona-xtrabackup","title":"Are you aware of any web-based backup management tools (commercial or not) built around Percona XtraBackup?","text":"

Zmanda Recovery Manager is a commercial tool that uses Percona XtraBackup for Non-Blocking Backups:

\u201cZRM provides support for non-blocking backups of MySQL using Percona XtraBackup. ZRM with *Percona XtraBackup provides resource utilization management by providing throttling based on the number of IO operations per second. Percona XtraBackup based backups also allow for table level recovery even though the backup was done at the database level (needs the recovery database server to be Percona Server for MySQL with XtraDB).\u201d*

"},{"location":"faq.html#xtrabackup-binary-fails-with-a-floating-point-exception","title":"xtrabackup binary fails with a floating point exception","text":"

In most of the cases this is due to not having installed the required libraries (and version) by xtrabackup. Installing the GCC suite with the supporting libraries and recompiling xtrabackup solves the issue. See Compiling and Installing from Source Code for instructions on the procedure.

"},{"location":"faq.html#how-xtrabackup-handles-the-ibdataib_log-files-on-restore-if-they-arent-in-mysql-datadir","title":"How xtrabackup handles the ibdata/ib_log files on restore if they aren\u2019t in mysql datadir?","text":"

In case the ibdata and ib_log files are located in different directories outside the datadir, you will have to put them in their proper place after the logs have been applied.

"},{"location":"faq.html#backup-fails-with-error-24-too-many-open-files","title":"Backup fails with Error 24: \u2018Too many open files\u2019","text":"

This usually happens when database being backed up contains large amount of files and Percona XtraBackup can\u2019t open all of them to create a successful backup. In order to avoid this error the operating system should be configured appropriately so that Percona XtraBackup can open all its files. On Linux, this can be done with the ulimit command for specific backup session or by editing the /etc/security/limits.conf to change it globally (NOTE: the maximum possible value that can be set up is 1048576 which is a hard-coded constant in the Linux kernel).

"},{"location":"faq.html#how-to-deal-with-skipping-of-redo-logs-for-ddl-operations","title":"How to deal with skipping of redo logs for DDL operations?","text":"

To prevent creating corrupted backups when running DDL operations, Percona XtraBackup aborts if it detects that redo logging is disabled. In this case, the following error is printed:

[FATAL] InnoDB: An optimized (without redo logging) DDL operation has been performed. All modified pages may not have been flushed to the disk yet.\nPercona XtraBackup will not be able to take a consistent backup. Retry the backup operation.\n

Note

Redo logging is disabled during a sorted index build. To avoid this error, Percona XtraBackup can use metadata locks on tables while they are copied:

Note

As of Percona XtraBackup 8.0.15, the \u2013lock-ddl-per-table option is deprecated. Use the --lock-ddl option.

"},{"location":"flush-tables-with-read-lock.html","title":"FLUSH TABLES WITH READ LOCK option","text":"

The FLUSH TABLES WITH READ LOCK option does the following with a global read lock:

Release the lock with UNLOCK TABLES.

Note

FLUSH TABLES WITH READ LOCK does not prevent inserting rows into the log tables.

To ensure consistent backups, use the FLUSH TABLES WITH READ LOCK option before taking a non-InnoDB file backup. The option does not affect long-running queries.

Long-running queries with FLUSH TABLES WITH READ LOCK enabled can leave the server in a read-only mode until the queries finish. Killing the FLUSH TABLES WITH READ LOCK does not help if the database is in either the Waiting for table flush or Waiting for master to send event state. To return to normal operation, you must kill any long-running queries.

Note

All described in this section has no effect when backup locks are used. Percona XtraBackup will use Backup locks where available as a lightweight alternative to FLUSH TABLES WITH READ LOCK. This feature is available in Percona Server for MySQL 5.6+. Percona XtraBackup uses this automatically to copy non-InnoDB data to avoid blocking DML queries that modify InnoDB tables.

In order to prevent this from happening two things have been implemented:

"},{"location":"flush-tables-with-read-lock.html#wait-for-queries-to-finish","title":"Wait for queries to finish","text":"

You should issue a global lock when no long queries are running. Waiting to issue the global lock for extended period of time is not a good method. The wait can extend the time needed for backup to take place. The \u2013ftwrl-wait-timeout option can limit the waiting time. If it cannot issue the lock during this time, xtrabackup stops the option, exits with an error message, and backup is not be taken.

The default value for this option is zero (0) value which turns off the option.

Another possibility is to specify the type of query to wait on. In this case --ftwrl-wait-query-type. Possible values are all and update. When all is used xtrabackup will wait for all long running queries (execution time longer than allowed by --ftwrl-wait-threshold) to finish before running the FLUSH TABLES WITH READ LOCK. When update is used xtrabackup will wait on UPDATE/ALTER/REPLACE/INSERT queries to finish.

The time needed for a specific query to complete is hard to predict. We assume that the long-running queries will not finish in a timely manner. Other queries which run for a short time finish quickly. xtrabackup uses the value of \u2013ftwrl-wait-threshold option to specify the long-running queries and will block a global lock. In order to use this option xtrabackup user should have PROCESS and SUPER privileges.

"},{"location":"flush-tables-with-read-lock.html#kill-the-blocking-queries","title":"Kill the blocking queries","text":"

The second option is to kill all the queries which prevent from acquiring the global lock. In this case, all queries which run longer than FLUSH TABLES WITH READ LOCK are potential blockers. Although all queries can be killed, additional time can be specified for the short running queries to finish using the --kill-long-queries-timeout option. This option specifies the time for queries to complete, after the value is reached, all the running queries will be killed. The default value is zero, which turns this feature off.

The --kill-long-query-type option can be used to specify all or only SELECT queries that are preventing global lock from being acquired. In order to use this option xtrabackup user should have PROCESS and SUPER privileges.

"},{"location":"flush-tables-with-read-lock.html#options-summary","title":"Options summary","text":""},{"location":"flush-tables-with-read-lock.html#example","title":"Example","text":"

Running the xtrabackup with the following options will cause xtrabackup to spend no longer than 3 minutes waiting for all queries older than 40 seconds to complete.

$  xtrabackup --backup --ftwrl-wait-threshold=40 \\\n--ftwrl-wait-query-type=all --ftwrl-wait-timeout=180 \\\n--kill-long-queries-timeout=20 --kill-long-query-type=all \\\n--target-dir=/data/backups/\n

After FLUSH TABLES WITH READ LOCK is issued, xtrabackup will wait for 20 seconds for lock to be acquired. If lock is still not acquired after 20 seconds, it will kill all queries which are running longer that the FLUSH TABLES WITH READ LOCK.

"},{"location":"glossary.html","title":"Glossary","text":""},{"location":"glossary.html#csm","title":".CSM","text":"

Each table with the CSV Storage Engine has .CSM file which contains the metadata of it.

"},{"location":"glossary.html#csv","title":".CSV","text":"

Each table with the CSV Storage engine has .CSV file which contains the data of it (which is a standard Comma Separated Value file).

"},{"location":"glossary.html#exp","title":".exp","text":"

Files with the .exp extension are created by Percona XtraBackup per each InnoDB tablespace when the --export option is used on prepare. See restore individual tables.

"},{"location":"glossary.html#frm","title":".frm","text":"

For each table, the server will create a file with the .frm extension containing the table definition (for all storage engines).

"},{"location":"glossary.html#general-availability-ga","title":"General availability (GA)","text":"

A finalized version of the product which is made available to the general public. It is the final stage in the software release cycle.

"},{"location":"glossary.html#ibd","title":".ibd","text":"

On a multiple tablespace setup ([innodb_file_per_table] enabled), MySQL will store each newly created table on a file with a .ibd extension.

"},{"location":"glossary.html#mrg","title":".MRG","text":"

Each table using the MERGE storage engine, besides of a .frm file, will have .MRG file containing the names of the MyISAM tables associated with it.

"},{"location":"glossary.html#myd","title":".MYD","text":"

Each MyISAM table has .MYD (MYData) file which contains the data on it.

"},{"location":"glossary.html#myi","title":".MYI","text":"

Each MyISAM table has .MYI (MYIndex) file which contains the table\u2019s indexes.

"},{"location":"glossary.html#opt","title":".opt","text":"

MySQL stores options of a database (like charset) in a file with a .opt extension in the database directory.

"},{"location":"glossary.html#par","title":".par","text":"

Each partitioned table has .par file which contains metadata about the partitions.

"},{"location":"glossary.html#trg","title":".TRG","text":"

The file contains the triggers associated with a table, for example, \\mytable.TRG. With the .TRN file, they represent all the trigger definitions.

"},{"location":"glossary.html#trn","title":".TRN","text":"

The file contains the names of triggers that are associated with a table, for example, \\mytable.TRN. With the .TRG file, they represent all the trigger definitions.

"},{"location":"glossary.html#backup","title":"backup","text":"

The process of copying data or tables to be stored in a different location.

"},{"location":"glossary.html#compression","title":"compression","text":"

The method that produces backups in a reduced size.

"},{"location":"glossary.html#configuration-file","title":"configuration file","text":"

The file that contains the server startup options.

"},{"location":"glossary.html#crash","title":"crash","text":"

An unexpected shutdown which does not allow the normal server shutdown cleanup activities.

"},{"location":"glossary.html#crash-recovery","title":"crash recovery","text":"

The actions that occur when MySQL is restarted after a crash.

"},{"location":"glossary.html#data-dictionary","title":"data dictionary","text":"

The metadata for the tables, indexes, and table columns stored in the InnoDB system tablespace.

"},{"location":"glossary.html#datadir","title":"datadir","text":"

The directory in which the database server stores its data files. Most Linux distribution use /var/lib/mysql by default.

"},{"location":"glossary.html#full-backup","title":"full backup","text":"

A backup that contains the complete source data from an instance.

"},{"location":"glossary.html#ibdata","title":"ibdata","text":"

The default prefix for tablespace files. For example, ibdata1 is a 10MB auto-extensible file that MySQL creates for a shared tablespace by default.

"},{"location":"glossary.html#incremental-backup","title":"incremental backup","text":"

A backup stores data from a specific point in time.

"},{"location":"glossary.html#innodb","title":"InnoDB","text":"

Storage engine which provides ACID-compliant transactions and foreign key support, among others improvements over MyISAM. It is the default engine for MySQL as of the 8.0 series.

"},{"location":"glossary.html#innodb_buffer_pool_size","title":"innodb_buffer_pool_size","text":"

The size in bytes of the memory buffer to cache data and indexes of InnoDB\u2019s tables. This aims to reduce disk access to provide better performance.

[mysqld] innodb_buffer_pool_size=8MB

"},{"location":"glossary.html#innodb_data_home_dir","title":"innodb_data_home_dir","text":"

The directory (relative to datadir) where the database server stores the files in a shared tablespace setup. This option does not affect the location of innodb\\_file\\_per\\_table. For example:

[mysqld] innodb_data_home_dir = ./

"},{"location":"glossary.html#innodb_data_file_path","title":"innodb_data_file_path","text":"

Specifies the names, sizes and location of shared tablespace files:

[mysqld] innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend

"},{"location":"glossary.html#innodb_file_per_table","title":"innodb_file_per_table","text":"

By default, InnoDB creates tables and indexes in a file-per-tablespace. If the innodb_file_per_table variable is disabled, you can enable the variable in your configuration file:

[mysqld] innodb_file_per_table or start the server with --innodb_file_per_table.

"},{"location":"glossary.html#innodb_log_group_home_dir","title":"innodb_log_group_home_dir","text":"

Specifies the location of the InnoDB log files:

[mysqld] innodb_log_group_home=/var/lib/mysql

"},{"location":"glossary.html#logical-backup","title":"logical backup","text":"

A backup which contains a set of SQL statements. The statements can be used to recreate the databases.

"},{"location":"glossary.html#lsn","title":"LSN","text":"

Each InnoDB page contains a log sequence number(LSN). The LSN is the system version number for the database. Each page\u2019s LSN shows how recently it was changed.

"},{"location":"glossary.html#mycnf","title":"my.cnf","text":"

The database server\u2019s main configuration file. Most Linux distributions place it as /etc/mysql/my.cnf or /etc/my.cnf, but the location and name depends on the particular installation. Note that this method is not the only way of configuring the server, some systems rely on the command options.

"},{"location":"glossary.html#myisam","title":"MyISAM","text":"

The MySQL default storage engine until version 5.5. It doesn\u2019t fully support transactions but in some scenarios may be faster than InnoDB. Each table is stored on disk in 3 files: .frm, .MYD, .MYI.

"},{"location":"glossary.html#physical-backup","title":"physical backup","text":"

A backup that copies the data files.

"},{"location":"glossary.html#point-in-time-recovery","title":"point in time recovery","text":"

This method restores the data into the state it was at any selected point of time.

"},{"location":"glossary.html#prepared-backup","title":"prepared backup","text":"

A consistent set of backup data that is ready to be restored.

"},{"location":"glossary.html#restore","title":"restore","text":"

Copies the database backups taken using the backup command to the original location or a different location. A restore returns data that has been either lost, corrupted, or stolen to the original condition at a specific point in time.

"},{"location":"glossary.html#tech-preview","title":"Tech preview","text":"

A tech preview item can be a feature, a variable, or a value within a variable. Before using this feature in production, we recommend that you test restoring production from physical backups in your environment and also use an alternative backup method for redundancy. A tech preview item is included in a release for users to provide feedback. The item is either updated and released as general availability(GA) or removed if not useful. The functionality can change from tech preview to GA.

"},{"location":"glossary.html#xbcrypt","title":"xbcrypt","text":"

To support the encryption and the decryption of the backups, a new tool xbcrypt was introduced to Percona XtraBackup. This utility has been modeled after the xbstream binary to perform encryption and decryption outside Percona XtraBackup.

"},{"location":"glossary.html#xbstream","title":"xbstream","text":"

To support simultaneous compression and streaming, Percona XtraBackup uses the xbstream format. For more information see xbstream

"},{"location":"glossary.html#xtradb","title":"XtraDB","text":"

Percona XtraDB is an enhanced version of the InnoDB storage engine, designed to better scale on modern hardware. Percona XtraDB includes features which are useful in a high performance environment. It is fully backward-compatible, and is a drop-in replacement for the standard InnoDB storage engine. For more information, see The Percona XtraDB Storage Engine.

"},{"location":"glossary.html#zstandard-zstd","title":"Zstandard (ZSTD)","text":"

ZSTD is a fast lossless compression algorithm that targets real-time compression scenarios and better compression ratios.

ZSTD compression algorithm was implemented in Percona XtraBackup 8.0.30-23.

"},{"location":"how-xtrabackup-works.html","title":"How Percona XtraBackup works","text":"

Percona XtraBackup is based on InnoDB\u2019s crash-recovery functionality. It copies your InnoDB data files, which results in data that is internally inconsistent; but then it performs crash recovery on the files to make them a consistent, usable database again.

This works because InnoDB maintains a redo log, also called the transaction log. This contains a record of every change to InnoDB data. When InnoDB starts, it inspects the data files and the transaction log, and performs two steps. It applies committed transaction log entries to the data files, and it performs an undo operation on any transactions that modified data but did not commit.

Percona XtraBackup 8.0.30-23 adds --register-redo-log-consumer parameter. The --register-redo-log-consumer parameter is disabled by default. When enabled, this parameter lets Percona XtraBackup register as a redo log consumer at the start of the backup. The server does not remove a redo log that Percona XtraBackup (the consumer) has not yet copied. The consumer reads the redo log and manually advances the log sequence number (LSN). The server blocks the writes during the process. Based on the redo log consumption, the server determines when it can purge the log.

Percona XtraBackup works by remembering the LSN when it starts, and then copying away the data files. It takes some time to do this, so if the files are changing, then they reflect the state of the database at different points in time. At the same time, Percona XtraBackup runs a background process that watches the transaction log files, and copies changes from it. Percona XtraBackup needs to do this continually because the transaction logs are written in a round-robin fashion, and can be reused after a while. Percona XtraBackup needs the transaction log records for every change to the data files since it began execution.

Percona XtraBackup uses Backup locks

where available as a lightweight alternative to FLUSH TABLES WITH READ LOCK. This feature is available in Percona Server for MySQL 5.6+. MySQL 8.0 allows acquiring an instance level backup lock via the LOCK INSTANCE FOR BACKUP statement.

Locking is only done for MyISAM and other non-InnoDB tables after Percona XtraBackup finishes backing up all InnoDB/XtraDB data and logs. Percona XtraBackup uses this automatically to copy non-InnoDB data to avoid blocking DML queries that modify InnoDB tables.

Important

The BACKUP_ADMIN privilege is required to query the performance_schema_log_status for either LOCK INSTANCE FOR BACKUP or LOCK TABLES FOR BACKUP.

xtrabackup tries to avoid backup locks and FLUSH TABLES WITH READ LOCK when the instance contains only InnoDB tables. In this case, xtrabackup obtains binary log coordinates from performance_schema.log_status. FLUSH TABLES WITH READ LOCK is still required in MySQL 8.0 when xtrabackup is started with the --slave-info. The log_status table in Percona Server for MySQL 8.0 is extended to include the relay log coordinates, so no locks are needed even with the --slave-info option.

See also

MySQL Documentation: LOCK INSTANCE FOR BACKUP

When backup locks are supported by the server, xtrabackup first copies InnoDB data, runs the LOCK TABLES FOR BACKUP and then copies the MyISAM tables. Once this is done, the backup of the files will begin. It will backup .frm, .MRG, .MYD, .MYI, .CSM, .CSV, .sdi and .par files.

After that xtrabackup will use LOCK BINLOG FOR BACKUP to block all operations that might change either binary log position or Exec_Master_Log_Pos or Exec_Gtid_Set (i.e. source binary log coordinates corresponding to the current SQL thread state on a replication replica) as reported by SHOW MASTER/SLAVE STATUS. xtrabackup will then finish copying the REDO log files and fetch the binary log coordinates. After this is completed xtrabackup will unlock the binary log and tables.

Finally, the binary log position will be printed to STDERR and xtrabackup will exit returning 0 if all went OK.

Note that the STDERR of xtrabackup is not written in any file. You will have to redirect it to a file, e.g., xtrabackup OPTIONS 2> backupout.log.

It will also create the following files in the directory of the backup.

During the prepare phase, Percona XtraBackup performs crash recovery against the copied data files, using the copied transaction log file. After this is done, the database is ready to restore and use.

The backed-up MyISAM and InnoDB tables will be eventually consistent with each other, because after the prepare (recovery) process, InnoDB\u2019s data is rolled forward to the point at which the backup completed, not rolled back to the point at which it started. This point in time matches where the FLUSH TABLES WITH READ LOCK was taken, so the MyISAM data and the prepared InnoDB data are in sync.

The xtrabackup offers many features not mentioned in the preceding explanation. The functionality of each tool is explained in more detail further in this manual. In brief, though, the tools enable you to do operations such as streaming and incremental backups with various combinations of copying the data files, copying the log files, and applying the logs to the data.

"},{"location":"how-xtrabackup-works.html#restoring-a-backup","title":"Restoring a backup","text":"

To restore a backup with xtrabackup you can use the --copy-back or --move-back options.

xtrabackup will read from the my.cnf the variables datadir, innodb_data_home_dir, innodb_data_file_path, innodb_log_group_home_dir and check that the directories exist.

It will copy the MyISAM tables, indexes, etc. (.MRG, .MYD, .MYI, .CSM, .CSV, .sdi, and par files) first, InnoDB tables and indexes next and the log files at last. It will preserve file\u2019s attributes when copying them, you may have to change the files\u2019 ownership to mysql before starting the database server, as they will be owned by the user who created the backup.

Alternatively, the --move-back option may be used to restore a backup. This option is similar to --copy-back with the only difference that instead of copying files it moves them to their target locations. As this option removes backup files, it must be used with caution. It is useful in cases when there is not enough free disk space to hold both data files and their backup copies.

"},{"location":"installation.html","title":"Install Percona XtraBackup 8.0 overview","text":"

We recommend that you install Percona XtraBackup 8.0 from the official Percona software repositories using the appropriate package manager for your system:

"},{"location":"installation.html#installation-alternatives","title":"Installation alternatives","text":"

Percona also provides the following methods:

Before installing Percona XtraBackup with any of these methods, we recommend that you review the release notes and Server version and backup version comparison.

"},{"location":"lock-options.html","title":"lock-ddl-per-table option improvements","text":"

To block DDL statements on an instance, Percona Server implemented LOCK TABLES FOR BACKUP. Percona XtraBackup uses this lock for the duration of the backup. This lock does not affect DML statements.

Percona XtraBackup has also implemented --lock-ddl-per-table, which blocks DDL statements by using metadata locks (MDL).

The following procedures describe a simplified backup operation when using --lock-ddl-per-table:

  1. Parse and copy all redo logs after the checkpoint mark

  2. Fork a dedicated thread to continue following new redo log entries

  3. List the tablespaces required to copy

  4. Iterate through the list. The following steps occur with each listed tablespace:

  5. Query INFORMATION_SCHEMA.INNODB_TABLES to find which tables belong to the tablespace ID and take an MDL on the underlying table or tables in case there is a shared tablespace.

  6. Copy the tablespace .ibd files.

The backup process may encounter a redo log event, generated by the bulk load operations, which notifies backup tools that data file changes have been omitted from the redo log. This event is an MLOG_INDEX_LOAD. If this event is found by the redo follow thread, the backup continues and assumes the backup is safe because the MDL protects tablespaces already copied and the MLOG_INDEX_LOAD event is for a tablespace that is not copied.

These assumptions may not be correct and may lead to inconsistent backups.

"},{"location":"lock-options.html#-lock-ddl-per-table-redesign","title":"--lock-ddl-per-table redesign","text":"

Implemented in Percona XtraBackup version 8.0.22-15.0, the --lock-ddl-per-table has been redesigned to minimize inconsistent backups.

The following procedure reorders the steps:

"},{"location":"lock-options.html#other-improvements","title":"Other improvements","text":"

The following improvements have been added:

Warning

The lock-ddl-per-table variable is deprecated in Percona Server for MySQL 8.0. Use --lock-ddl instead of this variable.

"},{"location":"log-enhancements.html","title":"Improved log statements","text":"

Percona XtraBackup is an open-source command-line utility. Command-line tools have limited interaction with the background operations and the logs provide the progress of an operation or more information about errors.

In earlier versions, the error logs did not have a standard structure. Notice in the following examples the variance in the log statements:

 $ xtrabackup: recognized client arguments: --parallel=4 --target-dir=/data/backups/ --backup=1\n
The output should be similar to the following:

Expected output
./bin/xtrabackup version 8.0.27-19 based on MySQL server 8.0.27 Linux (x86_64) (revision id: b0f75188ca3)\n
220322 19:05:13 [01] Copying undo_001 to /data/backups/undo_001\n
Completed space ID check of 1008 files.\nInitializing buffer pool, total size = 128.000000M, instances = 1, chunk size =128.000000M\nCompleted initialization of buffer pool\nIf the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().\n
"},{"location":"log-enhancements.html#log-statement-structure","title":"Log statement structure","text":"

Starting in Percona XtraBackup 8.0.28-20, changes have been made to improve the log statements. The improved log structure is displayed in the backup, prepare, move-back/copy-back error logs.

Each log statement has the following attributes:

An example of a prepare log that is generated with the improved structure. The uniformity of the headers makes it easier to follow an operation\u2019s progress or review the log to diagnose issues.

Expected output
2022-03-22T19:15:36.142247+05:30 0 [Note] [MY-011825] [Xtrabackup] This target seems to be not prepared yet.\n2022-03-22T19:15:36.142792+05:30 0 [Note] [MY-013251] [InnoDB] Number of pools: 1\n2022-03-22T19:15:36.149212+05:30 0 [Note] [MY-011825] [Xtrabackup] xtrabackup_logfile detected: size=8388608, start_lsn=(33311656)\n2022-03-22T19:15:36.149998+05:30 0 [Note] [MY-011825] [Xtrabackup] using the following InnoDB configuration for recovery:\n2022-03-22T19:15:36.150023+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_data_home_dir = .\n2022-03-22T19:15:36.150036+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_data_file_path = ibdata1:12M:autoextend\n2022-03-22T19:15:36.150078+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_log_group_home_dir = .\n2022-03-22T19:15:36.150095+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_log_files_in_group = 1\n2022-03-22T19:15:36.150111+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_log_file_size = 8388608\n2022-03-22T19:15:36.151667+05:30 0 [Note] [MY-011825] [Xtrabackup] inititialize_service_handles suceeded\n2022-03-22T19:15:36.151903+05:30 0 [Note] [MY-011825] [Xtrabackup] using the following InnoDB configuration for recovery:\n2022-03-22T19:15:36.151926+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_data_home_dir = .\n2022-03-22T19:15:36.151954+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_data_file_path = ibdata1:12M:autoextend\n2022-03-22T19:15:36.151976+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_log_group_home_dir = .\n2022-03-22T19:15:36.151991+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_log_files_in_group = 1\n2022-03-22T19:15:36.152004+05:30 0 [Note] [MY-011825] [Xtrabackup] innodb_log_file_size = 8388608\n2022-03-22T19:15:36.152021+05:30 0 [Note] [MY-011825] [Xtrabackup] Starting InnoDB instance for recovery.\n2022-03-22T19:15:36.152035+05:30 0 [Note] [MY-011825] [Xtrabackup] Using 104857600 bytes for buffer pool (set by --use-memory parameter)\n
"},{"location":"lru-dump-backup.html","title":"LRU dump backup","text":"

Percona XtraBackup includes a saved buffer pool dump into a backup to enable reducing the warm up time. It restores the buffer pool state from ib_buffer_pool file after restart. Percona XtraBackup discovers ib_buffer_pool and backs it up automatically.

If the buffer restore option is enabled in my.cnf buffer pool will be in the warm state after backup is restored.

"},{"location":"make-backup-in-replication-env.html","title":"Make backups in replication environments","text":"

There are options specific to back up from a replication replica.

"},{"location":"make-backup-in-replication-env.html#the-slave-info-option","title":"The --slave-info option","text":"

This option is useful when backing up a replication replica server. It prints the binary log position and name of the source server. It also writes this information to the xtrabackup_slave_info file as a CHANGE MASTER statement.

This option is useful for setting up a new replica for this source. You can start a replica server with this backup and issue the statement saved in the xtrabackup_slave_info file. More details of this procedure can be found in How to setup a replica for replication in 6 simple steps with Percona XtraBackup.

"},{"location":"make-backup-in-replication-env.html#the-safe-slave-backup-option","title":"The --safe-slave-backup option","text":"

In order to assure a consistent replication state, this option stops the replication SQL thread and waits to start backing up until Slave_open_temp_tables in SHOW STATUS is zero. If there are no open temporary tables, the backup will take place, otherwise the SQL thread will be started and stopped until there are no open temporary tables. The backup will fail if Slave_open_temp_tables does not become zero after --safe-slave-backup-timeout seconds (defaults to 300 seconds). The replication SQL thread will be restarted when the backup finishes.

Note

Prior to Percona XtraBackup 8.0.22-15.0, using a safe-slave-backup stops the SQL replica thread after the InnoDB tables and before the non-InnoDB tables are backed up.

As of Percona XtraBackup 8.0.22-15.0, using a safe-slave-backup option stops the SQL replica thread before copying the InnoDB files.

Using this option is always recommended when taking backups from a replica server.

Warning

Make sure your replica is a true replica of the source before using it as a source for backup. A good tool to validate a replica is pt-table-checksum.

"},{"location":"page-tracking.html","title":"Take an incremental backup using page tracking","text":"

Percona XtraBackup 8.0.27 adds support for page tracking functionality for an incremental backup.

To create an incremental backup with page tracking, Percona XtraBackup uses the MySQL mysqlbackup component. This component provides a list of pages modified since the last backup, and Percona XtraBackup copies only those pages. This operation removes the need to scan the pages in the database. If the majority of pages have not been modified, the page tracking feature can improve the speed of incremental backups.

"},{"location":"page-tracking.html#install-the-component","title":"Install the component","text":"

To start using the page tracking functionality, do the following:

  1. Install the mysqlbackup component and enable it on the server:

    $ INSTALL COMPONENT \"file://component_mysqlbackup\";\n
  2. Check whether the mysqlbackup component is installed successfully:

    $ SELECT COUNT(1) FROM mysql.component WHERE component_urn='file://component_mysqlbackup';\n
"},{"location":"page-tracking.html#use-page-tracking","title":"Use page tracking","text":"

You can enable the page tracking functionality for the full and incremental backups with the --page-tracking option.

The option has the following benefits:

Percona XtraBackup processes a list of all the tracked pages in memory. If Percona XtraBackup does not have enough available memory to process this list, the process throws an error and exits. For example, if an incremental backup uses 200GB, Percona XtraBackup can use an additional 100MB of memory to process and store the page tracking data.

The examples of creating full and incremental backups using the --page-tracking option:

Full backupIncremental backup
$ xtrabackup --backup --target-dir=$FULL_BACK --page-tracking\n
$ xtrabackup --backup --target-dir=$INC_BACKUP  \n--incremental-basedir=$FULL_BACKUP --page-tracking\n

After enabling the functionality, the next incremental backup finds changed pages using page tracking.

The first full backup using page tracking, Percona XtraBackup may have a delay. The following is an example of the message:

Expected output
xtrabackup: pagetracking: Sleeping for 1 second, waiting for checkpoint lsn 17852922 /\nto reach to page tracking start lsn 21353759\n

Enable page tracking before creating the first backup to avoid this delay. This method ensures that the page tracking log sequence number (LSN) is higher than the checkpoint LSN of the server.

"},{"location":"page-tracking.html#start-page-tracking-manually","title":"Start page tracking manually","text":"

After the mysqlbackup component is loaded and active on the server, you can start page tracking manually with the following option:

$ SELECT mysqlbackup_page_track_set(true);\n
"},{"location":"page-tracking.html#check-the-lsn-value","title":"Check the LSN value","text":"

Check the LSN value starting from which changed pages are tracked with the following option:

$ SELECT mysqlbackup_page_track_get_start_lsn();\n
"},{"location":"page-tracking.html#stop-page-tracking","title":"Stop page tracking","text":"

To stop page tracking, use the following command:

$ SELECT mysqlbackup_page_track_set(false);\n
"},{"location":"page-tracking.html#purge-page-tracking-data","title":"Purge page tracking data","text":"

When you start page tracking, it creates a file under the server\u2019s datadir to collect data about changed pages. This file grows until you stop the page tracking. If you stop the server and then restart it, page tracking creates a new file but also keeps the old one. The old file continues to grow until you stop the page tracking explicitly.

If you purge the page tracking data, you should create a full backup afterward. To purge the page tracking data, do the following steps:

$ SELECT mysqlbackup_page_track_set(false);\n$ SELECT mysqlbackup_page_track_purge_up_to(9223372036854775807);\n/* Specify the LSN up to which you want to purge page tracking data. /\n9223372036854775807 is the highest possible LSN which purges all page tracking files.*/\n$ SELECT mysqlbackup_page_track_set(true);\n
"},{"location":"page-tracking.html#known-issue","title":"Known issue","text":"

If the index is built in place using an exclusive algorithm and then is added to a table after the last LSN checkpoint, you may generate a bad incremental backup using page tracking. For more details see PS-8032.

"},{"location":"page-tracking.html#uninstall-the-mysqlbackup-component","title":"Uninstall the mysqlbackup component","text":"

To uninstall the mysqlbackup component, use the following statement:

$ UNINSTALL COMPONENT \"file://component_mysqlbackup\"\n
"},{"location":"permissions.html","title":"Permissions needed","text":"

We will be referring to permissions to the ability of a user to access and perform changes on the relevant parts of the host\u2019s filesystem, starting/stopping services and installing software.

By privileges, we refer to the abilities of a database user to perform different kinds of actions on the database server.

There are many ways for checking the permission on a file or directory. For example, ls -ls /path/to/file or stat /path/to/file | grep Access will do the job:

$ stat /etc/mysql | grep Access\n
The result could look like this:

Expected output
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)\nAccess: 2011-05-12 21:19:07.129850437 -0300\n$ ls -ld /etc/mysql/my.cnf\n-rw-r--r-- 1 root root 4703 Apr  5 06:26 /etc/mysql/my.cnf\n

As in this example, my.cnf is owned by root and not writable for anyone else. Assuming that you do not have root\u2018s password, you can check what permissions you have on these types of files with sudo -l:

$ sudo -l\n
The results could look like this:

Expected output
Password:\nYou may run the following commands on this host:\n(root) /usr/bin/\n(root) NOPASSWD: /etc/init.d/mysqld\n(root) NOPASSWD: /bin/vi /etc/mysql/my.cnf\n(root) NOPASSWD: /usr/local/bin/top\n(root) NOPASSWD: /usr/bin/ls\n(root) /bin/tail\n

Being able to execute with sudo scripts in /etc/init.d/, /etc/rc.d/ or /sbin/service is the ability to start and stop services.

Also, If you can execute the package manager of your distribution, you can install or remove software with it. If not, having rwx permission over a directory will let you do a local installation of software by compiling it there. This is a typical situation in many hosting companies\u2019 services.

There are other ways for managing permissions, such as using PolicyKit, * Extended ACLs or SELinux*, which may be preventing or allowing your access. You should check them in that case.

See also

Connection and privileges needed

"},{"location":"point-in-time-recovery.html","title":"Point-in-time recovery","text":"

Recovering up to particular moment in database\u2019s history can be done with xtrabackup and the binary logs of the server.

Note that the binary log contains the operations that modified the database from a point in the past. You need a full datadir as a base, and then you can apply a series of operations from the binary log to make the data match what it was at the point in time you want.

$ xtrabackup --backup --target-dir=/path/to/backup\n$ xtrabackup --prepare --target-dir=/path/to/backup\n

For more details on these procedures, see Creating a backup and Preparing a backup.

Now, suppose that some time has passed, and you want to restore the database to a certain point in the past, having in mind that there is the constraint of the point where the snapshot was taken.

To find out what is the situation of binary logging in the server, execute the following queries:

mysql> SHOW BINARY LOGS;\n
Expected output
+------------------+-----------+\n| Log_name         | File_size |\n+------------------+-----------+\n| mysql-bin.000001 |       126 |\n| mysql-bin.000002 |      1306 |\n| mysql-bin.000003 |       126 |\n| mysql-bin.000004 |       497 |\n+------------------+-----------+\n

and

mysql> SHOW MASTER STATUS;\n
Expected output
+------------------+----------+--------------+------------------+\n| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |\n+------------------+----------+--------------+------------------+\n| mysql-bin.000004 |      497 |              |                  |\n+------------------+----------+--------------+------------------+\n

The first query will tell you which files contain the binary log and the second one which file is currently being used to record changes, and the current position within it. Those files are stored usually in the datadir (unless other location is specified when the server is started with the --log-bin= option).

To find out the position of the snapshot taken, see the xtrabackup_binlog_info at the backup\u2019s directory:

$ cat /path/to/backup/xtrabackup_binlog_info\n
Expected output
mysql-bin.000003      57\n

This will tell you which file was used at moment of the backup for the binary log and its position. That position will be the effective one when you restore the backup:

$ xtrabackup --copy-back --target-dir=/path/to/backup\n

As the restoration will not affect the binary log files (you may need to adjust file permissions, see Restoring a Backup), the next step is extracting the queries from the binary log with mysqlbinlog starting from the position of the snapshot and redirecting it to a file

$ mysqlbinlog /path/to/datadir/mysql-bin.000003 /path/to/datadir/mysql-bin.000004 \\\n--start-position=57 > mybinlog.sql\n

Note that if you have multiple files for the binary log, as in the example, you have to extract the queries with one process, as shown above.

Inspect the file with the queries to determine which position or date corresponds to the point-in-time wanted. Once determined, pipe it to the server. Assuming the point is 11-12-25 01:00:00:

$ mysqlbinlog /path/to/datadir/mysql-bin.000003 /path/to/datadir/mysql-bin.000004 \\\n--start-position=57 --stop-datetime=\"11-12-25 01:00:00\" | mysql -u root -p\n

and the database will be rolled forward up to that Point-In-Time.

"},{"location":"prepare-compressed-backup.html","title":"Prepare the backup","text":"

Before you can prepare the backup you\u2019ll 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/\n

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\u2019re 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/\n
Confirmation message
InnoDB: Starting shutdown...\nInnoDB: Shutdown completed; log sequence number 9293846\n170223 13:39:31 completed OK!\n

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

The next step is to restore the backup.

"},{"location":"prepare-full-backup.html","title":"Prepare a full backup","text":"

After making a backup with the --backup option, you need to prepare it in order to restore it. Data files are not point-in-time consistent until they are prepared, because they were copied at different times as the program ran, and they might have been changed while this was happening.

If you try to start InnoDB with these data files, it will detect corruption and stop working to avoid running on damaged data. The --prepare step makes the files perfectly consistent at a single instant in time, so you can run InnoDB on them.

You can run the prepare operation on any machine; it does not need to be on the originating server or the server to which you intend to restore. You can copy the backup to a utility server and prepare it there.

Note that Percona XtraBackup 8.0 can only prepare backups of MySQL 8.0, Percona Server for MySQL 8.0, and Percona XtraDB Cluster 8.0 databases. Releases prior to 8.0 are not supported.

During the prepare operation, xtrabackup boots up a kind of modified embedded InnoDB (the libraries xtrabackup was linked against). The modifications are necessary to disable InnoDB standard safety checks, such as complaining about the log file not being the right size. This warning is not appropriate for working with backups. These modifications are only for the xtrabackup binary; you do not need a modified InnoDB to use xtrabackup for your backups.

The prepare step uses this \u201cembedded InnoDB\u201d to perform crash recovery on the copied data files, using the copied log file. The prepare step is very simple to use: you simply run xtrabackup with the --prepare option and tell it which directory to prepare, for example, to prepare the previously taken backup run:

$ xtrabackup --prepare --target-dir=/data/backups/\n

When this finishes, you should see an InnoDB shutdown with a message such as the following, where again the value of LSN will depend on your system:

Expected output
InnoDB: Shutdown completed; log sequence number 137345046\n160906 11:21:01 completed OK!\n

All following prepares will not change the already prepared data files, you\u2019ll see that output says:

Expected output
xtrabackup: This target seems to be already prepared.\nxtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.\n

It is not recommended to interrupt xtrabackup process while preparing backup because it may cause data files corruption and backup will become unusable. Backup validity is not guaranteed if prepare process was interrupted.

Note

If you intend the backup to be the basis for further incremental backups, you should use the --apply-log-only option when preparing the backup, or you will not be able to apply incremental backups to it. See the documentation on preparing incremental backups for more details.

After preparing the backup, you can restore the backup.

"},{"location":"prepare-incremental-backup.html","title":"Prepare an incremental backup","text":"

The --prepare step for incremental backups is not the same as for full backups. In full backups, two types of operations are performed to make the database consistent: committed transactions are replayed from the log file against the data files, and uncommitted transactions are rolled back. You must skip the rollback of uncommitted transactions when preparing an incremental backup, because transactions that were uncommitted at the time of your backup may be in progress, and it\u2019s likely that they will be committed in the next incremental backup. You should use the --apply-log-only option to prevent the rollback phase.

Warning

If you do not use the --apply-log-only option to prevent the rollback phase, then your incremental backups will be useless. After transactions have been rolled back, further incremental backups cannot be applied.

Beginning with the full backup you created, you can prepare it, and then apply the incremental differences to it. Recall that you have the following backups:

/data/backups/base\n/data/backups/inc1\n/data/backups/inc2\n

To prepare the base backup, you need to run --prepare as usual, but prevent the rollback phase:

$ xtrabackup --prepare --apply-log-only --target-dir=/data/backups/base\n

The output should end with text similar to the following:

Expected output
InnoDB: Shutdown completed; log sequence number 1626007\n161011 12:41:04 completed OK!\n

The log sequence number should match the to_lsn of the base backup, which you saw previously.

Warning

This backup is actually safe to restore as-is now, even though the rollback phase has been skipped. If you restore it and start MySQL, InnoDB will detect that the rollback phase was not performed, and it will do that in the background, as it usually does for a crash recovery upon start. It will notify you that the database was not shut down normally.

To apply the first incremental backup to the full backup, run the following command:

$ xtrabackup --prepare --apply-log-only --target-dir=/data/backups/base \\\n--incremental-dir=/data/backups/inc1\n

This applies the delta files to the files in /data/backups/base, which rolls them forward in time to the time of the incremental backup. It then applies the redo log as usual to the result. The final data is in /data/backups/base, not in the incremental directory. You should see an output similar to:

Expected output
incremental backup from 1626007 is enabled.\nxtrabackup: cd to /data/backups/base\nxtrabackup: This target seems to be already prepared with --apply-log-only.\nxtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(4124244)\n...\nxtrabackup: page size for /tmp/backups/inc1/ibdata1.delta is 16384 bytes\nApplying /tmp/backups/inc1/ibdata1.delta to ./ibdata1...\n...\n161011 12:45:56 completed OK!\n

Again, the LSN should match what you saw from your earlier inspection of the first incremental backup. If you restore the files from /data/backups/base, you should see the state of the database as of the first incremental backup.

Warning

Percona XtraBackup does not support using the same incremental backup directory to prepare two copies of backup. Do not run --prepare with the same incremental backup directory (the value of \u2013incremental-dir) more than once.

Preparing the second incremental backup is a similar process: apply the deltas to the (modified) base backup, and you will roll its data forward in time to the point of the second incremental backup:

$ xtrabackup --prepare --target-dir=/data/backups/base \\\n--incremental-dir=/data/backups/inc2\n

Note

--apply-log-only should be used when merging the incremental backups except the last one. That\u2019s why the previous line does not contain the --apply-log-only option. Even if the --apply-log-only was used on the last step, backup would still be consistent but in that case server would perform the rollback phase.

Once prepared incremental backups are the same as the full backups, and they can be restored in the same way.

"},{"location":"prepare-individual-partitions-backup.html","title":"Prepare an individual partitions backup","text":"

For preparing partial backups, the procedure is analogous to restoring individual tables. Apply the logs and use xtrabackup --export:

$ xtrabackup --apply-log --export /mnt/backup/2012-08-28_10-29-09\n

You may see warnings in the output about tables that do not exist. This happens because InnoDB-based engines stores its data dictionary inside the tablespace files. xtrabackup removes the missing tables (those that haven\u2019t been selected in the partial backup) from the data dictionary in order to avoid future warnings or errors.

The next step is to restore the backup.

"},{"location":"prepare-partial-backup.html","title":"Prepare a partial backup","text":"

The procedure is analogous to restoring individual tables: apply the logs and use the --export option:

$ xtrabackup --prepare --export --target-dir=/path/to/partial/backup\n

When you use the --prepare option on a partial backup, you will see warnings about tables that don\u2019t exist. This is because these tables exist in the data dictionary inside InnoDB, but the corresponding .ibd files don\u2019t exist. They were not copied into the backup directory. These tables will be removed from the data dictionary, and when you restore the backup and start InnoDB, they will no longer exist and will not cause any errors or warnings to be printed to the log file.

Could not find any file associated with the tablespace ID: 5

Use --innodb-directories to find the tablespace files. If that fails then use -\u2013innodb-force-recovery=1 to ignore this and to permanently lose all changes to the missing tablespace(s).

The next step is to restore restore the partition from the backup.

"},{"location":"privileges.html","title":"Connection and privileges needed","text":"

Percona XtraBackup needs to be able to connect to the database server and perform operations on the server and the datadir when creating a backup, when preparing in some scenarios and when restoring it. In order to do so, there are privileges and permission requirements on its execution that must be fulfilled.

Privilege refers to the operations that a system user is permitted to do in the database server. They are set at the database server and only apply to users in the database server.

Permissions are those which permits a user to perform operations on the system, like reading, writing or executing on a certain directory or start/stop a system service. They are set at a system level and only apply to system users.

When xtrabackup is used, there are two actors involved: the user invoking the program - a system user - and the user performing action in the database server - a database user. Note that these are different users in different places, even though they may have the same username.

All the invocations of xtrabackup in this documentation assume that the system user has the appropriate permissions, and you are providing the relevant options for connecting the database server - besides the options for the action to be performed - and the database user has adequate privileges.

"},{"location":"privileges.html#connect-to-the-server","title":"Connect to the server","text":"

The database user used to connect to the server and its password are specified by the --user and --password option:

$ xtrabackup --user=DVADER --password=14MY0URF4TH3R --backup \\\n--target-dir=/data/bkps/\n

If you don\u2019t use the --user option, Percona XtraBackup will assume the database user whose name is the system user executing it.

"},{"location":"privileges.html#other-connection-options","title":"Other connection options","text":"

According to your system, you may need to specify one or more of the following options to connect to the server:

Option Description -port Use this port when connecting to the database with TCP/IP -socket Use this socket when connecting to the local database. -host Use this host when connecting to the database server with TCP/IP

These options are passed to the mysql child process without alteration, see mysql --help for details.

Note

In case of multiple server instances, the correct connection parameters (port, socket, host) must be specified in order for xtrabackup to talk to the correct server.

"},{"location":"privileges.html#privileges-needed","title":"Privileges needed","text":"

Once connected to the server, in order to perform a backup you need READ and EXECUTE permissions at a filesystem level in the server\u2019s datadir.

The database user needs the following privileges to back up tables or databases:

A SQL example of creating a database user with the minimum privileges required to take full backups would be:

mysql> CREATE USER 'bkpuser'@'localhost' IDENTIFIED BY 's3cr%T';\nmysql> GRANT BACKUP_ADMIN, PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'bkpuser'@'localhost';\nmysql> GRANT SELECT ON performance_schema.log_status TO 'bkpuser'@'localhost';\nmysql> GRANT SELECT ON performance_schema.keyring_component_status TO bkpuser@'localhost';\nmysql> GRANT SELECT ON performance_schema.replication_group_members TO bkpuser@'localhost';\nmysql> FLUSH PRIVILEGES;\n
"},{"location":"privileges.html#query-the-privileges","title":"Query the privileges","text":"

To query the privileges that your database user has been granted at the console of the server execute:

mysql> SHOW GRANTS;\n

or for a particular user with:

mysql> SHOW GRANTS FOR 'db-user'@'host';\n

It will display the privileges using the same format as for the GRANT statement.

Note that privileges may vary across versions of the server. To list the exact list of privileges that your server support (and a brief description of them) execute:

mysql> SHOW PRIVILEGES;\n

See also

Permissions needed

"},{"location":"quickstart-overview.html","title":"Quickstart Guide for Percona XtraBackup","text":"

Percona XtraBackup (PXB) is a 100% open source backup solution for all versions of Percona Server for MySQL and MySQL\u00ae that performs online non-blocking, tightly compressed, highly secure full backups on transactional systems. Maintain fully available applications during planned maintenance windows with Percona XtraBackup.

"},{"location":"quickstart-overview.html#install-percona-xtrabackup","title":"Install Percona XtraBackup:","text":"

You can install Percona XtraBackup using different methods:

"},{"location":"quickstart-overview.html#for-superior-and-optimized-performance","title":"For superior and optimized performance","text":"

Percona Server for MySQL (PS) is a freely available, fully compatible, enhanced, and open source drop-in replacement for any MySQL database. It provides superior and optimized performance, greater scalability and availability, enhanced backups, increased visibility, and instrumentation. Percona Server for MySQL is trusted by thousands of enterprises to provide better performance and concurrency for their most demanding workloads.

Install Percona Server for MySQL.

"},{"location":"quickstart-overview.html#for-high-availability","title":"For high availability","text":"

Percona XtraDB Cluster (PXC) is a 100% open source, enterprise-grade, highly available clustering solution for MySQL multi-master setups based on Galera. PXC helps enterprises minimize unexpected downtime and data loss, reduce costs, and improve performance and scalability of your database environments supporting your critical business applications in the most demanding public, private, and hybrid cloud environments.

Install Percona XtraDB Cluster.

"},{"location":"quickstart-overview.html#for-monitoring-and-management","title":"For Monitoring and Management","text":"

Percona Monitoring and Management (PMM) monitors and provides actionable performance data for MySQL variants, including Percona Server for MySQL, Percona XtraDB Cluster, Oracle MySQL Community Edition, Oracle MySQL Enterprise Edition, and MariaDB. PMM captures metrics and data for the InnoDB, XtraDB, and MyRocks storage engines, and has specialized dashboards for specific engine details.

Install PMM and connect your MySQL instances to it.

"},{"location":"release-notes.html","title":"Percona XtraBackup 8.0 release notes index","text":""},{"location":"restore-a-backup.html","title":"Restore a backup","text":"

Warning

Backup needs to be prepared before it can be restored.

For convenience, xtrabackup binary has the --copy-back option to copy the backup to the datadir of the server:

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

If you don\u2019t want to save your backup, you can use the --move-back option which will move the backed up data to the datadir.

If you don\u2019t want to use any of the above options, you can additionally use rsync or cp to restore the files.

Note

The datadir must be empty before restoring the backup. Also, it\u2019s important to note that MySQL server needs to be shut down before restore is performed. You cannot restore to a datadir of a running mysqld instance (except when importing a partial backup).

Example of the rsync command that can be used to restore the backup can look like this:

$ rsync -avrP /data/backup/ /var/lib/mysql/\n

You should check that the restored files have the correct ownership and permissions.

As files\u2019 attributes will be preserved, in most cases you will need to change the files\u2019 ownership to mysql before starting the database server, as they will be owned by the user who created the backup:

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

Data is now restored, and you can start the server.

"},{"location":"restore-individual-partitions.html","title":"Restore the partition from the backup","text":"

Restoring should be done by importing the tables in the partial backup to the server.

First step is to create new table in which data will be restored.

mysql> CREATE TABLE `name_p4` (\n`id` int(11) NOT NULL AUTO_INCREMENT,\n`name` text NOT NULL,\n`imdb_index` varchar(12) DEFAULT NULL,\n`imdb_id` int(11) DEFAULT NULL,\n`name_pcode_cf` varchar(5) DEFAULT NULL,\n`name_pcode_nf` varchar(5) DEFAULT NULL,\n`surname_pcode` varchar(5) DEFAULT NULL,\nPRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2812744 DEFAULT CHARSET=utf8\n

Note

Generate a .cfg metadata file by running FLUSH TABLES ... FOR EXPORT. The command can only be run on a table, not on the individual table partitions. The file is located in the table schema directory and is used for schema verification when importing the tablespace.

To restore the partition from the backup, the tablespace must be discarded for that table:

mysql> ALTER TABLE name_p4 DISCARD TABLESPACE;\n

The next step is to copy the .ibd file from the backup to the MySQL data directory:

cp /mnt/backup/2012-08-28_10-29-09/imdb/name#P#p4.ibd /var/lib/mysql/imdb/name_p4.ibd\n

Note

Make sure that the copied files can be accessed by the user running MySQL.

The last step is to import the tablespace:

mysql> ALTER TABLE name_p4 IMPORT TABLESPACE;\n
"},{"location":"restore-individual-tables.html","title":"Restore individual tables","text":"

Percona XtraBackup can export a table that is contained in its own .ibd file. With Percona XtraBackup, you can export individual tables from any InnoDB database, and import them into Percona Server for MySQL with XtraDB or MySQL 8.0. The source doesn\u2019t have to be XtraDB or MySQL 8.0, but the destination does. This method only works on individual .ibd files.

The following example exports and imports the following table:

CREATE TABLE export_test (\na int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n
"},{"location":"restore-individual-tables.html#export-the-table","title":"Export the table","text":"

To generate an .ibd file in the target directory, create the table using the innodb_file_per_table mode:

$ find /data/backups/mysql/ -name export_test.*\n/data/backups/mysql/test/export_test.ibd\n

During the --prepare step, add the --export option to the command. For example:

$ xtrabackup --prepare --export --target-dir=/data/backups/mysql/\n

When restoring an encrypted InnoDB tablespace table, add the keyring file:

$ xtrabackup --prepare --export --target-dir=/tmp/table \\\n--keyring-file-data=/var/lib/mysql-keyring/keyring\n

The following files are the only files required to import the table into a server running Percona Server for MySQL with XtraDB or MySQL 8.0. If the server uses InnoDB Tablespace Encryption, add the .cfp file, which contains the transfer key and an encrypted tablespace key.

The files are located in the target directory:

/data/backups/mysql/test/export_test.ibd\n/data/backups/mysql/test/export_test.cfg\n
"},{"location":"restore-individual-tables.html#import-the-table","title":"Import the table","text":"

On the destination server running Percona Server for MySQL with XtraDB or MySQL 8.0, create a table with the same structure, and then perform the following steps:

  1. Run the ALTER TABLE test.export_test DISCARD TABLESPACE; command. If you see the following error message:

    Error message
    ERROR 1809 (HY000): Table 'test/export_test' in system tablespace\n

    enable innodb_file_per_table option on the server and create the table again.

    $ set global innodb_file_per_table=ON;\n
  2. Copy the exported files to the test/ subdirectory of the destination server\u2019s data directory.

  3. Run ALTER TABLE test.export_test IMPORT TABLESPACE;

    The table is imported, and you can run a SELECT to see the imported data.

"},{"location":"restore-partial-backup.html","title":"Restore a partial backup","text":"

Restoring should be done by restoring individual tables in the partial backup to the server.

It can also be done by copying back the prepared backup to a \u201cclean\u201d datadir (in that case, make sure to include the mysql database) to the datadir you are moving the backup to. A system database can be created with the following:

$ sudo mysql --initialize --user=mysql\n

Once you start the server, you may see mysql complaining about missing tablespaces:

Expected output
2021-07-19T12:42:11.077200Z 1 [Warning] [MY-012351] [InnoDB] Tablespace 4, name 'test1/t1', file './d2/test1.ibd' is missing!\n2021-07-19T12:42:11.077300Z 1 [Warning] [MY-012351] [InnoDB] Tablespace 4, name 'test1/t1', file './d2/test1.ibd' is missing!\n

In order to clean the orphan database from the data dictionary, you must manually create the missing database directory and then DROP this database from the server.

Example of creating the missing database:

$ mkdir /var/lib/mysql/test1/d2\n

Example of dropping the database from the server:

mysql> DROP DATABASE d2;\n
Expected output
Query OK, 2 rows affected (0.5 sec)\n
"},{"location":"server-backup-version-comparison.html","title":"Server version and backup version comparison","text":"

A MySQL change to a feature, such as the structure of a redo log record, can cause older versions of Percona XtraBackup to fail. To ensure that you can back up and restore your data, use a Percona XtraBackup version that is equal to or above your source server version.

See also

How XtraBackup works

Percona XtraBackup 8.0.21 adds the --no-server-version-check option. Before the backup starts, XtraBackup compares the source system version to the Percona XtraBackup version. If the source system version is greater than the XtraBackup version, XtraBackup stops the backup and returns an error message. This comparison prevents a failed backup or a corrupted backup due to source system changes.

The parameter checks for the following scenarios:

Explicitly adding the --no-server-version-check parameter, like the example, overrides the parameter and the backup proceeds.

$ xtrabackup --backup --no-server-version-check --target-dir=$mysql/backup1\n

When you override the parameter, the following events can happen:

"},{"location":"set-up-replication.html","title":"How to set up a replica for replication in 6 simple steps with Percona XtraBackup","text":"

Data is, by far, the most valuable part of a system. Having a backup done systematically and available for a rapid recovery in case of failure is admittedly essential to a system. However, it is not common practice because of its costs, infrastructure needed or even the boredom associated to the task. Percona XtraBackup is designed to solve this problem.

You can have almost real-time backups in 6 simple steps by setting up a replication environment with Percona XtraBackup.

"},{"location":"set-up-replication.html#all-the-things-you-will-need","title":"All the things you will need","text":"

Setting up a replica for replication with Percona XtraBackup is a straightforward procedure. In order to keep it simple, here is a list of the things you need to follow the steps without hassles:

Source

A system with a MySQL-based server installed, configured and running. This system will be called Source, as it is where your data is stored and the one to be replicated. We will assume the following about this system:

Replica

Another system, with a MySQL-based server installed on it. We will refer to this machine as Replica and we will assume the same things we did about Source, except that the server-id on Replica is 2.

Percona XtraBackup

The backup tool we will use. It should be installed in both computers for convenience.

Note

It is not recommended to mix MySQL variants (Percona Server, MySQL) in your replication setup. This may produce incorrect xtrabackup_slave_info file when adding a new replica.

"},{"location":"set-up-replication.html#version-updates","title":"Version updates","text":"

The 8.0.23 version deprecates the CHANGE_MASTER_TO command. In that version and later, use the CHANGE_REPLICATION_SOURCE_TO and the appropriate options instead.

The 8.0.22 version deprecates theSTART SLAVE command. In that version or later, use START REPLICA instead.

"},{"location":"set-up-replication.html#1-make-a-backup-on-the-source-and-prepare-it","title":"1. Make a backup on the Source and prepare it","text":"

At the Source, issue the following to a shell:

$ xtrabackup --backup --user=yourDBuser --password=MaGiCdB1 --target-dir=/path/to/backupdir\n

After this is finished you should get:

Expected output
xtrabackup: completed OK!\n

This will make a copy of your MySQL data dir to the /path/to/backupdir directory. You have told Percona XtraBackup to connect to the database server using your database user and password, and do a hot backup of all your data in it (all MyISAM, InnoDB tables and indexes in them).

In order for snapshot to be consistent you need to prepare the data on the source:

$ xtrabackup --prepare --target-dir=/path/to/backupdir\n

You need to select path where your snapshot has been taken. If everything is ok you should get the same OK message. Now the transaction logs are applied to the data files, and new ones are created: your data files are ready to be used by the MySQL server.

Percona XtraBackup knows where your data is by reading your my.cnf file. If you have your configuration file in a non-standard place, you should use the flag --defaults-file =/location/of/my.cnf.

If you want to skip writing the username and password every time you want to access MySQL, you can set it up in .mylogin.cnf as follows:

mysql_config_editor set --login-path=client --host=localhost --user=root --password\n

For more information, see MySQL Configuration Utility.

This statement provides root access to MySQL.

"},{"location":"set-up-replication.html#2-copy-backed-up-data-to-the-replica","title":"2. Copy backed up data to the Replica","text":"

On the Source, use rsync or scp to copy the data from the Source to the Replica. If you are syncing the data directly to replica\u2019s data directory, we recommend that you stop the mysqld there.

$ rsync -avpP -e ssh /path/to/backupdir Replica:/path/to/mysql/\n

After data has been copied, you can back up the original or previously installed MySQL datadir (NOTE: Make sure mysqld is shut down before you move the contents of its datadir, or move the snapshot into its datadir.). Run the following commands on the Replica:

$ mv /path/to/mysql/datadir /path/to/mysql/datadir_bak\n

and move the snapshot from the Source in its place:

$ xtrabackup --move-back --target-dir=/path/to/mysql/backupdir\n

After you copy data over, make sure the Replica MySQL has the proper permissions to access them.

$ chown mysql:mysql /path/to/mysql/datadir\n

If the ibdata and iblog files are located in directories outside the datadir, you must put these files in their proper place after the logs have been applied.

"},{"location":"set-up-replication.html#3-configure-the-sources-mysql-server","title":"3. Configure the Source\u2019s MySQL server","text":"

On the source, run the following command to add the appropriate grant. This grant allows the replica to be able to connect to source:

mysql> GRANT REPLICATION SLAVE ON *.*  TO 'repl'@'$replicaip'\nIDENTIFIED BY '$replicapass';\n

Also make sure that firewall rules are correct and that the Replica can connect to the Source. Run the following command on the Replica to test that you can run the mysql client on Replica, connect to the Source, and authenticate.

mysql> mysql --host=Source --user=repl --password=$replicapass\n

Verify the privileges.

mysql> SHOW GRANTS;\n
"},{"location":"set-up-replication.html#4-configure-the-replicas-mysql-server","title":"4. Configure the Replica\u2019s MySQL server","text":"

Copy the my.cnf file from the Source to the Replica:

$ scp user@Source:/etc/mysql/my.cnf /etc/mysql/my.cnf\n

and change the following options in /etc/mysql/my.cnf:

server-id=2\n

and start/restart mysqld on the Replica.

In case you\u2019re using init script on Debian-based system to start mysqld, be sure that the password for debian-sys-maint user has been updated, and it\u2019s the same as that user\u2019s password on the Source. Password can be seen and updated in /etc/mysql/debian.cnf.

"},{"location":"set-up-replication.html#5-start-the-replication","title":"5. Start the replication","text":"

On the Replica, review the content of the file xtrabackup_binlog_info, it will be something like:

$ cat /var/lib/mysql/xtrabackup_binlog_info\n

The results should resemble the following:

Expected output
Source-bin.000001     481\n

The term master is deprecated. Do the following on a MySQL console and use the username and password you\u2019ve set up in STEP 3 :

CHANGE REPLICATION SOURCE TO\nSOURCE_HOST='$sourceip',\nSOURCE_USER='repl',\nSOURCE_PASSWORD='$replicapass',\nSOURCE_LOG_FILE='Source-bin.000001',\nSOURCE_LOG_POS=481;\n

Start the replica:

START REPLICA;\n

The term slave is deprecated. Do the following:

"},{"location":"set-up-replication.html#6-check","title":"6. Check","text":"

On the Replica, check that everything went OK with:

SHOW REPLICA STATUS\\G\n

The result shows the status:

Expected output
Slave_IO_Running: Yes\nSlave_SQL_Running: Yes\nSeconds_Behind_Master: 13\n

Both IO and SQL threads need to be running. The Seconds_Behind_Master means the SQL currently being executed has a current_timestamp of 13 seconds ago. It is an estimation of the lag between the Source and the Replica. Note that at the beginning, a high value could be shown because the Replica has to \u201ccatch up\u201d with the Source.

"},{"location":"set-up-replication.html#adding-more-replicas-to-the-source","title":"Adding more replicas to the Source","text":"

You can use this procedure with slight variation to add new replicas to a source. We will use Percona XtraBackup to clone an already configured replica. We will continue using the previous scenario for convenience, but we will add a NewReplica to the plot.

At the Replica, do a full backup:

$ xtrabackup --user=yourDBuser --password=MaGiCiGaM \\\n--backup --slave-info --target-dir=/path/to/backupdir\n

By using the --slave-info Percona XtraBackup creates additional file called xtrabackup_slave_info.

Apply the logs:

$ xtrabackup --prepare --use-memory=2G --target-dir=/path/to/backupdir/\n

Note

In the prepare phase, the --use-memory parameter speeds up the process if the amount of RAM assigned to the option is available. Use the parameter only in the prepare phase. In the other phases the parameter makes the application lazy allocate this memory (reserve) but does not affect database pages.

Copy the directory from the Replica to the NewReplica (NOTE: Make sure mysqld is shut down on the NewReplica before you copy the contents the snapshot into its datadir.):

rsync -avprP -e ssh /path/to/backupdir NewReplica:/path/to/mysql/datadir\n

For example, to set up a new user, user2, you add another grant on the Source:

> GRANT REPLICATION SLAVE ON *.*  TO 'user2'@'$newreplicaip'\nIDENTIFIED BY '$replicapass';\n

On the NewReplica, copy the configuration file from the Replica:

$ scp user@Replica:/etc/mysql/my.cnf /etc/mysql/my.cnf\n

Make sure you change the server-id variable in /etc/mysql/my.cnf to 3 and disable the replication on start:

skip-slave-start\nserver-id=3\n

After setting server_id, start mysqld.

Fetch the master_log_file and master_log_pos from the file xtrabackup_slave_info, execute the statement for setting up the source and the log file for the NewReplica:

> CHANGE MASTER TO\n     MASTER_HOST='$Sourceip',\n     MASTER_USER='repl',\n     MASTER_PASSWORD='$replicapass',\n     MASTER_LOG_FILE='Source-bin.000001',\n     MASTER_LOG_POS=481;\n

The term master is deprecated. Do the following and then start the replica:

The term slave is deprecated. Do the following:

> START REPLICA;\n

If both IO and SQL threads are running when you check the NewReplica, server is replicating the Source.

See also

How to create a new (or repair a broken) GTID based slave

"},{"location":"smart-memory-estimation.html","title":"Smart memory estimation","text":"

The Smart memory estimation is tech preview feature. Before using Smart memory estimation 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 Smart memory estimation feature. With this feature, Percona XtraBackup computes the memory required for prepare phase, while copying redo log entries during the backup phase. Percona XtraBackup also considers the number of InnoDB pages to be fetched from the disk.

Percona XtraBackup performs the backup procedure in two steps:

"},{"location":"smart-memory-estimation.html#how-does-smart-memory-estimation-work","title":"How does Smart memory estimation work","text":"

In the prepare phase, Percona XtraBackup checks the server\u2019s available free memory and uses that memory up to the limit specified in the --use-free-memory-pct option to run --prepare. Due to backward compatibility, the default value for the --use-free-memory-pct option is 0 (zero), which defines the option as disabled. For example, if you set --use-free-memory-pct=50, then 50% of the free memory is used to prepare a backup.

Starting with Percona XtraBackup 8.0.32-26, you can enable or disable the memory estimation during the backup phase with the --estimate-memory option. The default value is OFF. Enable the memory estimation with --estimate-memory=ON:

$ xtrabackup --backup --estimate-memory=ON --target-dir=/data/backups/\n

In the prepare phase, enable the --use-free-memory-pct option by specifying the percentage of free memory to be used to prepare a backup. The --use-free-memory-pct value must be larger than 0.

For example:

$ xtrabackup --prepare --use-free-memory-pct=50 --target-dir=/data/backups/\n
"},{"location":"smart-memory-estimation.html#example-of-smart-memory-estimation-usage","title":"Example of Smart memory estimation usage","text":"

The examples of how Smart memory estimation can improve the time spent on prepare in different versions of Percona XtraBackup:

In Percona XtraBackup 8.0.32-26 and higherIn Percona XtraBackup 8.0.30-23 and higher

We back up 16, 32, and 64 tables using sysbench. Each set contains 1M rows. In the backup phase, we enable Smart memory estimation with --estimate-memory=ON. In the prepare phase, we set --use-free-memory-pct=50, and Percona XtraBackup uses 50% of the free memory to prepare a backup. The backup is run on an ec2 c4.8xlarge instance (36 vCPUs / 60GB memory / General Purpose SSD (gp2)).

We back up 16, 32, and 64 tables using sysbench. Each set contains 1M rows. In the prepare phase, we set --use-free-memory-pct=50, and Percona XtraBackup uses 50% of the free memory to prepare a backup. The backup is run on an ec2 c4.8xlarge instance (36 vCPUs / 60GB memory / General Purpose SSD (gp2)).

During each --backup, the following sysbench is run:

sysbench --db-driver=mysql --db-ps-mode=disable --mysql-user=sysbench --mysql-password=sysbench --table_size=1000000 --tables=${NUM_OF_TABLES} --threads=24 --time=0 --report-interval=1 /usr/share/sysbench/oltp_write_only.lua run\n

The following table shows the backup details (all measurements are in Gigabytes):

Used memory Size of XtraBackup log Size of backup 16 tables 3.375 0.7 4.7 32 tables 8.625 2.6 11 64 tables 18.5 5.6 22

Prepare executed without Smart memory estimation uses the default of 128MB for the buffer pool.

The results are the following:

Note

The following results are based on tests in a specific environment. Your results may vary.

"},{"location":"store-backup-history.html","title":"Store backup history on the server","text":"

Percona XtraBackup supports storing the backups history on the server. This feature was implemented in Percona XtraBackup 2.2. Storing backup history on the server was implemented to provide users with additional information about backups that are being taken. Backup history information will be stored in the PERCONA_SCHEMA.XTRABACKUP_HISTORY table.

To use this feature the following options are available: