xtrabackup physical backup of MySQL database (a)

Introduction : When it comes to database backup, we know that can be used to make a backup of the database tools mysqldump, mydumer, mysqlpump and so on, practical work, the database on the machine is not the case, it is used mysqldump tool to backup, these backup tools advantages and disadvantages, not described in detail here, to share another database backup tools today, called XtraBackup.

A, Xtrabackup Introduction

1. official website explained

Percona XtraBackup MySQL backup can be achieved in the case does not prevent the user's query, making it ideal for companies with large data sets and can not afford downtime of mission-critical applications. As open source solutions to provide free, Percona XtraBackup reducing backup costs while providing unique features for MySQL backup.
 
2.Xtrabackup advantage
Complete backups quickly and reliably
Uninterrupted during backup transaction
Save disk space and network bandwidth
Automatic backup verification
Faster recovery time may be extended uptime
supports full non-blocking backup of InnoDB, XtraDB and HailDB storage engine
 
Backup process 3.Xtrabackup

 
(1) will open a background process detects when backup begins, real-time detection mysql redo (the committed transactions) changes, once there is a new redo log writing, immediately logging into the background log file xtrabackup_log found
(2) Copy InnoDB data files and file system table space ibdata1,
(3) the end to be copied is performed flush tables with read lock operation, copy .frm, .MYI, .MY other documents
(4) with the purpose of performing read lock flush tables in order to prevent the occurrence of the data table DML operation, and obtains binlog position at this time,
(5) will be issued last unlock tables, the table can be set to read-write status,
(6) The final stop xtrabackup_log.

4. Why XtraBackup

Because when a database of more than 100G, then there is no use mysqldump XtraBackup advantage, large work mysqldump backup data will appear stuck, the possibility of disconnection, XtraBackup support a full backup, incremental backup, full recovery, incremental recovery, when innodb engine for backup does not lock the table hot backup.

Two, XtraBackup installation

1.xtrabackup official website there are many versions, have 1.6,2.0-2.4 and 8.0, each version has a different, according to their need to download and install, such as:
xtrabackup1.6 version supports MySQL 5.0,5.1 and 5.5.
xtrabackup2.2 and 2.3 version supports backup MySQL 5.1, 5.5 and 5.6.
xtrabackup2.4 version supports MySQL 5.1,5.5,5.6 and 5.7.
xtrabackup8.0 version only supports MySQL8.0, does not support before 8.0.
This article uses xtrabackup2.3.


2. Download and install

Official website to download source packages, binary packages, as well as a repository, the official website to download the recommended repository, I am here atmospheres Centos7, so use yum to install, choose to install yum install -y percona-xtrabackup.x86_64 here

1  yum  install http: // www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm 
2  yum list | grep Percona
 3 Percona-xtrabackup.x86_64                  2.3 . 10 - 1 .el7 Percona-release- x86_64
 4 Percona-xtrabackup- 22 .x86_64               2.2 . 13 - 1 .el7 Percona-release- x86_64
 5 Percona-xtrabackup- 22 -debuginfo.x86_64     2.2 .13 - 1 .el7 Percona-release- x86_64
 6 Percona-xtrabackup- 24 .x86_64               2.4 . 18 - 1 .el7 Percona-release- x86_64
 7 Percona-xtrabackup- 24 -debuginfo.x86_64     2.4 . 18 - 1 .el7 Percona-release- x86_64
 8 Percona-xtrabackup- 80 .x86_64               8.0 . 9 - 1 .el7 Percona-release- x86_64
 9Percona-xtrabackup- 80 -debuginfo.x86_64     8.0 . 9 - 1 .el7 Percona-release- x86_64
 10 Percona-xtrabackup-debuginfo.x86_64        2.3 . 10 - 1 .el7 Percona-release- x86_64
 11 Percona-xtrabackup-test.x86_64             2.3 . 10 - 1 .el7 Percona-release- x86_64
 12 Percona-xtrabackup-test- 22 .x86_64          2.2 . 13 - 1.el7                 percona-release-x86_64
13 percona-xtrabackup-test-24.x86_64         2.4.18-1.el7                 percona-release-x86_64
14 percona-xtrabackup-test-80.x86_64         8.0.9-1.el7                  percona-release-x86_64

After installation, you can check xtrabackup version, my local database version 5.6

1 xtrabackup --version
2 xtrabackup version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )

3. Tools Introduction

After the installation is complete, there are four Xtrabackup executable file that two of the more important backup tool is innobackupex, xtrabackup

innobackupex
innobackupex xtrabackup is a package of Perl scripts. .
xtrabackup
compiled C binaries, provides for the use MyISAM, InnoDB and MySQL XtraDB table back up the entire database instance functions.
xbcrypt encryption
utility for encrypting and decrypting the backup file.
xbstream
allows the extraction of files from xbstream as a stream format, similar to tar.
xbcloud
for downloading xbstream or all or part of the archive upload it to the cloud from the cloud.

Official website Description: innobackupex still like version 2.2 supports all the same features and syntax, but now deprecated and will be removed in the next major release, the backup Percona XtraBackup 2.3 version of the recommended way to take is to use xtrabackup script, this article describes innobackupex script, not very different.

4.innobackupex command parameters

= --user              # specify the database backup user

= --password           # specify the database backup user password

