Creating a MySQL Backup Using the XtraBackup Utility

Percona XtraBackup  is a hot backup utility for  MySQL databases .

No table locks occur during data backup, your system continues to operate without any restrictions.

XtraBackup 2.4  can back up InnoDBXtraDB  and  MyISAM tables   on MySQL 5.11, 5.5, 5.6 and 5.7 servers  , as well as  Percona  for  MySQL  with  XtraDB .

To work with  MySQL 8.x  , you should use  XtraBackup 8.x. This article will only talk about  XtraBackup 2.4.

The main advantage of  XtraBackup  is that this utility is suitable for both backing up highly loaded servers and systems with a low number of transactions.

If the total size of your MySQL databases is significant (tens of gigabytes), then the standard mysqldump utility   will not allow you to quickly create a backup, and restoring the dump will take a long time.

Installation

Installing  XtraBackup  from apt  Percona repository  .

Run the following commands in sequence:

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

sudo apt-get update 

sudo apt-get install percona-xtrabackup-24

2 . After installation, run the command  xtrabackup -v. Since, it is important to make sure that the utility works correctly on the server. As a result, something similar will be displayed on the screen:

xtrabackup: recognized server arguments: β€” datadir=/var/lib/mysql β€” tmpdir=/tmp β€” server-id=1 β€” logbin=/var/log/mysql/mysql-bin.log β€” innodbbufferpoolsize=16384M β€” innodbfilepertable=1 β€” innodbflushmethod=Odirect β€” innodbflushlogattrxcommit=0xtrabackup version 2.4.20 based on MySQL server 5.7.26 Linux (x8664) (revision id: c8b4056)

,  

XtraBackup :

  • MySQL.

  •  datadir

  •  target-dir .

datadir?

datadir β€” ,  MySQL  . , . Linux  /var/lib/mysql.

target-dir ?

target-dir β€” , .

, :

  • RELOAD LOCK TABLES

  • REPLICATION CLIENT

  • CREATE TABLESPACE

  • PROCESS

  • SUPER

  • CREATE

  • INSERT

  • SELECT

 

XtraBackup , , MySQL.

?

, ,  /etc/my.cnf.

XtraBackup  [mysqld]  [xtrabackup]  MySQL. , .

,  datadir   InnoDB XtraBackup  .

XtraBackup ,  [mysqld],  [xtrabackup]. , .

my.cnf. . ,  [xtrabackup]  my.cnf β€”  target_dir, , . .

 my.cnf:

[xtrabackup]
target_dir = /data/backups/mysql/

:

#!/bin/bash

#     
rm -rf /mysql/backup

# C 
xtrabackup --user=xtrabackup \
 --password=xxxx_SECRET_xxxx \
 --backup \
 --target-dir=/mysql/backup

#     
xtrabackup --prepare --target-dir=/mysql/backup

#  
tar -zcvf /home/developer/dumps/xtrabackup-all-dbs-"$(date +%F-%H:%M:%S)".gz /mysql/backup

?

() , :

rm -rf /mysql/backup.

,  XtraBackup   /mysql/backup/:

xtrabackup --user=xtrabackup --password=xxxxz1cYf95550Gc6xxxxxxxpE3rB03xxxx --backup --target-dir=/mysql/backup

MySQL xtrabackup . target-dir , .

!

:

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

/mysql/backup , . 

, .  xtrabackup --prepare --target-dir=/mysql/backup .

. , . .

, β€” , :

tar -zcvf /home/developer/dumps/xtrabackup-all-dbs-Β«$(date % F% H% M% S)Β».gz /mysql/backup

 

. .

.  datadir.

datadir?

.

1

 XtraBackup.  --copy-bak

 datadir  :

xtrabackup --copy-back --target-dir=/mysql/backup

2

,  XtraBackup.

, β€”  datadir.  cp  rsync.

,  datadir.

, :

  • MySQL .

  • Empty the datadir folder   or move its contents to another location. The datadir directory   must be empty.

Once the data has been transferred to  datadir, the  MySQL server can be started.

Materials used

Official documentation of Percona XtraBackup .




All Articles