好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

MySQL 8 物理全量恢复

MySQL 8 物理全量恢复

祖仙教小凡仙 海鲨数据库架构师

Percona XtraBackup的工作原理:

1.XtraBackup复制InnoDB数据文件,这会导致内部不一致的数据,但是它会对文件执行崩溃恢复,以使其再次成为一个一致的可用数据库

2.这样做的可行性是因为InnoDB维护一个REDO日志,也称为事务日志。REDO日志包含了InnoDB数据每次更改的记录。当InnoDB启动时,REDO日志会检查数据文件和事务日志,并执行两个步骤。它将已提交的事务日志条目应用于数据文件,并对任何修改了数据但未提交的事务执行undo操作

3.Percona XtraBackup会在启动时记住日志序列号(LSN),然后复制数据文件。这需要一些时间来完成,如果文件正在改变,那么它会在不同的时间点反映数据库的状态。同时,Percona XtraBackup运行一个后台进程,用于监视事务日志文件,并从中复制更改。Percona XtraBackup需要持续这样做,因为事务日志是以循环方式写入的,并且可以在一段时间后重新使用。Percona XtraBackup开始执行后,需要复制每次数据文件更改对应的事务日志记录

这里我们看到普通全量备份 UNDO大小为10MB

 
[root@localhost backup]# ll -h
总用量 57M
-rw-r----- 1 root root  475 1月  27 23:12 backup-my.cnf
-rw-r----- 1 root root  156 1月  27 23:12 binlog.000027
-rw-r----- 1 root root   16 1月  27 23:12 binlog.index
drwxr-x--- 2 root root 4.0K 1月  27 23:12 bookstore
drwxr-x--- 6 root root 4.0K 1月  28 23:51 Full_mysql8020_2021-01-28-23-51-49
-rw-r----- 1 root root 3.5K 1月  27 23:12 ib_buffer_pool
-rw-r----- 1 root root  12M 1月  27 23:12 ibdata1
drwxr-x--- 2 root root 4.0K 1月  27 23:12 mysql
-rw-r----- 1 root root  24M 1月  27 23:12 mysql.ibd
drwxr-x--- 2 root root 4.0K 1月  27 23:12 performance_schema
drwxr-x--- 2 root root 4.0K 1月  27 23:12 sys
-rw-r----- 1 root root  10M 1月  27 23:12 undo_001
-rw-r----- 1 root root  10M 1月  27 23:12 undo_002
-rw-r----- 1 root root   18 1月  27 23:12 xtrabackup_binlog_info
-rw-r----- 1 root root   95 1月  27 23:12 xtrabackup_checkpoints
-rw-r----- 1 root root  547 1月  27 23:12 xtrabackup_info
-rw-r----- 1 root root 2.5K 1月  27 23:12 xtrabackup_logfile
-rw-r----- 1 root root   39 1月  27 23:12 xtrabackup_tablespaces 

全量压缩备份

 
[root@localhost Full_mysql8020_2021-01-28-23-51-49]# ll -h
总用量 2.8M
-rw-r----- 1 root root  459 1月  28 23:51 backup-my.cnf.qp
-rw-r----- 1 root root  190 1月  28 23:51 binlog.000032.qp
-rw-r----- 1 root root   93 1月  28 23:51 binlog.index.qp
drwxr-x--- 2 root root 4.0K 1月  28 23:51 bookstore
-rw-r----- 1 root root  988 1月  28 23:51 ib_buffer_pool.qp
-rw-r----- 1 root root 164K 1月  28 23:51 ibdata1.qp
drwxr-x--- 2 root root 4.0K 1月  28 23:51 mysql
-rw-r----- 1 root root 2.1M 1月  28 23:51 mysql.ibd.qp
drwxr-x--- 2 root root 4.0K 1月  28 23:51 performance_schema
drwxr-x--- 2 root root 4.0K 1月  28 23:51 sys
-rw-r----- 1 root root 219K 1月  28 23:51 undo_001.qp
-rw-r----- 1 root root 207K 1月  28 23:51 undo_002.qp
-rw-r----- 1 root root  105 1月  28 23:51 xtrabackup_binlog_info.qp
-rw-r----- 1 root root   95 1月  28 23:51 xtrabackup_checkpoints
-rw-r----- 1 root root  540 1月  28 23:51 xtrabackup_info.qp
-rw-r----- 1 root root  509 1月  28 23:51 xtrabackup_logfile.qp
-rw-r----- 1 root root  130 1月  28 23:51 xtrabackup_tablespaces.qp 

UNDO大小才219K

比较具体表大小

 
[root@localhost bookstore]# ll -h
总用量 288K
-rw-r----- 1 root root 128K 1月  27 23:12 books2.ibd
-rw-r----- 1 root root 160K 1月  27 23:12 books.ibd
[root@localhost bookstore]# cd ..
[root@localhost backup]# cd Full_mysql8020_2021-01-28-23-51-49/bookstore/
[root@localhost bookstore]# ll -h
总用量 24K
-rw-r----- 1 root root 5.6K 1月  28 23:51 books2.ibd.qp
-rw-r----- 1 root root 4.0K 1月  28 23:51 books3.ibd.qp
-rw-r----- 1 root root 4.0K 1月  28 23:51 books4.ibd.qp
-rw-r----- 1 root root 6.9K 1月  28 23:51 books.ibd.qp 

books.ibd 160K 压缩后的books.ibd.qp 6.9K

全量恢复 启动数据库 并给BOOKS表插入一条记录

 
[root@localhost mysql8020debug]# ./log_mysqlc_by_root.sh 
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20-debug Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| bookstore          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.11 sec)

mysql> use bookstore
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_bookstore |
+---------------------+
| books               |
| books2              |
| books3              |
| books4              |
+---------------------+
4 rows in set (0.01 sec)

mysql> select * from books;
+----+------------------------+-------+---------------------+
| id | title                  | price | publishDate         |
+----+------------------------+-------+---------------------+
|  1 | Java编程思想           | 98.50 | 2005-01-02 0 |
|  2 | HeadFirst设计模式      | 55.70 | 2010-11-09 0 |
|  3 | 第一行Android代码      | 69.90 | 2015-06-23 0 |
|  4 | C++编程思想            | 88.50 | 2004-01-09 0 |
|  5 | HeadFirst Java         | 55.70 | 2013-12-17 0 |
|  6 | 疯狂Android            | 19.50 | 2014-07-31 0 |
+----+------------------------+-------+---------------------+
6 rows in set (0.02 sec)

mysql> insert into books(title,price,publishDate) values('数据库架构师修炼', 

查看更多关于MySQL 8 物理全量恢复的详细内容...

  阅读:38次