TDengine数据迁移

前言

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

taosdump 可以用数据库、超级表或普通表作为逻辑数据单元进行备份,也可以对数据库、超级 表和普通表中指定时间段内的数据记录进行备份。使用时可以指定数据备份的目录路径,如果 不指定位置,taosdump 默认会将数据备份到当前目录。

如果指定的位置已经有数据文件,taosdump 会提示用户并立即退出,避免数据被覆盖。这意味着同一路径只能被用于一次备份。 如果看到相关提示,请小心操作。

一、taodump简介安装及使用

https://docs.taosdata.com/reference/taosdump/#简介

二、taoTools安装

安装包下载:https://docs.taosdata.com/releases/tools/

三、详细dump命令
复制代码
Usage: taosdump [OPTION...] dbname [tbname ...]
  or:  taosdump [OPTION...] --databases db1,db2,...
  or:  taosdump [OPTION...] --all-databases
  or:  taosdump [OPTION...] -i inpath
  or:  taosdump [OPTION...] -o outpath

  -h, --host=HOST            Server host dumping data from. Default is
                             localhost.
  -p, --password             User password to connect to server. Default is
                             taosdata.
  -P, --port=PORT            Port to connect
  -u, --user=USER            User name used to connect to server. Default is
                             root.
  -c, --config-dir=CONFIG_DIR   Configure directory. Default is /etc/taos
  -i, --inpath=INPATH        Input file path.
  -o, --outpath=OUTPATH      Output file path.
  -r, --resultFile=RESULTFILE   DumpOut/In Result file path and name.
  -a, --allow-sys            Allow to dump system database
  -A, --all-databases        Dump all databases.
  -D, --databases=DATABASES  Dump inputted databases. Use comma to separate
                             databases' name.
  -e, --escape-character     Use escaped character for database name
  -N, --without-property     Dump database without its properties.
  -s, --schemaonly           Only dump tables' schema.
  -d, --avro-codec=snappy    Choose an avro codec among null, deflate, snappy,
                             and lzma.
  -S, --start-time=START_TIME   Start time to dump. Either epoch or
                             ISO8601/RFC3339 format is acceptable. ISO8601
                             format example: 2017-10-01T00:00:00.000+0800 or
                             2017-10-0100:00:00:000+0800 or '2017-10-01
                             00:00:00.000+0800'
  -E, --end-time=END_TIME    End time to dump. Either epoch or ISO8601/RFC3339
                             format is acceptable. ISO8601 format example:
                             2017-10-01T00:00:00.000+0800 or
                             2017-10-0100:00:00.000+0800 or '2017-10-01
                             00:00:00.000+0800'
  -B, --data-batch=DATA_BATCH   Number of data per query/insert statement when
                             backup/restore. Default value is 16384. If you see
                             'error actual dump .. batch ..' when backup or if
                             you see 'WAL size exceeds limit' error when
                             restore, please adjust the value to a smaller one
                             and try. The workable value is related to the
                             length of the row and type of table schema.
  -I, --inspect              inspect avro file content and print on screen
  -L, --loose-mode           Using loose mode if the table name and column name
                             use letter and number only. Default is NOT.
  -n, --no-escape            No escape char '`'. Default is using it.
  -Q, --dot-replace          Repalce dot character with underline character in
                             the table name.(Version 2.5.3)
  -T, --thread-num=THREAD_NUM   Number of thread for dump in file. Default is
                             8.
  -C, --cloud=CLOUD_DSN      specify a DSN to access TDengine cloud service
  -R, --restful              Use RESTful interface to connect TDengine
  -t, --timeout=SECONDS      The timeout seconds for websocket to interact.
  -g, --debug                Print debug info.
  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version
  -W, --rename=RENAME-LIST   Rename database name with new name during
                             importing data. RENAME-LIST: 
                             "db1=newDB1|db2=newDB2" means rename db1 to newDB1
                             and rename db2 to newDB2 (Version 2.5.4)

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

Report bugs to <support@taosdata.com>.

dev环境TDengie数据按照时间导出

复制代码
--查询TDengie中当前时间范围内的数据
select count(*) from 超级表 where time >='2024-01-01T00:00:00.000+0800' and time <= '2024-06-30T23:59:59.000+0800';
本次导出数量:3378
总数量:7383

--查询TDengine当前时间范围内的数据
select count(*) from 超级表 where time >='2024-01-01T00:00:00.000+0800' and time <= '2024-06-30T23:59:59.000+0800';
本次导出数量:3701
总数量:3944


当前时间范围内数据导出
taosdump -D 数据库名 -o /home/taosdata -S 2024-01-01T00:00:00.000+0800 -E 2024-06-30T23:59:59.000+0800

恢复当前导出的数据到另外一台TDengine(测试时使用的是我本地的虚拟机中安装的TDengine)
taosdump -u root -p 123456 -i /home/taosdata

dev环境TDengie数据增量导出

复制代码
--TDengine中剩余数据:4005
select count(*) from 超级表 where time >= '2023-01-01T00:00:00.000+0800' and time < '2024-01-01T00:00:00.000+0800';

--TDengine中剩余数据:243
select count(*) from 超级表 where time >= '2023-01-01T00:00:00.000+0800' and time < '2024-01-01T00:00:00.000+0800';

--当前时间范围内的数据量
taosdump -D 数据库 -o /home/taosdata -S 2023-01-01T00:00:00.000+0800 -E 2024-01-01T00:00:00.000+0800

恢复当前导出的数据到另外一台TDengine(测试时使用的是我本地的虚拟机中安装的TDengine)
taosdump -u root -p 123456 -i /home/taosdata

四、TDengine 数据迁移完之后对比
迁移完成后,可以通过查询超级表中的数据的总数量来验证。

复制代码
select count(*) from stb_charging_working_data;
select count(*) from stb_cp_chargingparameter_rpt_data;
相关推荐
焦糖布丁的午夜7 小时前
MySQL数据库大王小练习
数据库·mysql
windfantasy19907 小时前
编程考级体系:覆盖全学段多科目的优势分析
大数据
狗头实习生8 小时前
Spring常见的事务失效原因
java·数据库·spring
19226388 小时前
新能源场景生成与削减:Matlab 实现之旅
tdengine
冉冰学姐8 小时前
SSM泰兴市公交信息系统f504u(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·ssm 框架应用·泰兴市公交·息管理系统
偶像你挑的噻10 小时前
3.Qt-基础布局以及事件
开发语言·数据库·qt
Dxy123931021610 小时前
MySQL如何做读写分离架构
数据库·mysql·架构
wheelerer11 小时前
企业营销的隐形门槛:当规则成为第一道城墙
大数据·营销·流量营销
毕设十刻11 小时前
基于Vue的考勤管理系统8n7j8(程序 + 源码 + 数据库 + 调试部署 + 开发环境配置),配套论文文档字数达万字以上,文末可获取,系统界面展示置于文末
前端·数据库·vue.js
跨境猫小妹12 小时前
亚马逊合规新纪元:隐形战场里,谁在悄悄出局?
大数据·人工智能·产品运营·跨境电商·防关联