MySQL - Xtrabackup installation process and the problems encountered

Xtarbackup About
Xtrabackup by percona free open-source database hot backup software, it can be non-blocking backups (backup for MyISAM tables also need to add a lock) to database InnoDB database storage engine and XtraDB; mysqldump backup is a logical backup adopted, its biggest drawback is slower backup and restore, if the database is larger than 50G, mysqldump backup is not suitable.
Xtrabackup advantage

1) the backup speed, reliable physical backup
2) does not interrupt the backup process transaction (no lock table) is performed
3) can be based compression capabilities save disk space and flow
4) Automatic Backup Verification
5) reducing the speed
6 ) can be spread on the backup transmission to another machine
7) in the backup data without increasing the load on the server

Xtrabackup backup principle
will first open a background process detects when backup begins, changes in real-time detection mysql redo, once found a new log is written immediately logging into the background log file xtrabackup_log, the innodb data files after copying a system table space file ibdatax, after the end of the copy will be executed flush tables with readlock, and then copy the .frm MYI MYD and other documents, the final implementation unlock tables, the final stop xtrabackup_log.
Xtrabackup incremental backup Introduction

Xtrabackup incremental backup principle is:

1), first to complete a full backup, and at this time the checkpoint record LSN;
2), then the incremental backup, each LSN comparison table space is larger than the page LSN of the last backup, and if the backup page record LSN current checkpoint.

Incremental backup advantages:

1), the database is too large there is not enough space full backup, incremental backup can save space, and high efficiency;
2), supports hot backup, the backup process does not lock table (for InnoDB terms), to read and write the database does not block ;
3), the daily backup only a small amount of data, may also be remote backup, local space-saving;
4), based on the file backup and recovery operations, reducing the risk of direct operation of the database;
5), more efficient backup, restore more efficient .

Install
the operating environment is centos 7.2
download XtraBackup:
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.9/binary/redhat/7/x86_64/Percona-XtraBackup-2.4.9-ra467167cdd4- el7-x86_64-bundle.tar

(Percona-XtraBackup-8.0下载:
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-8.0.4/binary/redhat/7/x86_64/percona-xtrabackup-80-8.0.4-1.el7.x86_64.rpm
依赖:yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr bison libtool ncurses5-devel perl perl-devel perl-Digest-MD5 perl-Time-HiRes perl-DBD-MySQL libev libev-devel libgcrypt libgcrypt-devel curl curl-devel python-setuptools libarchive-devel)

Decompression: tar -xf Percona-XtraBackup-2.4.9 -ra467167cdd4-el7-x86_64-bundle.tar
check the installation percona-xtrabackup-24-2.4.9-1.el6.x86_64.rpm required dependencies:
yum the install -Y percona-xtrabackup-24-2.4.9-1.el6.x86_64.rpm --skip-broken
installation according Tip:
yum -Y * MariaDB perl- the install-libs
there is a need to manually download and install dependencies
wget HTTP: / /mirror.centos.org/centos/7/extras/x86_64/Packages/libev-4.15-7.el7.x86_64.rpm
installation dependencies several attempts to install xtrabackup-Percona
yum the install Percona -Y-xtrabackup-24- 2.4.9-1.el6.x86_64.rpm
my display properly installed, there is no error.

[root@localhost src]# which xtrabackup
/usr/bin/xtrabackup
[root@localhost src]# innobackupex -v
innobackupex version 2.4.9 Linux (x86_64) (revision id: a467167cdd4)
[root@localhost src]#
MySQL - Xtrabackup installation process and the problems encountered

mysql create database and table
mysql> the Create Database Home;
Query the OK, 1 Row affected (0.00 sec)

mysql> show databases;
mysql> create table address (name varchar(10) not null,homeaddress varchar(20) not null);
Query OK, 0 rows affected (0.08 sec)
mysql> use home ;
Database changed
mysql> insert into address values('zhuangsan','guangzhou');
Query OK, 1 row affected (0.02 sec)

mysql> insert into address values('lisi','shanghai');
Query OK, 1 row affected (0.01 sec)

mysql> insert into address values('waner','shenzhen');
Query OK, 1 row affected (0.03 sec)
全量备份:
[root@localhost run]# innobackupex --defaults-file=/etc/my.cnf --user=root --password="123abc" --backup /data/mysqldata

