有两种方式可以获取 HugeGraph-Tools:

    • 下载二进制tar包
    • 下载源码编译安装

    2.1 下载二进制tar包

    下载最新版本的 HugeGraph-Tools 包:

    2.2 下载源码编译安装

    下载最新版本的 HugeGraph-Tools 源码包:

    编译生成 tar 包:

    3.1 功能概览

    解压后,进入 hugegraph-tools 目录,可以使用bin/hugegraph或者bin/hugegraph help来查看 usage 信息。主要分为:

    • 图管理类,graph-mode-set、graph-mode-get、graph-list、graph-get 和 graph-clear
    • 异步任务管理类,task-list、task-get、task-delete、task-cancel 和 task-clear
    • Gremlin类,gremlin-execute 和 gremlin-schedule
    • 备份/恢复类,backup、restore、migrate、schedule-backup 和 dump
    • 安装部署类,deploy、clear、start-all 和 stop-all
    1. Usage: hugegraph [options] [command] [command options]
    3.2 [options]-全局变量

    options是 HugeGraph-Tools 的全局变量,可以在 hugegraph-tools/bin/hugegraph 中配置,包括:

    • —graph,HugeGraph-Tools 操作的图的名字,默认值是 hugegraph
    • —url,HugeGraph-Server 的服务地址,默认是
    • —user,当 HugeGraph-Server 开启认证时,传递用户名
    • —password,当 HugeGraph-Server 开启认证时,传递用户的密码
    • —timeout, 连接 HugeGraph-Server 时的超时时间,默认是 30s

    上述全局变量,也可以通过环境变量来设置。一种方式是在命令行使用 export 设置临时环境变量,在该命令行关闭之前均有效

    另一种方式是在 bin/hugegraph 脚本中设置环境变量:

    3.3 图管理类,graph-mode-set、graph-mode-get、graph-list、graph-get和graph-clear
    • graph-mode-set,设置图的 restore mode
      • —graph-mode 或者 -m,必填项,指定将要设置的模式,合法值包括 [NONE, RESTORING, MERGING]
    • graph-mode-get,获取图的 restore mode
    • graph-list,列出某个 HugeGraph-Server 中全部的图
    • graph-get,获取某个图及其存储后端类型
    • graph-clear,清除某个图的全部 schema 和 data
      • —confirm-message 或者 -c,必填项,删除确认信息,需要手动输入,二次确认防止误删,”I’m sure to delete all data”,包括双引号
    3.4 异步任务管理类,task-list、task-get和task-delete
    • task-list,列出某个图中的异步任务,可以根据任务的状态过滤
      • —status,选填项,指定要查看的任务的状态,即按状态过滤任务
      • —limit,选填项,指定要获取的任务的数目,默认为 -1,意思为获取全部符合条件的任务
    • task-get,获取某个异步任务的详细信息
      • —task-id,必填项,指定异步任务的 ID
    • task-delete,删除某个异步任务的信息
      • —task-id,必填项,指定异步任务的 ID
    • task-cancel,取消某个异步任务的执行
      • —task-id,要取消的异步任务的 ID
    • task-clear,清理完成的异步任务
      • —force,选填项,设置时,表示清理全部异步任务,未执行完成的先取消,然后清除所有异步任务。默认只清理已完成的异步任务
    3.5 Gremlin类,gremlin-execute和gremlin-schedule
    • gremlin-execute,发送 Gremlin 语句到 HugeGraph-Server 来执行查询或修改操作,同步执行,结束后返回结果
      • —file 或者 -f,指定要执行的脚本文件,UTF-8编码,与 —script 互斥
      • —script 或者 -s,指定要执行的脚本字符串,与 —file 互斥
      • —aliases 或者 -a,Gremlin 别名设置,格式为:key1=value1,key2=value2,…
      • —bindings 或者 -b,Gremlin 绑定设置,格式为:key1=value1,key2=value2,…
      • —language 或者 -l,Gremlin 脚本的语言,默认为 gremlin-groovy
    • gremlin-schedule,发送 Gremlin 语句到 HugeGraph-Server 来执行查询或修改操作,异步执行,任务提交后立刻返回异步任务id
      • —file 或者 -f,指定要执行的脚本文件,UTF-8编码,与 —script 互斥
      • —script 或者 -s,指定要执行的脚本字符串,与 —file 互斥
      • —bindings 或者 -b,Gremlin 绑定设置,格式为:key1=value1,key2=value2,…
      • —language 或者 -l,Gremlin 脚本的语言,默认为 gremlin-groovy
    3.6 备份/恢复类
    • backup,将某张图中的 schema 或者 data 备份到 HugeGraph 系统之外,以 JSON 形式存在本地磁盘或者 HDFS
      • —directory 或者 -d,存储 schema 或者 data 的目录,本地目录时,默认为’./{graphName}’,HDFS 时,默认为 ‘{fs.default.name}/{graphName}’
      • —huge-types 或者 -t,要备份的数据类型,逗号分隔,可选值为 ‘all’ 或者 一个或多个 [vertex,edge,vertex_label,edge_label,property_key,index_label] 的组合,’all’ 代表全部6种类型,即顶点、边和所有schema
      • —log 或者 -l,指定日志目录,默认为当前目录
      • —retry,指定失败重试次数,默认为 3
      • —split-size 或者 -s,指定在备份时对顶点或者边分块的大小,默认为 1048576
      • -D,用 -Dkey=value 的模式指定动态参数,用来备份数据到 HDFS 时,指定 HDFS 的配置项,例如:-Dfs.default.name=hdfs://localhost:9000
    • restore,将 JSON 格式存储的 schema 或者 data 恢复到一个新图中(RESTORING 模式)或者合并到已存在的图中(MERGING 模式)
      • —directory 或者 -d,存储 schema 或者 data 的目录,本地目录时,默认为’./{graphName}’,HDFS 时,默认为 ‘{fs.default.name}/{graphName}’
      • —huge-types 或者 -t,要恢复的数据类型,逗号分隔,可选值为 ‘all’ 或者 一个或多个 [vertex,edge,vertex_label,edge_label,property_key,index_label] 的组合,’all’ 代表全部6种类型,即顶点、边和所有schema
      • —log 或者 -l,指定日志目录,默认为当前目录
      • —retry,指定失败重试次数,默认为 3
      • -D,用 -Dkey=value 的模式指定动态参数,用来从 HDFS 恢复图时,指定 HDFS 的配置项,例如:-Dfs.default.name=hdfs://localhost:9000
    • migrate, 将图从一个 HugeGraphServer 迁移至另一个 HugeGraphServer
      • —source-graph,源图的名字
      • —source-url,源图所在的 HugeGraphServer 的URL
      • —target-graph,目标图的名字
      • —target-url,目标图所在的 HugeGraphServer
      • —directory 或者 -d,迁移过程中,存储源图的 schema 或者 data 的目录,本地目录时,默认为’./{graphName}’,HDFS 时,默认为 ‘{fs.default.name}/{graphName}’
      • —huge-types 或者 -t,要迁移的数据类型,逗号分隔,可选值为 ‘all’ 或者 一个或多个 [vertex,edge,vertex_label,edge_label,property_key,index_label] 的组合,’all’ 代表全部6种类型,即顶点、边和所有schema
      • —log 或者 -l,指定日志目录,默认为当前目录
      • —retry,指定失败重试次数,默认为 3
      • —split-size 或者 -s,指定迁移过程中对源图进行备份时顶点或者边分块的大小,默认为 1048576
      • -D,用 -Dkey=value 的模式指定动态参数,用来在迁移图过程中需要备份数据到 HDFS 时,指定 HDFS 的配置项,例如:-Dfs.default.name=hdfs://localhost:9000
      • —graph-mode 或者 -m,将源图恢复到目标图时将目标图设置的模式,合法值包括 [RESTORING, MERGING]
      • —clean,是否删除在迁移图的过程中产生的源图的备份,默认为 true,即默认迁移图结束后清理产生的源图备份
    • schedule-backup,周期性对图执行备份操作,并保留一定数目的最新备份(目前仅支持本地文件系统)
      • —directory 或者 -d,必填项,指定备份数据的目录
      • —backup-num,选填项,指定保存的最新的备份的数目,默认为 3
      • —interval,选填项,指定进行备份的周期,格式同 Linux crontab 格式
    • dump,把整张图的顶点和边全部导出,默认以vertex vertex-edge1 vertex-edge2...JSON格式存储。用户也可以自定义存储格式,只需要在hugegraph-tools/src/main/java/com/baidu/hugegraph/formatter目录下实现一个继承自Formatter的类,例如CustomFormatter,使用时指定该类为formatter即可,例如bin/hugegraph dump -f CustomFormatter
      • —formatter 或者 -f,指定使用的 formatter,默认为 JsonFormatter
      • —directory 或者 -d,存储 schema 或者 data 的目录,默认为当前目录
      • —huge-types 或者 -t,要备份的数据类型,逗号分隔,可选值为 ‘all’ 或者 一个或多个 [vertex,edge,vertex_label,edge_label,property_key,index_label] 的组合,’all’ 代表全部6种类型
      • —log 或者 -l,指定日志目录,默认为当前目录
      • —retry,指定失败重试次数,默认为 3
      • —split-size 或者 -s,指定在备份时对顶点或者边分块的大小,默认为 1048576
      • -D,用 -Dkey=value 的模式指定动态参数,用来备份数据到 HDFS 时,指定 HDFS 的配置项,例如:-Dfs.default.name=hdfs://localhost:9000
    3.7 安装部署类
    • deploy,一键下载、安装和启动 HugeGraph-Server 和 HugeGraph-Studio
      • -v,必填项,指明安装的 HugeGraph-Server 和 HugeGraph-Studio 的版本号,最新的是 0.9
      • -p,必填项,指定安装的 HugeGraph-Server 和 HugeGraph-Studio 目录
      • -u,选填项,指定下载 HugeGraph-Server 和 HugeGraph-Studio 压缩包的链接
    • clear,清理 HugeGraph-Server 和 HugeGraph-Studio 目录和tar包
      • -p,必填项,指定要清理的 HugeGraph-Server 和 HugeGraph-Studio 的目录
    • start-all,一键启动 HugeGraph-Server 和 HugeGraph-Studio,并启动监控,服务死掉时自动拉起服务
      • -v,必填项,指明要启动的 HugeGraph-Server 和 HugeGraph-Studio 的版本号,最新的是 0.9
      • -p,必填项,指定安装了 HugeGraph-Server 和 HugeGraph-Studio 的目录
    • stop-all,一键关闭 HugeGraph-Server 和 HugeGraph-Studio
    3.8 具体命令参数

    各子命令的具体参数如下:

    1. Usage: hugegraph [options] [command] [command options]
    2. Options:
    3. --graph
    4. Name of graph
    5. Default: hugegraph
    6. --password
    7. Password of user
    8. --timeout
    9. Connection timeout
    10. Default: 30
    11. --url
    12. The URL of HugeGraph-Server
    13. Default: http://127.0.0.1:8080
    14. --user
    15. User Name
    16. Commands:
    17. graph-list List all graphs
    18. Usage: graph-list
    19. graph-get Get graph info
    20. Usage: graph-get
    21. graph-clear Clear graph schema and data
    22. Options:
    23. * --confirm-message, -c
    24. Confirm message of graph clear is "I'm sure to delete all data".
    25. (Note: include "")
    26. graph-mode-set Set graph mode
    27. Usage: graph-mode-set [options]
    28. Options:
    29. * --graph-mode, -m
    30. Graph mode, include: [NONE, RESTORING, MERGING]
    31. Possible Values: [NONE, RESTORING, MERGING]
    32. graph-mode-get Get graph mode
    33. Usage: graph-mode-get
    34. task-list List tasks
    35. Usage: task-list [options]
    36. Options:
    37. --limit
    38. Limit number, no limit if not provided
    39. Default: -1
    40. --status
    41. Status of task
    42. task-get Get task info
    43. Usage: task-get [options]
    44. Options:
    45. * --task-id
    46. Task id
    47. Default: 0
    48. task-delete Delete task
    49. Usage: task-delete [options]
    50. Options:
    51. * --task-id
    52. Task id
    53. Default: 0
    54. task-cancel Cancel task
    55. Usage: task-cancel [options]
    56. Options:
    57. * --task-id
    58. Task id
    59. Default: 0
    60. task-clear Clear completed tasks
    61. Usage: task-clear [options]
    62. Options:
    63. --force
    64. Force to clear all tasks, cancel all uncompleted tasks firstly,
    65. and delete all completed tasks
    66. Default: false
    67. gremlin-execute Execute Gremlin statements
    68. Usage: gremlin-execute [options]
    69. Options:
    70. --aliases, -a
    71. Gremlin aliases, valid format is: 'key1=value1,key2=value2...'
    72. Default: {}
    73. --bindings, -b
    74. Gremlin bindings, valid format is: 'key1=value1,key2=value2...'
    75. --file, -f
    76. Gremlin Script file to be executed, UTF-8 encoded, exclusive to
    77. --script
    78. --language, -l
    79. Gremlin script language
    80. Default: gremlin-groovy
    81. --script, -s
    82. Gremlin script to be executed, exclusive to --file
    83. gremlin-schedule Execute Gremlin statements as asynchronous job
    84. Usage: gremlin-schedule [options]
    85. Options:
    86. --bindings, -b
    87. Gremlin bindings, valid format is: 'key1=value1,key2=value2...'
    88. Default: {}
    89. --file, -f
    90. Gremlin Script file to be executed, UTF-8 encoded, exclusive to
    91. --script
    92. --language, -l
    93. Gremlin script language
    94. Default: gremlin-groovy
    95. --script, -s
    96. Gremlin script to be executed, exclusive to --file
    97. backup Backup graph schema/data. If directory is on HDFS, use -D to
    98. set HDFS params if needed. For exmaple:
    99. -Dfs.default.name=hdfs://localhost:9000
    100. Usage: backup [options]
    101. Options:
    102. --directory, -d
    103. Directory of graph schema/data, default is './{graphname}' in
    104. local file system or '{fs.default.name}/{graphname}' in HDFS
    105. --huge-types, -t
    106. Type of schema/data. Concat with ',' if more than one. 'all' means
    107. all vertices, edges and schema, in other words, 'all' equals with
    108. 'vertex,edge,vertex_label,edge_label,property_key,index_label'
    109. Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE]
    110. --log, -l
    111. Directory of log
    112. Default: ./logs
    113. --retry
    114. Retry times, default is 3
    115. Default: 3
    116. --split-size, -s
    117. Split size of shard
    118. Default: 1048576
    119. -D
    120. HDFS config parameters
    121. Syntax: -Dkey=value
    122. Default: {}
    123. schedule-backup Schedule backup task
    124. Usage: schedule-backup [options]
    125. Options:
    126. --backup-num
    127. The number of latest backups to keep
    128. Default: 3
    129. * --directory, -d
    130. The directory of backups stored
    131. --interval
    132. The interval of backup, format is: "a b c d e". 'a' means minute
    133. (0 - 59), 'b' means hour (0 - 23), 'c' means day of month (1 -
    134. 31), 'd' means month (1 - 12), 'e' means day of week (0 - 6)
    135. (Sunday=0), "*" means all
    136. Default: "0 0 * * *"
    137. dump Dump graph to files
    138. Usage: dump [options]
    139. Options:
    140. --directory, -d
    141. Directory of graph schema/data, default is './{graphname}' in
    142. local file system or '{fs.default.name}/{graphname}' in HDFS
    143. --formatter, -f
    144. Formatter to customize format of vertex/edge
    145. Default: JsonFormatter
    146. --huge-types, -t
    147. Type of schema/data. Concat with ',' if more than one. 'all' means
    148. all vertices, edges and schema, in other words, 'all' equals with
    149. 'vertex,edge,vertex_label,edge_label,property_key,index_label'
    150. Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE]
    151. --log, -l
    152. Directory of log
    153. Default: ./logs
    154. --retry
    155. Retry times, default is 3
    156. Default: 3
    157. --split-size, -s
    158. Split size of shard
    159. Default: 1048576
    160. -D
    161. HDFS config parameters
    162. Syntax: -Dkey=value
    163. Default: {}
    164. restore Restore graph schema/data. If directory is on HDFS, use -D to
    165. set HDFS params if needed. For
    166. exmaple:-Dfs.default.name=hdfs://localhost:9000
    167. Options:
    168. --clean
    169. Whether to remove the directory of graph data after restored
    170. Default: false
    171. --directory, -d
    172. Directory of graph schema/data, default is './{graphname}' in
    173. local file system or '{fs.default.name}/{graphname}' in HDFS
    174. --huge-types, -t
    175. Type of schema/data. Concat with ',' if more than one. 'all' means
    176. all vertices, edges and schema, in other words, 'all' equals with
    177. 'vertex,edge,vertex_label,edge_label,property_key,index_label'
    178. Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE]
    179. --log, -l
    180. Directory of log
    181. Default: ./logs
    182. --retry
    183. Retry times, default is 3
    184. Default: 3
    185. -D
    186. HDFS config parameters
    187. Syntax: -Dkey=value
    188. Default: {}
    189. migrate Migrate graph
    190. Usage: migrate [options]
    191. Options:
    192. --clean
    193. Whether to remove the directory of graph data after restored
    194. Default: true
    195. --directory, -d
    196. Directory of graph schema/data, default is './{graphname}' in
    197. local file system or '{fs.default.name}/{graphname}' in HDFS
    198. --graph-mode, -m
    199. Mode used when migrating to target graph, include: [RESTORING,
    200. MERGING]
    201. Default: RESTORING
    202. Possible Values: [NONE, RESTORING, MERGING]
    203. --huge-types, -t
    204. Type of schema/data. Concat with ',' if more than one. 'all' means
    205. all vertices, edges and schema, in other words, 'all' equals with
    206. 'vertex,edge,vertex_label,edge_label,property_key,index_label'
    207. Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE]
    208. --log, -l
    209. Directory of log
    210. Default: ./logs
    211. --retry
    212. Retry times, default is 3
    213. Default: 3
    214. --source-graph
    215. The source graph to migrate
    216. Default: hugegraph
    217. --source-url
    218. The source graph url to migrate
    219. Default: http://127.0.0.1:8080
    220. --split-size, -s
    221. Split size of shard
    222. Default: 1048576
    223. --target-graph
    224. The target graph to migrate
    225. Default: hugegraph
    226. --target-url
    227. The target graph url to migrate
    228. Default: http://127.0.0.1:8081
    229. -D
    230. HDFS config parameters
    231. Syntax: -Dkey=value
    232. Default: {}
    233. deploy Install HugeGraph-Server and HugeGraph-Studio
    234. Usage: deploy [options]
    235. Options:
    236. * -p
    237. Install path of HugeGraph-Server and HugeGraph-Studio
    238. -u
    239. Download url prefix path of HugeGraph-Server and HugeGraph-Studio
    240. * -v
    241. Version of HugeGraph-Server and HugeGraph-Studio
    242. start-all Start HugeGraph-Server and HugeGraph-Studio
    243. Usage: start-all [options]
    244. Options:
    245. * -p
    246. Install path of HugeGraph-Server and HugeGraph-Studio
    247. * -v
    248. Version of HugeGraph-Server and HugeGraph-Studio
    249. clear Clear HugeGraph-Server and HugeGraph-Studio
    250. Usage: clear [options]
    251. Options:
    252. * -p
    253. Install path of HugeGraph-Server and HugeGraph-Studio
    254. stop-all Stop HugeGraph-Server and HugeGraph-Studio
    255. Usage: stop-all
    256. Usage: help