Download: xtrabackup
Https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/redhat/7/x86_64/Percona-XtraBackup-2.4.8-r97330f7-el7-x86_64-bundle.tar
Decompress and install yum
tar -xvf Percona-XtraBackup-2.4.8-r97330f7-el7-x86_64-bundle.taryum install percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm
Full backup
innobackupex –user=root –password=123456 –no-timestamp /backup/mysql/full
Add data in the database
Add a database db1, create table T1 in db1 (the engine of the table is InnoDB), and insert data
MariaDB [(none)]> create database if not exists db1;MariaDB [(none)]> use db1;MariaDB [db1]> create table t1(id int,name varchar(20))engine=innodb;MariaDB [db1]> insert into t1 values(1,‘aa‘);
First Incremental Backup
[[email protected] ~]# innobackupex --user=root --password=123456 --no-timestamp --incremental-basedir=/backup/mysql/full --incremental /backup/mysql/01
Add data in the database
mysql -uroot -p123456 -e "insert into db1.t1(id,name)values(2,‘100‘);"
Second Incremental Backup
[[email protected] ~]# innobackupex --user=root --password=123456 --no-timestamp --incremental-basedir=/backup/mysql/01 --incremental /backup/mysql/02
Simulate data loss and delete all contents in the database
cd /var/lib/mysql/rm -rf *
Restore full backup
[[email protected] mysql]# innobackupex --user=root --password=123456 --apply-log --redo-only /backup/mysql/full/
Restore the first Incremental Backup
[[email protected] mysql]# innobackupex --user=root --password=123456 --apply-log --redo-only /backup/mysql/full/ --incremental-dir=/backup/mysql/01
Restore the second Incremental Backup
[[email protected] mysql]# innobackupex --user=root --password=123456 --apply-log /backup/mysql/full/ --incremental-dir=/backup/mysql/02
Apply-Log
[[email protected] mysql]# innobackupex --user=root --password=123456 --copy-back /backup/mysql/full/
Set permissions
[[email protected] mysql]# chown -R mysql.mysql /var/lib/mysql/
Restart to check whether the recovery is successful
[[email protected] mysql]# systemctl restart mariadb[[email protected] mysql]# mysql -uroot -p123456 -e "select * from db1.t1;"+------+------+| id | name |+------+------+| 1 | aa || 2 | 100 |+------+------+
Innobackupex Incremental backup and recovery