赞
踩
如果是使用开源版本IoTDB,那么有如下三种数据同步和备份的方法,可供选择。
如果是使用企业版本IoTDB(TimechoDB),那么一种数据同步的方法就够了,简单方便更好用。
IoTDB支持CSV文件导入导出,这一工具极大地简化了数据库备份、迁移以及同步的流程,为用户带来了极大的便利。
- 数据库备份与迁移是数据库运维中的核心任务,其重要性不言而喻。
- 确保备份过程既简单快捷又稳定可靠,对于保障数据安全与业务连续性至关重要。
- 注意:IoTDB V1.3.2及之后版本使用tools/export-data、tools/import-data
- 注意:IoTDB V1.3.1及之前版本使用tools/export-csv、tools/import-csv
[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.1-all-bin]# bash sbin/start-cli.sh
---------------------
Starting IoTDB Cli
---------------------
_____ _________ ______ ______
|_ _| | _ _ ||_ _ `.|_ _ \
| | .--.|_/ | | \_| | | `. \ | |_) |
| | / .'`\ \ | | | | | | | __'.
_| |_| \__. | _| |_ _| |_.' /_| |__) |
|_____|'.__.' |_____| |______.'|_______/ version 1.3.1 (Build: 214695d)
Successfully login at 127.0.0.1:6667
IoTDB> CREATE DATABASE root.test.test
Msg: The statement is executed successfully.
IoTDB> show databases
+--------------+----+-----------------------+---------------------+---------------------+
| Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
+--------------+----+-----------------------+---------------------+---------------------+
|root.test.test|null| 1| 1| 604800000|
+--------------+----+-----------------------+---------------------+---------------------+
Total line number = 1
It costs 0.006s
IoTDB> INSERT INTO root.test.test(status) values(1)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(1)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(2)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(3)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(11)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(22)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(33)
Msg: The statement is executed successfully.
IoTDB> select status from root.test.test
+-----------------------------+---------------------+
| Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-07-21T10:43:54.070+08:00| 1.0|
|2024-07-21T10:44:22.376+08:00| 1.0|
|2024-07-21T10:44:25.306+08:00| 2.0|
|2024-07-21T10:44:27.752+08:00| 3.0|
|2024-07-21T10:44:34.186+08:00| 11.0|
|2024-07-21T10:44:36.251+08:00| 22.0|
|2024-07-21T10:44:38.068+08:00| 33.0|
+-----------------------------+---------------------+
Total line number = 7
It costs 0.119s
bash tools/export-csv.sh -h <ip> -p <port> -u <username> -pw <password> -td <directory> [-tf <time-format> -datatype <true/false> -q <query command> -s <sql file>]
true (默认)
: 在CSV文件的header中时间序列的后面打印出对应的数据类型。例如:Time, root.sg1.d1.s1(INT32), root.sg1.d1.s2(INT64).false
: 只在CSV的header中打印出时间序列的名字, Time, root.sg1.d1.s1 , root.sg1.d1.s2除此之外,如果你没有使用-s和-q参数,在导出脚本被启动之后你需要按照程序提示输入查询语句,不同的查询结果会被保存到不同的CSV文件中。
[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.1-all-bin]# bash tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./
------------------------------------------
Starting IoTDB Client Export Script
------------------------------------------
ExportCsv> please input query: select status from root.test.test
select status from root.test.test
Export completely!
dump0_0.csv
就是本次导出的csv文件。
[root@VM-0-3-centos apache-iotdb-1.3.1-all-bin]# bash sbin/start-cli.sh
---------------------
Starting IoTDB Cli
---------------------
_____ _________ ______ ______
|_ _| | _ _ ||_ _ `.|_ _ \
| | .--.|_/ | | \_| | | `. \ | |_) |
| | / .'`\ \ | | | | | | | __'.
_| |_| \__. | _| |_ _| |_.' /_| |__) |
|_____|'.__.' |_____| |______.'|_______/ version 1.3.1 (Build: 214695d)
Successfully login at 127.0.0.1:6667\
IoTDB> select status from root.test.test
+----+
|Time|
+----+
+----+
Empty set.
It costs 0.184s
将在2.4小节获得的dump0_0.csv上传到导入服务器中
bash tools/import-csv.sh -h <ip> -p <port> -u <username> -pw <password> -f <xxx.csv> [-fd <./failedDirectory>] [-aligned <true>] [-tp <ms/ns/us>] [-typeInfer <boolean=text,float=double...>] [-linesPerFailedFile <int_value>]
[root@VM-0-3-centos apache-iotdb-1.3.1-all-bin]# bash tools/import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f dump0_0.csv -fd ./failed
------------------------------------------
Starting IoTDB Client Import Script
------------------------------------------
Import completely!
[root@VM-0-3-centos apache-iotdb-1.3.1-all-bin]# bash sbin/start-cli.sh
---------------------
Starting IoTDB Cli
---------------------
_____ _________ ______ ______
|_ _| | _ _ ||_ _ `.|_ _ \
| | .--.|_/ | | \_| | | `. \ | |_) |
| | / .'`\ \ | | | | | | | __'.
_| |_| \__. | _| |_ _| |_.' /_| |__) |
|_____|'.__.' |_____| |______.'|_______/ version 1.3.1 (Build: 214695d)
Successfully login at 127.0.0.1:6667
IoTDB> select status from root.test.test
+-----------------------------+---------------------+
| Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-07-21T10:43:54.070+08:00| 1.0|
|2024-07-21T10:44:22.376+08:00| 1.0|
|2024-07-21T10:44:25.306+08:00| 2.0|
|2024-07-21T10:44:27.752+08:00| 3.0|
|2024-07-21T10:44:34.186+08:00| 11.0|
|2024-07-21T10:44:36.251+08:00| 22.0|
|2024-07-21T10:44:38.068+08:00| 33.0|
+-----------------------------+---------------------+
Total line number = 7
It costs 0.164s
export-csv.sh
和import-csv.sh
,取而代之的是export-data.sh
和import-data.sh
。觉得好,就一键三连呗(点赞+收藏+关注)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。