1. 完全恢复
MySQL 中,物理备份的完全恢复相对比较简单,下面来看个案例:
恢复数据一致性, 通过回滚未提交的事务及同步已经提交的事务至数据文件,使用得数据文件处于一致性状态。 innobackupex 通常还可以使用 --user-memory 选项来指定其可以使用的内存的大小,如果有足够的内存空间可用,可以多划分一些内存给 prepare 的过程,以提高其完成备份的速度。
[root@localhost ~]200824 06:29:44 innobackupex: Starting the apply-log operation
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".innobackupex version 2.4.9 based on MySQL server 5.7.13 Linux (x86_64) (revision id: a467167cdd4)xtrabackup: cd to /mysql/dbbackup/xtrabackup: This target seems to be not prepared yet.InnoDB: Number of pools: 1xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(14533834254)......InnoDB: 5.7.13 started; log sequence number 14533834773xtrabackup: starting shutdown with innodb_fast_shutdown = 1InnoDB: FTS optimize thread exiting.InnoDB: Starting shutdown...InnoDB: Shutdown completed; log sequence number 14533834792200824 06:30:35 completed OK!
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
[root@localhost ~]Shutting down MySQL.... SUCCESS![root@localhost ~][root@localhost ~][root@localhost ~]200824 06:44:20 innobackupex: Starting the copy-back operation
IMPORTANT: Please check that the copy-back run completes successfully.
At the end of a successful copy-back run innobackupex
prints "completed OK!".innobackupex version 2.4.9 based on MySQL server 5.7.13 Linux (x86_64) (revision id: a467167cdd4)200824 06:44:20 [01] Copying ib_logfile0 to /mysql/data/ib_logfile0200824 06:44:28 [01] ...done......200824 06:44:59 [01] Creating directory /mysql/data/2020-09-01_06-42-14200824 06:44:59 [01] ...done.200901 06:44:59 completed OK![root@localhost ~][root@localhost ~]Starting MySQL.. SUCCESS!
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
mysql> use tempdbDatabase changed
mysql> select * from customer;+| id | last_name | first_name | birth_date | gender | balance |+| 1 | 111 | 111 | NULL | 1 | 10 || 2 | 222 | 222 | 2020-07-15 | 1 | 20 |+2 rows in set (0.01 sec)
2. 不完全恢复
逻辑恢复中,mysqlbinlog 的不完全恢复方法,同样适用于物理备份的不完全恢复。
1.13 点,运维人员误删除表 customer,可以用备份和 binlog 日志恢复到故障前(中午12点,物理备份数据库)
从备份文件目录找到 binlog 位置文件 xtrabackup_binlog_info,查看备份结束时 binlog 的位置:
[root@localhost ~][root@localhost ~]-rw-r-rw-r-rw-r-rw-r-rw-r-rw-r-rw-rdrwxr-xdrwxr-xdrwxr-xdrwxr-x-rw-r-rw-r-rw-r-rw-r-rw-r[root@localhost ~]mysql-bin.000022 190
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
mysql> show master logs;+| Log_name | File_size |+| mysql-bin.000018 | 245704317 || mysql-bin.000019 | 1078 || mysql-bin.000020 | 781 || mysql-bin.000021 | 483 || mysql-bin.000022 | 757 || mysql-bin.000023 | 190 |+6 rows in set (0.00 sec)
恢复备份文件(参考完全备份步骤),然后使用 binlog 日志跳过故障时间点,完成恢复
完全恢复[mysql@localhost ~]$ mysqlbinlog Enter password:[mysql@localhost ~]$ mysqlbinlog Enter password:
3. 小结
本小节通过 xtrabackup 工具,介绍了物理恢复的两种恢复方式:完全恢复、不完全恢复。
- 物理备份的完全恢复相对简单,恢复最新的全备文件
- 不完全恢复相对要复杂,分为基于时间点的恢复和基于位置的恢复,通常适用于人为误操作的恢复场景