Backup with Percona XtraBackup on Ubuntu 16.04

percona xtrabackup

Introduction

Percona XtraBackup is an open source backup utility for MySQL-based servers that doesn’t lock your database while performing backup. Using it provides the following benefits:

  • Backups are completed quickly and reliably
  • Uninterrupted transaction processing during backups
  • Savings on disk space and network bandwidth
  • Automatic backup verification
  • Higher uptime due to faster restore time

This tool works with MySQL, but also with MariaDB and Percona Server. It supports backup of InnoDB, XtraDB, and HailDB.
In this guide, we’ll install Percona XtraBackup on an Ubuntu 16.04.

Install Percona XtraBackup

First of all, you’ll need access to your server console (of course).
We will use the latest package of this utility, so, add the Percona repository with the following command:

$ wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb

Then, install the downloaded package with dpkg:

# dpkg -i percona-release_0.1-4.xenial_all.deb

Now, update the local cache:

# apt-get update

And finally, install Percona XtraBackup:

# apt-get install percona-xtrabackup-24

We have now successfully installed Percona XtraBackup.

Configure a new user and a backup directory

Assuming you have a MySQL compatible database already, access its shell as the root user:

mysql -u root -p

Then, create a new user, called ‘backupusr’, with the password ‘mypwd’:

CREATE USER 'backupusr'@'localhost' IDENTIFIED BY 'mypwd'

Grant this user the privileges “RELOAD, PROCESS, LOCKTABLE, REPLICATION CLIENT”:

GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'backupusr'@'localhost';
FLUSH PRIVILEGES;
exit

Then, create a folder in which you can store the backup, for example:

mkdir -p ~/backup/mysql/

Performing backup

So, now we want to back up our databases. To start the process:

xtrabackup --backup --target-dir=~/backup/mysql/

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.

That’s it! you have performed a backup of your database.

NOTE: if the DB data or log files aren’t stored in the same directory, you might need to specify the location of those.