xtrabackup备份原理解析

对于数据量大的数据库来说,xtrabackup是作为mysql最好的热备份工具。

xtrabackup内容解析:

首先做一次全量备份:

xtrabackup -uroot -p123456 --backup -S /usr/local/mysql/mysql.sock 

第一部分(对于innodb表的备份):

190422 16:14:28  version_check Connected to MySQL server
190422 16:14:28  version_check Executing a version check against the server...
190422 16:14:28  version_check Done.
190422 16:14:28 Connecting to MySQL server host: localhost, user: root, password: set, port: not set, socket: /usr/local/mysql/mysql.sock
Using server version 5.7.23-log
xtrabackup version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/mysql/data
xtrabackup: open files limit requested 65535, set to 65535
xtrabackup: using the following InnoDB configuration:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:12M;ibdata2:1G:autoextend
xtrabackup:   innodb_log_group_home_dir = ./
xtrabackup:   innodb_log_files_in_group = 3
xtrabackup:   innodb_log_file_size = 1073741824
xtrabackup: using O_DIRECT
InnoDB: Number of pools: 1
190422 16:14:29 >> log scanned up to (23226687)
xtrabackup: Generating a list of tablespaces
InnoDB: Allocated tablespace ID 2 for mysql/plugin, old maximum was 0
190422 16:14:29 [01] Copying ./ibdata1 to /root/xtrabackup_backupfiles/ibdata1
190422 16:14:29 [01]        ...done
190422 16:14:29 [01] Copying ./ibdata2 to /root/xtrabackup_backupfiles/ibdata2
190422 16:14:30 >> log scanned up to (23226687)
190422 16:14:31 >> log scanned up to (23226687)
190422 16:14:32 >> log scanned up to (23226687)
190422 16:14:33 >> log scanned up to (23226687)
190422 16:14:33 [01]        ...done
190422 16:14:33 [01] Copying ./mysql/plugin.ibd to /root/xtrabackup_backupfiles/mysql/plugin.ibd
 

1)log scanned up to (23226687)之前都是一些输出的常用信息。

2)Copying。。

开始拷贝ibdata1和ibdata2文件

3)log scanned up to

扫描最新的redolog的LSN号

4)Copying 。。

拷贝innodb的数据文件

 

第二部分(对于非innodb表):

190422 16:14:34 >> log scanned up to (23226687)
190422 16:14:34 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
190422 16:14:34 Executing FLUSH TABLES WITH READ LOCK...
190422 16:14:34 Starting to backup non-InnoDB tables and files
190422 16:14:34 [01] Copying ./mysql/db.opt to /root/xtrabackup_backupfiles/mysql/db.opt
190422 16:14:34 [01]        ...done
1)log scanned up to (23226687)

后台的redolog扫描线程一直在扫描最新的日志,持续写入

2)Executing FLUSH TABLES WITH READ LOCK...

执行全局读锁,防止写入

3)Starting to backup non-InnoDB tables and files

开始对非innodb表和文件开始拷贝

4)Copying .

拷贝开始

 

第三部分:

190422 16:14:34 [00]        ...done
190422 16:14:34 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '23226678'
xtrabackup: Stopping log copying thread.
.190422 16:14:34 >> log scanned up to (23226687)

190422 16:14:34 Executing UNLOCK TABLES
190422 16:14:34 All tables unlocked
190422 16:14:34 [00] Copying ON to /root/xtrabackup_backupfiles/ON
190422 16:14:34 [00]        ...done
190422 16:14:34 Backup created in directory '/root/xtrabackup_backupfiles/'
MySQL binlog position: filename 'mysql-bin.000002', position '1874', GTID of the last change '5e8ed74d-61c4-11e9-8417-000c290bcf2a:1-221,
73218b73-61ca-11e9-8462-000c2993db47:1-13882'
190422 16:14:34 [00] Writing /root/xtrabackup_backupfiles/backup-my.cnf
190422 16:14:34 [00]        ...done
190422 16:14:34 [00] Writing /root/xtrabackup_backupfiles/xtrabackup_info
190422 16:14:34 [00]        ...done
xtrabackup: Transaction log of lsn (23226678) to (23226687) was copied.
190422 16:14:35 completed OK!
1)    ...done

拷贝完成

2)Stopping log copying thread.

停止后台redo线程

3)Executing UNLOCK TABLES

释放锁

 

xtrabackup备份原理解析_第1张图片

 

1、xtrabackup在启动后,会有两个线程,一个是redolog扫描线程,一个是innodb文件的ibd文件拷贝线程。redo日志线程总是在拷贝线程之前启动,早拷贝线程结束后结束。

2、ibd文件拷贝完成后通知主进程,告知拷贝完毕。

3、启动非innodb引擎的拷贝线程,加全局读锁。

4、非innodb引擎的文件拷贝完毕后,停止拷贝线程,然后停止redo线程,在停止redo线程之前,redo线程一直在拷贝,到最新的日志。

5、redo线程结束后,执行解锁表操作,进行收尾工作,备份结束。


 

你可能感兴趣的:(Linux,mysql,xtrabackup)