xtrabackup8.0怎么恢复单表【转】
实验场景
GreatSQL 8.0.25 InnoDB
1.备份,导出单表, test.t_user
/usr/bin/xtrabackup -uroot -p'GreatSQL' -S /data/GreatSQL/mysql.sock --tables='test.t_user' --backup --target-dir=/data/backup
2.恢复备份
xtrabackup --prepare --export --target-dir=/data/backup
3.建测试表
[root@GreatSQL][test02]>CREATE TABLE `t_user` (
-> `id` bigint NOT NULL AUTO_INCREMENT,
-> `name` varchar(255) DEFAULT NULL,
-> `age` tinyint DEFAULT NULL,
-> `create_time` datetime DEFAULT NULL,
-> `update_time` datetime DEFAULT NULL,
-> PRIMARY KEY (`id`),
-> KEY `idx_name` (`name`),
-> KEY `idx_age` (`age`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=1091002 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Query OK, 0 rows affected (0.16 sec)
4.卸载新表表空间
[root@GreatSQL][test02]>ALTER table t_user discard tablespace;
Query OK, 0 rows affected (0.11 sec)
5.拷贝备份的t_user文件
[root@localhost test]# cd /data/backup/test/
[root@localhost test2]# cp * /data/GreatSQL/test02/
[root@localhost test2]# ll
-rw-r--r-- 1 root root 964 Nov 24 04:12 t_user.cfg
-rw-r----- 1 root root 18874368 Nov 24 04:10 t_user.ibd
6.挂载新表表空间
[root@GreatSQL][test02]>ALTER TABLE t_user import tablespace;
Query OK, 0 rows affected, 1 warning (0.47 sec)
7.查询恢复数据
[root@GreatSQL][test02]>select count(*) from test02.t_user;
+----------+
| count(*) |
+----------+
| 91002 |
+----------+
1 row in set (0.10 sec)# 旧表的数据
[root@GreatSQL][test02]>select count(*) from test.t_user;
+----------+
| count(*) |
+----------+
| 91002 |
+----------+
1 row in set (0.07 sec)
(Wed Nov 24 21:35:57 2021)[root@GreatSQL][test02]>
转自
万答#14,xtrabackup8.0怎么恢复单表
https://mp.weixin.qq.com/s/1WGltn9A3qFfrmi6Q8NVBA