To follow this guide, ideally you should have Percona MySQL installed and configured in the way we described in our linked guide. But Percona XtraBackup supports all MySQL flavours like Percona Server, MariaDB, and the original MySQL from Oracle. You must apply the fixes to resolve problems such as Debian distro-specific automatic restart issues. If the server you are going to work is of live website, then first you should take a manual backup and test whether it is working.
Why We Need Percona XtraBackup?
mysqldump
is the commonly used trusted backup tool which comes with the MySQL package. It is a multi-threaded process for backup and single-threaded for restore. It is the best tool if databases are less than 20GB and you are manually working. In this way, the restore process will take higher time. Percona XtraBackup is like super-charged mysqldump
which supports incremental backup. It is a good tool to backup >20GB databases. It is fast, supports compression, encryption, a suitable tool for master/slave setup.
Steps to Install Percona XtraBackup
First, you need to create a backup-user of MySQL. Run these commands :
---
1 2 3 4 5 6 7 | # mysql -u root -p CREATE USER 'backupuser'@'localhost' IDENTIFIED BY 'use-own-password'; GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost'; FLUSH PRIVILEGES; exit # |
Create a new directory to store the MySQL backup files:
1 2 3 4 5 6 7 | # mkdir -p /data/backups/mysql/ ## optional steps touch /data/backups/mysql/README.md echo "I have manually created this directory for Percona XtraBackup" > /data/backups/mysql/README.md cat # |
Now, fetch the repository packages from Percona’s website:
1 2 3 4 5 | # wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb # |
Once you install the package, the Percona repositories should be added in the /etc/apt/sources.list.d/percona-release.list
file. Now, install it :
1 2 3 4 5 | # sudo apt-get update sudo apt-get install percona-xtrabackup-24 # |
For Percona’s software, we mentioned in our previous guides the need to pin the selected packages to avoid the upgrades from the distribution repositories. Essentially, you need to create a new file named /etc/apt/preferences.d/00percona.pref
:
1 2 3 | # nano /etc/apt/preferences.d/00percona.pref # |
… and add the following lines in it:
1 2 3 | Package: * Pin: release o=Percona Development Team Pin-Priority: 1001 |
You can take backup using this format of command :
1 2 3 | # innobackupex --user=backupuser --password=use-own-password--no-timestamp /data/backups/first_backup # |
After creating the backup, the data is not ready to be restored. We need the prepare for restoration :
1 2 3 | # innobackupex --apply-log /data/backups/first_backup # |
Wait still the process is completed. The backup is now ready to be restored on the same server or on the another server. Below is how you’ll restore backup in case of MariaDB :
1 2 3 4 5 6 7 8 9 | # systemctl stop mysql mkdir ~/mysql_old/ mv /var/lib/mysql/* ~/mysql_old/ innobackupex --copy-back /data/backups/my_backup # wait for 'innobackupex: completed OK' message chown -R mysql:mysql /var/lib/mysql systemctl start mysql # |
Percona has detailed documentation :
1 2 3 | # https://www.percona.com/doc/percona-xtrabackup/2.3/index.html # |
There are various user created bash scripts available on GitHub to automate the process. Here is an example of bash script on my GitHub repo to automate the full incremental backup.
Tagged With https://thecustomizewindows com/2019/10/how-to-install-percona-xtrabackup-on-ubuntu-server/ , innodbbackupex restore backup to new server , install xtrabackup 2 4 on ubuntu , install xtrabackup manualy