Two common Percona-xtrabackup tool command:
1.xtrabackup command: Only InnoDB database storage engines and XtraDB nonblocking backup
2.innobackupex command: perl encapsulated by a layer xtrabackup, backup MyISAM achieved by adding a read lock table.
Article Directory
Percona-xtrabackup installation tool
Percona yum install expansion of warehouse:
[root@linux ~]# yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
Start Repository:
[root@linux ~]# percona-release enable-only tools release
Install version 2.4 of xtrabackup:
yum -y install percona-xtrabackup-24
Create a user backup of the database:
mysql> grant reload,lock tables,replication client,process,super on *.* to userbak@'localhost' identified by 'user123';
# Create a user userbak, password user123, delegated authority: reload, lock tables, replication client, process, super
Refresh permissions:
mysql> flush privileges;
Create a backup file storage directory:
[root@centos02 ~]# mkdir /data/mysqlbak
Full backup and restore mysql database
Backup:
[root@centos02 ~]# innobackupex --defaults-file=/etc/my.cnf --user=userbak --password=user123 /data/mysqlbak -S /tmp/mysql.sock
# As the host to create user-defined authorization userbak to localhost, so need to use the -S parameter to specify the socket file, if the user is authorized to host 127.0.0.1 or the actual IP address, use the -h parameter to specify the host
View backed up files:
[root@centos02 ~]# ls /data/mysqlbak/2019-10-26_14-42-29/
backup-my.cnf ibdata1 mysql performance_schema test xtrabackup_checkpoints xtrabackup_info xtrabackup_logfile
# Directory to store the backup files are automatically named according to the backup time
Mysql directory comparison with the size of the backup directory:
[root@centos02 ~]# du -sh /data/mysql
111M /data/mysql
[root@centos02 ~]# du -sh /data/mysqlbak/
15M /data/mysqlbak/
# It can be seen by strabackup backup tool is to save disk space
restore:
Stop mysql service:
[root@centos02 ~]# service mysql stop
Delete the file datadir directory:
[root@centos02 ~]# rm -rf /data/mysql/*
Note:
Because the data backup may contain the transaction has not been submitted or has been submitted but not yet synchronized to the data file transactions. Therefore, at this time the data file is still in an inconsistent state. The main role of "preparation" is the use of available data files in a consistent state by transaction rollback uncommitted transaction synchronization and has been submitted to the data file.
The data file to maintain consistency:
[root@centos02 ~]# innobackupex --apply-log /data/mysqlbak/2019-10-26_14-42-29/
# Step in the realization of this preparation process, if the server is idle more than enough memory, you can use -user-memory parameter to specify the memory, so that speed, the default 100M
restore:
[root@centos02 ~]# innobackupex --defaults-file=/etc/my.cnf --copy-back /data/mysqlbak/2019-10-26_14-42-29/
The owner and group of the changed file recovery:
[root@centos02 ~]# chown -R mysql:mysql /data/mysql
Then you can start mysql service #
Incremental backup and restore mysql database
Note: The premise must have an incremental backup is a full backup
The first incremental backup:
[root@centos02 ~]# ls /data/mysqlbak/
2019-10-26_14-42-29
[root@centos02 ~]# innobackupex --user=userbak --password=user123 --incremental /data/mysqlbak/ --incremental-basedir=/data/mysqlbak/2019-10-26_14-42-29 -S /tmp/mysql.sock
Description:
Incremental backup requires the use - -incremental specified incremental backup storage path
using - -incremental-basedir specify a path full backup, that do incremental backups based on the full amount
Second incremental backup:
[root@centos02 ~]# ls /data/mysqlbak/
2019-10-26_14-42-29 2019-10-26_16-31-37
[root@centos02 ~]# innobackupex --user=userbak --password=user123 --incremental /data/mysqlbak/ --incremental-basedir=/data/mysqlbak/2019-10-26_16-31-37 -S /tmp/mysql.sock
Description:
This - -incremental-basedir need to specify a directory on an incremental backup, that is based on the time to do incremental incremental backup
Incremental Backup Recovery:
The current backup directory contains a full backup and two incremental backups:
[root@centos02 ~]# ls /data/mysqlbak/
2019-10-26_14-42-29 2019-10-26_16-31-37 2019-10-26_16-38-00
Stop mysql service:
[root@centos02 ~]# service mysql stop
Empty mysql data storage directory of the file:
[root@centos02 ~]# rm -rf /data/mysql/*
Prepare the whole amount:
[root@centos02 ~]# innobackupex --apply-log --redo-only /data/mysqlbak/2019-10-26_14-42-29/
Preparation for the first time increment:
[root@centos02 ~]# innobackupex --apply-log --redo-only /data/mysqlbak/2019-10-26_14-42-29/ --incremental-dir=/data/mysqlbak/2019-10-26_16-31-37
Preparing a second increment (the last incremental without - -redo-only):
[root@centos02 ~]# innobackupex --apply-log /data/mysqlbak/2019-10-26_14-42-29/ --incremental-dir=/data/mysqlbak/2019-10-26_16-38-00
Prepare full amount again (without - -redo-only):
[root@centos02 ~]# innobackupex --apply-log /data/mysqlbak/2019-10-26_14-42-29/
Note: Prepare the last incremental backup and full backup again when ready, without - -redo-only
Recovery: innobackupex --copy-back / full backup directory
[root@centos02 ~]# innobackupex --copy-back /data/mysqlbak/2019-10-26_14-42-29/
View datadir catalog:
[root@centos02 ~]# ls /data/mysql
ibdata1 ib_logfile0 ib_logfile1 ibtmp1 mysql performance_schema test test_mysql xtrabackup_info xtrabackup_master_key_id
# Data file recovery
Change the recovered data file the owner and group:
[root@centos02 ~]# chown -R mysql:mysql /data/mysql
Then you can start mysql service #
Added:
1. If every incremental backup is a backup to do incremental backups based on the previous time increment, then the recovery operation ready when you need to prepare the first full backup and every increase prepare
2. If each incremental backup is based on the first full backup, then the recovery time only need to prepare the first full backup and the last increase in equipment
MariaDB10.3.x full amount or later / incremental backup and recovery
MariaDB10.3.x and above versions have problems with Percona XtraBackup tool because MariaDB10.3 or later redo log format and before different.
Solution: Use mariabackup, it is an open source tool MariaDB provided for InnoDB, Aria and MyISAM tables physics online backup, this tool is based on the Percona of XtraBackup (version 2.3.8) solutions.
Full backup and restore:
Backup:
[root@linux ~]# mariabackup --defaults-file=/etc/my.cnf --backup --user=bakuser --password=bak123 --target-dir /data/mysqlbak/20191026
# Xtrabackup tool with a different backup file storage directory is Mariabackup needs its own definition and xtrabackup tool automatically generates the time, simply specify the / data / mysqlbak directory can
restore:
1. Stop the service and empty datadir:
[root@linux ~]# service mysql stop
Redirecting to /bin/systemctl stop mysql.service
[root@linux ~]# rm -rf /data/mysql/*
2. Prepare:
[root@linux ~]# mariabackup --prepare --target-dir /data/mysqlbak/20191026/
3. Start Recovery:
[root@linux ~]# mariabackup --copy-back --target-dir /data/mysqlbak/20191026/
4. Change the owner and restore files Group:
[root@linux ~]# chown -R mysql:mysql /data/mysql
# Successful, then you can start the service
Incremental backup and recovery:
Note: The premise of incremental backups need to have to have a full backup
The first increase in equipment:
[root@linux ~]# mariabackup --backup --user=bakuser --password=bak123 --target-dir /data/mysqlbak/20191026_inc1 --incremental-basedir /data/mysqlbak/20191026/
# - -target-dir defined by backup file storage path, - -incremental-basedir based on the total amount specified directory prepared by
Second prepared by:
[root@linux ~]# mariabackup --backup --user=bakuser --password=bak123 --target-dir /data/mysqlbak/20191026_inc2 --incremental-basedir /data/mysqlbak/20191026_inc1
# - -target-dir is defined by a second backup file storage path, - -incremental-basedir specified backup directory for the first time by a second increase on prepared
restore:
Stop the service and empty datadir:
[root@linux ~]# service mysql stop
Redirecting to /bin/systemctl stop mysql.service
[root@linux ~]# rm -rf /data/mysql/*
Prepare full backup:
[root@linux ~]# mariabackup --prepare --target-dir /data/mysqlbak/20191026 --apply-only
Preparation for the first time prepared by:
[root@linux ~]# mariabackup --prepare --target-dir /data/mysqlbak/20191026 --incremental-dir /data/mysqlbak/20191026_inc1 --apply-only
Preparing a second prepared by:
[root@linux ~]# mariabackup --prepare --target-dir /data/mysqlbak/20191026 --incremental-dir /data/mysqlbak/20191026_inc2 --apply-only
Began to recover:
[root@linux ~]# mariabackup --copy-back --target-dir /data/mysqlbak/20191026
Change the owner and group to recover data files:
[root@linux ~]# chown -R mysql:mysql /data/mysql
# After mysql to start
Added:
the xtrabackup different things, Mariabackup every increase in equipment are based on the case of the last increase prepared, ready to resume operations when every backup increase can be directly based on primary and backup directory, need not be based on a catalog prepared by the