= --port              # specify the database port

= --host              # specify a backup host

= --socket             # specified socket file path

--databases = # specify the database backup, multiple separated by spaces, such as = --databases " dbname1 dbname2 " , without the backup of all libraries

--defaults- File =          # specify the configuration file my.cnf

--apply- log log roll #

= --incremental             # incremental backup, incremental backup path followed

= basedir---incremental     # incremental backup, incremental backup path refers to the last

--redo- only # merge full backup and incremental backup data files

--copy- the Back # Copy the backup data to the database, the database directory to be empty

--no- timestamp # generate a backup file is not a directory name with a timestamp

--stream = # Specifies the format of the stream to do a backup, - = Stream tar , backup file archiving, - Stream = xbstream

= Host---remote the User @ # ip DST_DIR backup to a remote host
                      
Memory-= --use           # prepare the parameter used when, innodb instance used to control the amount of memory prepare
             
--parallel # number of threads used to copy data files. = With the -stream xbstream
                      
--compress # compression, = with the -stream xbstream
 
Threads =---compress . 4     # number of threads for parallel data compression. The default for this option is 1. = With the -stream xbstream
                      
--throttle = # innobackupex limit the rate of data reading and writing InnoDB

 

Third, a full backup with innobackupex
1. Perform a full backup command

innobackupex --defaults-file = / usr / local / mysql / my.cnf --user = root --password = "123456" --socket = / tmp / mysql.sock --no-timestamp / data / backup / $ (date +% F) / full
last successful backup output information indicates the following
xtrabackup:. LSN of the Transaction log (42,677,124,128) to (42,677,124,128) WAS copied appears
200127, China Completed 13:21:18 the OK!

In / data / backup directory generates a directory named the current date, full time directory below a directory storing a file back out

1 [root@devops 13:17:24/data/backup/]# ll 
2 total 2535576
3 drwx------ 3 root root       4096 Jan 27 13:17 2020-01-27

Introduce directory file information

. 1 [DevOps the root @ 13 is : 21 is : 18 is / Data / Backup /] LL # 2020 - 01 - 27 / Full /
 2 Total 141 364 
. 3 -rw-R & lt ----- . 1 the root the root        388 Jan 27  13 is : 21 is backup- my.cnf # backup command configuration information is used
 . 4 -rw-R & lt ----- . 1 the root the root 144 703 488 Jan 27  13 is : . 17 ibdata1 # tablespace backup files 
 . 5 drwx ------ 2 the root the root       4096Jan 27  13 is : 21 is MySQL # back out of mysql, performance_schema, test databases
 . 6 drwx ------ 2 the root the root       4096 Jan 27  13 is : 21 is performance_schema
 . 7 drwx ------ 2 the root the root       4096 Jan 27  13 is : 21 is Test
 . 8 -rw-R & lt ----- . 1 the root the root         21 is Jan 27  13 is : 21 is xtrabackup_binlog_info #binlog log
 . 9 -rw-R & lt ----- . 1the root the root        121 Jan 27  13 is : 21 is xtrabackup_checkpoints # this is important, which store LSN (Log Sequence Number)
 10 -rw-R & lt ----- . 1 the root the root        602 Jan 27  13 is : 21 is xtrabackup_info # version stored tools, databases version, use the start and end time and other information
 11 -rw-r ----- 1 root root       2560 Jan 27  13 : 21 xtrabackup_logfile # redo log files

2. Analog delete the entire data directory

cd /data/ && rm -rf mysqldata

3.kill off mysql process

pgrep mysql | xargs kill

4. Prepare

Preparation (prepare) a full backup
Under normal circumstances, after the backup is complete, the data is still unable to resume operations because 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 processed in an inconsistent state. The main role of "ready" it is through transaction rollback uncommitted transaction synchronization and data files that have been submitted to also make the data files in a consistent state.
-apply-log option innobackupex command can be used to achieve these functions
do not recommend interrupting xtrabackup process in preparation for, as this may result in corrupted data files and the backup will become unavailable. If the preparation process is interrupted, it can not guarantee the validity of backups.

innobackupex --apply /data/backup/2020-01-27/full/

  Final output: 200127 13:44:47 completed OK!

5. Check xtrabackup_checkpoints file    

checkpoints which type of view after the merger becomes a full-prepared shall be recoverable.

backup_type = full-prepared

6. Before performing a restore to the specified data directory in my.cnf

Before you restore a backup, datadir must be empty. Pay attention to the need to shut down before the restore MySQL server. Mysqld directory data can not be restored to the running instance (except when the lead-in portion backup)

1 cat /usr/local/mysql/my.cnf  | grep datadir
2 datadir         = /data/mysqldata

7. Perform recovery command

innobackupex --defaults-file=/usr/local/mysql/my.cnf --copy-back /data/backup/2020-01-27/full
200127 13:56:37 completed OK!      

If you restore the last output OK, no problem

8. Modify permissions

Since the property reserved file, so in most cases, before starting the mysql database server, you need to change the ownership of files to mysql

chown -R mysql.mysql /data/mysqldata

9. Start

service mysqld start

10. The inspection data


Summary : This article describes xtrabackup full backup and restore, will continue to write back, if there poorly written, please exhibitions, thank you

Guess you like

Origin www.cnblogs.com/summer-time/p/12237232.html