HugeGraph-Tools 是 HugeGragh 的自动化部署、管理和备份/还原组件。
有两种方式可以获取 HugeGraph-Tools:
下载最新版本的 HugeGraph-Tools 包:
wget https://github.com/hugegraph/hugegraph-tools/releases/download/v${version}/hugegraph-tools-${version}.tar.gz tar zxvf hugegraph-tools-${version}.tar.gz
下载最新版本的 HugeGraph-Tools 源码包:
$ git clone https://github.com/hugegraph/hugegraph-tools.git
编译生成 tar 包:
cd hugegraph-tools mvn package -DskipTests
生成 tar 包 hugegraph-tools-${version}.tar.gz
解压后,进入 hugegraph-tools 目录,可以使用bin/hugegraph
或者bin/hugegraph help
来查看 usage 信息。主要分为:
Usage: hugegraph [options] [command] [command options]
options
是 HugeGraph-Tools 的全局变量,可以在 hugegraph-tools/bin/hugegraph 中配置,包括:
上述全局变量,也可以通过环境变量来设置。一种方式是在命令行使用 export 设置临时环境变量,在该命令行关闭之前均有效
全局变量 | 环境变量 | 示例 |
---|---|---|
--url | HUGEGRAPH_URL | export HUGEGRAPH_URL=http://127.0.0.1:8080 |
--graph | HUGEGRAPH_GRAPH | export HUGEGRAPH_GRAPH=hugegraph |
--user | HUGEGRAPH_USERNAME | export HUGEGRAPH_USERNAME=admin |
--password | HUGEGRAPH_PASSWORD | export HUGEGRAPH_PASSWORD=test |
另一种方式是在 bin/hugegraph 脚本中设置环境变量:
#!/bin/bash # Set environment here if needed #export HUGEGRAPH_URL= #export HUGEGRAPH_GRAPH= #export HUGEGRAPH_USERNAME= #export HUGEGRAPH_PASSWORD=
当需要把备份的图原样恢复到一个新的图中的时候,需要先将图模式设置为 RESTORING 模式;当需要将备份的图合并到已存在的图中时,需要先将图模式设置为 MERGING 模式。
--file 和 --script 二者互斥,必须设置其中之一
--file 和 --script 二者互斥,必须设置其中之一
vertex vertex-edge1 vertex-edge2...
JSON格式存储。 用户也可以自定义存储格式,只需要在hugegraph-tools/src/main/java/com/baidu/hugegraph/formatter
目录下实现一个继承自Formatter
的类,例如CustomFormatter
,使用时指定该类为formatter即可,例如 bin/hugegraph dump -f CustomFormatter
deploy命令中有可选参数 -u,提供时会使用指定的下载地址替代默认下载地址下载 tar 包,并且将地址写入
~/hugegraph-download-url-prefix
文件中;之后如果不指定地址时,会优先从~/hugegraph-download-url-prefix
指定的地址下载 tar 包;如果 -u 和~/hugegraph-download-url-prefix
都没有时,会从默认下载地址进行下载
各子命令的具体参数如下:
Usage: hugegraph [options] [command] [command options] Options: --graph Name of graph Default: hugegraph --password Password of user --timeout Connection timeout Default: 30 --url The URL of HugeGraph-Server url Default: http://127.0.0.1:8080 --user User Name Commands: graph-list List all graphs Usage: graph-list graph-get Get graph info Usage: graph-get graph-clear Clear graph schema and data Usage: graph-clear [options] Options: * --confirm-message, -c Confirm message of graph clear is "I'm sure to delete all data". (Note: include "") graph-mode-set Set graph mode Usage: graph-mode-set [options] Options: * --graph-mode, -m Graph mode, include: [NONE, RESTORING, MERGING] Possible Values: [NONE, RESTORING, MERGING] graph-mode-get Get graph mode Usage: graph-mode-get task-list List tasks Usage: task-list [options] Options: --limit Limit number, no limit if not provided Default: -1 --status Status of task task-get Get task info Usage: task-get [options] Options: * --task-id Task id Default: 0 task-delete Delete task Usage: task-delete [options] Options: * --task-id Task id Default: 0 task-cancel Cancel task Usage: task-cancel [options] Options: * --task-id Task id Default: 0 task-clear Clear completed tasks Usage: task-clear [options] Options: --force Force to clear all tasks, cancel all uncompleted tasks firstly, and delete all completed task Default: false gremlin-execute Execute Gremlin statements Usage: gremlin-execute [options] Options: --aliases, -a Gremlin aliases, valid format is: 'key1=value1,key2=value2...' Default: {} --bindings, -b Gremlin bindings, valid format is: 'key1=value1,key2=value2...' Default: {} --file, -f Gremlin Script file to be executed, UTF-8encoded, exclusive to --script --language, -l Gremlin script language Default: gremlin-groovy --script, -s Gremlin script to be executed, exclusive to --file gremlin-schedule Execute Gremlin statements as asynchronous job Usage: gremlin-schedule [options] Options: --bindings, -b Gremlin bindings, valid format is: 'key1=value1,key2=value2...' Default: {} --file, -f Gremlin Script file to be executed, UTF-8encoded, exclusive to --script --language, -l Gremlin script language Default: gremlin-groovy --script, -s Gremlin script to be executed, exclusive to --file backup Backup graph schema/data. If directory is on HDFS, use -D to set HDFS params if needed. For exmaple:-Dfs.default.name=hdfs://localhost:9000 Usage: backup [options] Options: --directory, -d Directory of graph schema/data, default is './{graphname}' in local file system or '{fs.default.name}/{graphname}' in HDFS --huge-types, -t Type of schema/data. Concat with ',' if more than one. 'all' means all vertices, edges and schema, in other words, 'all' equals with 'vertex,edge,vertex_label,edge_label,property_key,index_label' Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE] --log, -l Directory of log Default: ./logs --retry Retry times, default is 3 Default: 3 --split-size, -s Split size of shard Default: 1048576 -D HDFS config parameters Syntax: -Dkey=value Default: {} schedule-backup Schedule backup task Usage: schedule-backup [options] Options: --backup-num The number of latest backups to keep Default: 3 * --directory, -d The directory of backups stored --interval The interval of backup, format is: "a b c d e". 'a' means minute (0 - 59), 'b' means hour (0 - 23), 'c' means day of month (1 - 31), 'd' means month (1 - 12), 'e' means day of week (0 - 6) (Sunday=0), "*" means all Default: 0,0,*,*,* dump Dump graph to files Usage: dump [options] Options: --directory, -d Directory of graph schema/data, default is './{graphname}' in local file system or '{fs.default.name}/{graphname}' in HDFS --formatter, -f Formatter to customize format of vertex/edge Default: JsonFormatter --huge-types, -t Type of schema/data. Concat with ',' if more than one. 'all' means all vertices, edges and schema, in other words, 'all' equals with 'vertex,edge,vertex_label,edge_label,property_key,index_label' Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE] --log, -l Directory of log Default: ./logs --retry Retry times, default is 3 Default: 3 --split-size, -s Split size of shard Default: 1048576 -D HDFS config parameters Syntax: -Dkey=value Default: {} restore Restore graph schema/data. If directory is on HDFS, use -D to set HDFS params if needed. For exmaple:-Dfs.default.name=hdfs://localhost:9000 Usage: restore [options] Options: --directory, -d Directory of graph schema/data, default is './{graphname}' in local file system or '{fs.default.name}/{graphname}' in HDFS --huge-types, -t Type of schema/data. Concat with ',' if more than one. 'all' means all vertices, edges and schema, in other words, 'all' equals with 'vertex,edge,vertex_label,edge_label,property_key,index_label' Default: [PROPERTY_KEY, VERTEX_LABEL, EDGE_LABEL, INDEX_LABEL, VERTEX, EDGE] --log, -l Directory of log Default: ./logs --retry Retry times, default is 3 Default: 3 -D HDFS config parameters Syntax: -Dkey=value Default: {} deploy Install HugeGraph-Server and HugeGraph-Studio Usage: deploy [options] Options: * -p Install path of HugeGraph-Server and HugeGraph-Studio -u Download url prefix path of HugeGraph-Server and HugeGraph-Studio * -v Version of HugeGraph-Server and HugeGraph-Studio start-all Start HugeGraph-Server and HugeGraph-Studio Usage: start-all [options] Options: * -p Install path of HugeGraph-Server and HugeGraph-Studio * -v Version of HugeGraph-Server and HugeGraph-Studio clear Clear HugeGraph-Server and HugeGraph-Studio Usage: clear [options] Options: * -p Install path of HugeGraph-Server and HugeGraph-Studio stop-all Stop HugeGraph-Server and HugeGraph-Studio Usage: stop-all help Print usage Usage: help