Dump Tool

Dump Tool 是一个单机离线数据导出工具,可以用于导出或统计指定条件的数据。

如何获得

Dump Tool 源码位于 nebula/src/tools/db_dump 下,用户可以执行 make db_dump 命令来编译生成该工具。在使用本工具前,你可以使用 Nebula Graph CLI 的 SHOW HOSTS 命令查看分区的分布。使用 vertex_id % partition_num 来计算点对应的 key 位于哪个分区。

注意: Dump Tool 位于 rpm 包中,目录是 nebula/bin/。该工具通过直接打开 RocksDB 转储数据,因此需要离线使用,关闭该 storaged 进程,并同时保持 meta_server 已启动。具体用法请参考下方说明。

如何使用

具体用法如下所示,用户可以通过执行不带参数的 db_dump 命令获得帮助。其中 space 参数是必须的,而 db_path 以及 meta_server 具有默认值,用户可以按照实际配置。vidspartstagsedges 可以任意组合,导出你需要的数据。

  1. ./db_dump --space=<space name>
  2. required:
  3. --space=<space name>
  4. # A space name must be given.
  5. optional:
  6. --db_path=<path to rocksdb>
  7. # Path to the RocksDB data directory. If nebula was installed in `/usr/local/nebula`,
  8. # the db_path would be /usr/local/nebula/data/storage/nebula/
  9. # Default: ./
  10. --meta_server=<ip:port,...>
  11. # A list of meta severs' ip:port separated by comma.
  12. # Default: 127.0.0.1:45500
  13. --mode= scan | stat
  14. # scan: print to screen when records meet the condition, and also print statistics to screen in final.
  15. # stat: print statistics to screen.
  16. # Default: scan
  17. --vids=<list of vid>
  18. # A list of vids separated by comma. This parameter means vertex_id/edge_src_id
  19. # Would scan the whole space's records if it is not given.
  20. --parts=<list of partition id>
  21. # A list of partition ids separated by comma.
  22. # Would output all partitions if it is not given.
  23. --tags=<list of tag name>
  24. # A list of tag name separated by comma.
  25. --edges=<list of edge name>
  26. # A list of edge name separated by comma.
  27. --limit=<N>
  28. # A positive number that limits the output.
  29. # Would output all if set to 0 or negative.
  30. # Default: 1000

下面是一些示例:

  1. // 指定 space 导出数据
  2. ./db_dump --space=space_name
  3. // 指定space, db_path, meta_server
  4. ./db_dump --space=space_name --db_path=/usr/local/nebula/data/storage/nebula/ --meta_server=127.0.0.1:45513
  5. // 指定 mode=stat(统计模式),此时只返回统计信息,不打印数据
  6. ./db_dump --space=space_name --mode=stat --db_path=/usr/local/nebula/data/storage/nebula/ --meta_server=127.0.0.1:45513
  7. // 指定 vid 导出该点以及以该点为起始点的边
  8. ./db_dump --space=space_name --mode=stat --db_path=/usr/local/nebula/data/storage/nebula/ --meta_server=127.0.0.1:45513 --vids=123,456
  9. // 指定 tag 类型,导出具有该 tag 的点
  10. ./db_dump --space=space_name --mode=stat --db_path=/usr/local/nebula/data/storage/nebula/ --meta_server=127.0.0.1:45513 --tags=tag1,tag2

返回的数据格式:

  1. // 点,key: part_id, vertex_id, tag_name, value: <prop_list>
  2. [vertex] key: 1, 0, poi value:mid:0,8191765721868409651,8025713627522363385,1993089399535188613,3926276052777355165,5123607763506443893,2990089379644866415,poi_name_0,上海,华东,30.2824,120.016,poi_stat_0,poi_fc_0,poi_sc_0,0,poi_star_0,
  3. // 边, key: part_id, src_id, edge_name, ranking, dst_id, value: <prop_list>
  4. [edge] key: 1, 0, consume_poi_reverse, 0, 656384 value:mid:656384,mid:0,7.19312,mid:656384,3897457441682646732,mun:656384,4038264117233984707,dun:656384,empe:656384,mobile:656384,gender:656384,age:656384,rs:656384,fpd:656384,0.75313,1.34433,fpd:656384,0.03567,7.56212,
  5. // 统计
  6. =======================================================
  7. COUNT: 10 #本次导出记录数量
  8. VERTEX COUNT: 1 #本次导出点数量
  9. EDGE COUNT: 9 #本次导出边数量
  10. TAG STATISTICS: #本次导出tag统计
  11. poi : 1
  12. EDGE STATISTICS: #本次导出edge统计
  13. consume_poi_reverse : 9
  14. =======================================================