使用 playground v7.2.0 启动集群,如何备份和恢复数据库,指点一下

【 TiDB 使用环境】开发环境
【 TiDB 版本】v7.2.0
就想问一下 ,tidb v.7.2.0,如何备份和恢复数据库,看文档,看得一头晕

如果是 playground 可以直接打包 ~/.tiup/data/ 文件夹

br或者dumpling+lighting

来,给你个最简单的案例。
用BACKUP DATABASE备份数据库,RESTORE database恢复数据库:以test库为例。


root@127.0.0.1:4000[(none)]>use test
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
root@127.0.0.1:4000[test]>show tables;
+----------------+
| Tables_in_test |
+----------------+
| my_table       |
+----------------+
1 row in set (0.00 sec)

root@127.0.0.1:4000[test]>select * from my_table;
+---------------------+---------+----------+
| id                  | name    | code     |
+---------------------+---------+----------+
|  576460752303423492 | 测试2   | website2 |
| 4611686018427387905 | 测试    | website  |
+---------------------+---------+----------+
2 rows in set (0.00 sec)

root@127.0.0.1:4000[test]>BACKUP DATABASE `test` TO '/tmp';
+-------------+------+--------------------+---------------------+---------------------+
| Destination | Size | BackupTS           | Queue Time          | Execution Time      |
+-------------+------+--------------------+---------------------+---------------------+
| /tmp        | 5492 | 442997127910785026 | 2023-07-21 08:38:52 | 2023-07-21 08:38:52 |
+-------------+------+--------------------+---------------------+---------------------+
1 row in set (0.20 sec)

root@127.0.0.1:4000[test]>show backups;
+------+-------------+----------+----------+---------------------+---------------------+---------------------+---------------------+---------+
| Id   | Destination | State    | Progress | Queue_time          | Execution_time      | Finish_time         | Connection          | Message |
+------+-------------+----------+----------+---------------------+---------------------+---------------------+---------------------+---------+
|    1 | /tmp        | Checksum |      100 | 2023-07-21 08:38:52 | 2023-07-21 08:38:52 | 2023-07-21 08:38:52 | 7843034144228507657 | NULL    |
+------+-------------+----------+----------+---------------------+---------------------+---------------------+---------------------+---------+
1 row in set (0.00 sec)

root@127.0.0.1:4000[test]>drop database test;
Query OK, 0 rows affected (0.33 sec)

root@127.0.0.1:4000[test]>RESTORE database `test` FROM '/tmp';
+-------------+------+--------------------+--------------------+---------------------+---------------------+
| Destination | Size | BackupTS           | Cluster TS         | Queue Time          | Execution Time      |
+-------------+------+--------------------+--------------------+---------------------+---------------------+
| /tmp        | 5492 | 442997127910785026 | 442997151373459460 | 2023-07-21 08:40:22 | 2023-07-21 08:40:22 |
+-------------+------+--------------------+--------------------+---------------------+---------------------+
1 row in set (0.87 sec)
Rows matched: 0  Changed: 0  Warnings: 0

root@127.0.0.1:4000[test]>show tables;
ERROR 1046 (3D000): No database selected
root@127.0.0.1:4000[test]>use test
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
root@127.0.0.1:4000[test]>show tables;
+----------------+
| Tables_in_test |
+----------------+
| my_table       |
+----------------+
1 row in set (0.00 sec)

root@127.0.0.1:4000[test]>select * from my_table;
+---------------------+---------+----------+
| id                  | name    | code     |
+---------------------+---------+----------+
|  576460752303423492 | 测试2   | website2 |
| 4611686018427387905 | 测试    | website  |
+---------------------+---------+----------+
2 rows in set (0.00 sec)

查dumpling用法

dumpling 得了,数据量小常用的备份工具都可以用的

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。