• TDengine数据迁移


    前言

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

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

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

    一、taodump简介安装及使用
    https://docs.taosdata.com/reference/taosdump/#%E7%AE%80%E4%BB%8B
    二、taoTools安装

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

    三、详细dump命令
    1. Usage: taosdump [OPTION...] dbname [tbname ...]
    2. or: taosdump [OPTION...] --databases db1,db2,...
    3. or: taosdump [OPTION...] --all-databases
    4. or: taosdump [OPTION...] -i inpath
    5. or: taosdump [OPTION...] -o outpath
    6. -h, --host=HOST Server host dumping data from. Default is
    7. localhost.
    8. -p, --password User password to connect to server. Default is
    9. taosdata.
    10. -P, --port=PORT Port to connect
    11. -u, --user=USER User name used to connect to server. Default is
    12. root.
    13. -c, --config-dir=CONFIG_DIR Configure directory. Default is /etc/taos
    14. -i, --inpath=INPATH Input file path.
    15. -o, --outpath=OUTPATH Output file path.
    16. -r, --resultFile=RESULTFILE DumpOut/In Result file path and name.
    17. -a, --allow-sys Allow to dump system database
    18. -A, --all-databases Dump all databases.
    19. -D, --databases=DATABASES Dump inputted databases. Use comma to separate
    20. databases' name.
    21. -e, --escape-character Use escaped character for database name
    22. -N, --without-property Dump database without its properties.
    23. -s, --schemaonly Only dump tables' schema.
    24. -d, --avro-codec=snappy Choose an avro codec among null, deflate, snappy,
    25. and lzma.
    26. -S, --start-time=START_TIME Start time to dump. Either epoch or
    27. ISO8601/RFC3339 format is acceptable. ISO8601
    28. format example: 2017-10-01T00:00:00.000+0800 or
    29. 2017-10-0100:00:00:000+0800 or '2017-10-01
    30. 00:00:00.000+0800'
    31. -E, --end-time=END_TIME End time to dump. Either epoch or ISO8601/RFC3339
    32. format is acceptable. ISO8601 format example:
    33. 2017-10-01T00:00:00.000+0800 or
    34. 2017-10-0100:00:00.000+0800 or '2017-10-01
    35. 00:00:00.000+0800'
    36. -B, --data-batch=DATA_BATCH Number of data per query/insert statement when
    37. backup/restore. Default value is 16384. If you see
    38. 'error actual dump .. batch ..' when backup or if
    39. you see 'WAL size exceeds limit' error when
    40. restore, please adjust the value to a smaller one
    41. and try. The workable value is related to the
    42. length of the row and type of table schema.
    43. -I, --inspect inspect avro file content and print on screen
    44. -L, --loose-mode Using loose mode if the table name and column name
    45. use letter and number only. Default is NOT.
    46. -n, --no-escape No escape char '`'. Default is using it.
    47. -Q, --dot-replace Repalce dot character with underline character in
    48. the table name.(Version 2.5.3)
    49. -T, --thread-num=THREAD_NUM Number of thread for dump in file. Default is
    50. 8.
    51. -C, --cloud=CLOUD_DSN specify a DSN to access TDengine cloud service
    52. -R, --restful Use RESTful interface to connect TDengine
    53. -t, --timeout=SECONDS The timeout seconds for websocket to interact.
    54. -g, --debug Print debug info.
    55. -?, --help Give this help list
    56. --usage Give a short usage message
    57. -V, --version Print program version
    58. -W, --rename=RENAME-LIST Rename database name with new name during
    59. importing data. RENAME-LIST:
    60. "db1=newDB1|db2=newDB2" means rename db1 to newDB1
    61. and rename db2 to newDB2 (Version 2.5.4)
    62. Mandatory or optional arguments to long options are also mandatory or optional
    63. for any corresponding short options.
    64. Report bugs to <support@taosdata.com>.

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

    1. --查询TDengie中当前时间范围内的数据
    2. select count(*) from 超级表 where time >='2024-01-01T00:00:00.000+0800' and time <= '2024-06-30T23:59:59.000+0800';
    3. 本次导出数量:3378
    4. 总数量:7383
    5. --查询TDengine当前时间范围内的数据
    6. select count(*) from 超级表 where time >='2024-01-01T00:00:00.000+0800' and time <= '2024-06-30T23:59:59.000+0800';
    7. 本次导出数量:3701
    8. 总数量:3944
    9. 当前时间范围内数据导出
    10. taosdump -D 数据库名 -o /home/taosdata -S 2024-01-01T00:00:00.000+0800 -E 2024-06-30T23:59:59.000+0800
    11. 恢复当前导出的数据到另外一台TDengine(测试时使用的是我本地的虚拟机中安装的TDengine)
    12. taosdump -u root -p 123456 -i /home/taosdata

    dev环境TDengie数据增量导出

    1. --TDengine中剩余数据:4005
    2. select count(*) from 超级表 where time >= '2023-01-01T00:00:00.000+0800' and time < '2024-01-01T00:00:00.000+0800';
    3. --TDengine中剩余数据:243
    4. select count(*) from 超级表 where time >= '2023-01-01T00:00:00.000+0800' and time < '2024-01-01T00:00:00.000+0800';
    5. --当前时间范围内的数据量
    6. taosdump -D 数据库 -o /home/taosdata -S 2023-01-01T00:00:00.000+0800 -E 2024-01-01T00:00:00.000+0800
    7. 恢复当前导出的数据到另外一台TDengine(测试时使用的是我本地的虚拟机中安装的TDengine)
    8. taosdump -u root -p 123456 -i /home/taosdata

    四、TDengine数据迁移完之后对比

    迁移完成后,可以通过查询超级表中的数据的总数量来验证。
    1. select count(*) from stb_charging_working_data;
    2. select count(*) from stb_cp_chargingparameter_rpt_data;
  • 相关阅读:
    一分钟秒懂人工智能对齐
    linux误删系统目录的恢复
    TypeScript的函数(方法)
    远程小组软件开发过程(3):人
    二维相位解包理论算法和软件【全文翻译- 质量分布图(3.3)】
    小程序中实现付款功能
    gRPC协议详解
    Java基于SpringBoot的车辆充电桩
    Jenkins 如何设置GitLab的钩子
    Feign源码解析:初始化过程(一)
  • 原文地址:https://blog.csdn.net/dc282614966/article/details/139613446