TDengine 入门教程⑩——容灾和数据备份机制(基于taosdump 的数据导入和导出)

文章目录

  • 一、前文
  • 二、安装
  • 三、数据导出
  • 四、数据导入
  • 五、参考

一、前文

TDengine 入门教程——导读

taosdump 是一个支持从运行中的 TDengine 集群备份数据并将备份的数据恢复到相同或另一个运行中的 TDengine 集群中的工具应用程序。

二、安装

  • 下载taosTools-2.2.1-Linux-x64.rpm安装包到服务器上
  • 再rpm安装

rpm -ivh taosTools-2.1.2-Linux-x64.rpm

[root@iZ2ze30dygwd6yh7gu6lskZ ~]# rpm -ivh taosTools-2.1.2-Linux-x64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
	package taostools-2.1.2-3.x86_64 is already installed

三、数据导出

  • 查看当前数据库的数据
[root@iZ2ze30dygwd6yh7gu6lskZ ~]# taos -p
Enter password: Welcome to the TDengine Command Line Interface, Client Version:3.0.0.1
Copyright (c) 2022 by TDengine, all rights reserved.

Server is Community Edition.

taos> SELECT * from test.weather;
           ts            |     temperature      |            location            |
==================================================================================
 2022-09-19 23:38:25.541 |             18.20000 | 北京                           |
 2022-09-19 23:39:02.053 |             18.20000 | 北京                           |
 2022-09-19 23:40:18.976 |             17.20000 | 北京                           |
 2022-09-19 23:40:22.410 |             16.20000 | 北京                           |
 2022-09-19 23:40:26.759 |             15.20000 | 北京                           |
Query OK, 5 rows in database (0.004588s)

  • 导出数据

taosdump -u root -p -A

[root@iZ2ze30dygwd6yh7gu6lskZ taos]# taosdump -u root -p -A
Enter password: ==============================
========== arguments config =========
taosdump version 2.1.2
host: (null)
user: root
port: 0
outpath: 
inpath: 
resultFile: ./dump_result.txt
all_databases: true
databases: false
databasesSeq: (null)
schemaonly: false
with_property: true
answer_yes: false
avro codec: snappy
data_batch: 16383
thread_num: 8
allow_sys: false
escape_char: true
loose_mode: false
isDumpIn: false
arg_list_len: 0
OK: Database: test exists
Start to dump out database: test
Start to dump out super table: test2 of test
Zero normal table need be dumped
Start to dump out super table: weather of test
connection: 0x561467e27e10 is dumping out schema: 1 sub table(s) of weather from offset 0
connection 0x561467e27e10 is dumping out schema:100% of weather
OK: total 1 sub table(s) of stable: weather dumped
[0]: Dumping 1%
[1]: Dumping 1%
WARN: SELECT COUNT(*) FROM test.`test1` WHERE _c0 >= -9223372036854775806 AND _c0 <= 9223372036854775807 fetch row, count: 0
[1]:100%
.100% of t1
[0]:100%
OK: Database test dumped
OK: 5 row(s) dumped out!

TDengine 入门教程⑩——容灾和数据备份机制(基于taosdump 的数据导入和导出)_第1张图片

四、数据导入

  • 数据导入之前,先删除数据库
[root@iZ2ze30dygwd6yh7gu6lskZ taos]# taos -p
Enter password: Welcome to the TDengine Command Line Interface, Client Version:3.0.0.1
Copyright (c) 2022 by TDengine, all rights reserved.

Server is Community Edition.

taos> drop database test;
Query OK, 0 of 0 rows affected (0.019727s)

taos> show databases;
              name              |
=================================
 information_schema             |
 performance_schema             |
Query OK, 2 rows in database (0.001128s)

taos> exit
  • 导入数据

taosdump -u root -p -i .

[root@iZ2ze30dygwd6yh7gu6lskZ taos]# taosdump -u root -p -i .
Enter password: ==============================
========== arguments config =========
taosdump version 2.1.2
host: (null)
user: root
port: 0
outpath: 
inpath: .
resultFile: ./dump_result.txt
all_databases: false
databases: false
databasesSeq: (null)
schemaonly: false
with_property: true
answer_yes: false
avro codec: snappy
data_batch: 16383
thread_num: 8
allow_sys: false
escape_char: true
loose_mode: false
isDumpIn: true
arg_list_len: 0
[1]: Restoring from test.3327204574891.2.avro-tbtags ...
[0]: Restoring from test.3327204574885.1.avro-tbtags ...
OK: [0] 0table(s) belong stb from the file(test.3327204574885.1.avro-tbtags) be successfully dumped in!
[0]:100%
OK: [1] 1table(s) belong stb from the file(test.3327204574891.2.avro-tbtags) be successfully dumped in!
[1]:100%
[0]: Restoring from test.3327204574902.avro-ntb ...
OK: [0] 1normal table(s) from (test.3327204574902.avro-ntb) be successfully dumped in!
[0]:100%
[0]: Restoring from test.3327204574906.0.avro ...
.OK: [0] 5 row(s) of file(test.3327204574906.0.avro) be successfully dumped in!
[0]:100%
OK: 5 row(s) dumped in!

  • 再次查看数据库中的数据是否和导出前一致。
[root@iZ2ze30dygwd6yh7gu6lskZ taos]# taos -p
Enter password: Welcome to the TDengine Command Line Interface, Client Version:3.0.0.1
Copyright (c) 2022 by TDengine, all rights reserved.

Server is Community Edition.

taos> show databases;
              name              |
=================================
 information_schema             |
 performance_schema             |
 test                           |
Query OK, 3 rows in database (0.003155s)

taos> SELECT * from test.weather;
           ts            |     temperature      |            location            |
==================================================================================
 2022-09-19 23:38:25.541 |             18.20000 | 北京                           |
 2022-09-19 23:39:02.053 |             18.20000 | 北京                           |
 2022-09-19 23:40:18.976 |             17.20000 | 北京                           |
 2022-09-19 23:40:22.410 |             16.20000 | 北京                           |
 2022-09-19 23:40:26.759 |             15.20000 | 北京                           |
Query OK, 5 rows in database (0.005086s)


五、参考

taosdump | TDengine 文档 | 涛思数据

觉得好,就一键三连呗(点赞+收藏+关注)

你可能感兴趣的:(TDengine,入门教程,tdengine,数据库,备份,taosdump,数据导入)