--user: mysql user account
--password: password for the account
/ data / mysqldata: Data backup directory
MySQL - Xtrabackup installation process and the problems encountered
[root @ localhost run] # ls / data / mysqldata / 2018-03-09_17-25-31 / # in this You can see the backup directory information, can also see the name of the library we created.
MySQL - Xtrabackup installation process and the problems encountered
[root @ localhost ~] # innobackupex --apply-log / data / mysqldata / 2018-03-09_17-25-31 / # This parameter enables the use of the relevant data file consistent state.
MySQL - Xtrabackup installation process and the problems encountered
MySQL - Xtrabackup installation process and the problems encountered

恢复:
删除表信息:
mysql> show databases
-> ;
+------------------------------+
| Database |
+------------------------------+
| information_schema |
| #mysql50#2018-03-09_17-25-31 |
| home |
| mysql |
| performance_schema |
| sys |
+------------------------------+
6 rows in set (0.09 sec)

mysql> use home;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_home |
+----------------+
| address |
+----------------+
1 row in set (0.00 sec)

mysql> drop table address;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from address
->;

ERROR 1146 (42S02): Table 'home.address' doesn't exist
mysql>
MySQL - Xtrabackup installation process and the problems encountered
恢复之前必须保证数据目录为空,即mysqldata目录。由于之前的备份数据在mysqldata目录中,所以需要将里面的数据copy出来,确保mysqldata目录是空的。才能正常恢复数据。要不然会报mysqldata目录非空错误。
[root@localhost mysqldata]# innobackupex --defaults-file=/etc/my.cnf --copy-back /data/mysqldata.bak/2018-03-09_17-25-31/
MySQL - Xtrabackup installation process and the problems encountered
MySQL - Xtrabackup installation process and the problems encountered
所遇问题处理 注:
恢复数据后,启动mysql出现报错,无法启动。
[root@localhost mysqldata]# service mysqld start
Starting MySQL.. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
MySQL - Xtrabackup installation process and the problems encountered
检查过/var/run/mysqld目录没问题,进入恢复数据文件目录和之前的数据进行对比,发现所以数据的所有者不是mysql而是root
MySQL - Xtrabackup installation process and the problems encountered
MySQL - Xtrabackup installation process and the problems encountered
修改恢复目录的数据权限
[root@localhost data]# chown -R mysql:mysql mysqldata
重新启动mysql,正常启动
MySQL - Xtrabackup installation process and the problems encountered
查看数据是否恢复。
MySQL - Xtrabackup installation process and the problems encountered
数据恢复正常。
增量备份与恢复:
新插入一些数据,创建用于增量备份的数据,用来模拟删除掉了全备后的数据,能否通过增量备份文件来恢复。
mysql> select * from address;
+-----------+-------------+
| name | homeaddress |
+-----------+-------------+
| zhuangsan | guangzhou |
| lisi | shanghai |
| waner | shenzhen |
| jinjin | jiangxi |
| xiaoxiong | xi`an |
| meimei | fujian |
+-----------+-------------+
6 rows in set (0.00 sec)

mysql>

MySQL - Xtrabackup installation process and the problems encountered

增量备份:
[root@localhost mysqldata.bak]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=123abc --incremental /data/mysqldata --incremental-basedir=/data/mysqldata.bak/2018-03-09_17-25-31
--incremental /data/mysqldata 指定增量备份文件存放目录
--incremental-basedir=/data/mysqldata.bak/2018-03-09_17-25-31 指定上一次全量备份或增量备份的存放目录
MySQL - Xtrabackup installation process and the problems encountered
显示以下内容说明成功:
180323 14:54:20 Executing UNLOCK TABLES
180323 14:54:20 All tables unlocked
180323 14:54:20 [00] Copying ib_buffer_pool to /data/mysqldata/2018-03-23_14-54-12/ib_buffer_pool
180323 14:54:20 [00] ...done
180323 14:54:20 Backup created in directory '/data/mysqldata/2018-03-23_14-54-12/'
180323 14:54:20 [00] Writing /data/mysqldata/2018-03-23_14-54-12/backup-my.cnf
180323 14:54:20 [00] ...done
180323 14:54:20 [00] Writing /data/mysqldata/2018-03-23_14-54-12/xtrabackup_info
180323 14:54:20 [00] ...done
xtrabackup: Transaction log of lsn (2564189) to (2564198) was copied.
180323 14:54:20 completed OK!
[root@localhost mysqldata.bak]#

Viewing backup situation
MySQL - Xtrabackup installation process and the problems encountered
to remove an entry test incremental restore
MySQL - Xtrabackup installation process and the problems encountered
before restoring the database remember to turn off the data service.
MySQL - Xtrabackup installation process and the problems encountered
MySQL - Xtrabackup installation process and the problems encountered
MySQL - Xtrabackup installation process and the problems encountered

Guess you like

Origin blog.51cto.com/3001441/2453754