HugeGraph-Tools is an automated deployment, management and backup/restore component of HugeGraph.
There are two ways to get HugeGraph-Tools:
Download the latest version of the HugeGraph-Toolchain package:
wget https://downloads.apache.org/incubator/hugegraph/1.0.0/apache-hugegraph-toolchain-incubating-1.0.0.tar.gz tar zxf *hugegraph*.tar.gz
Please ensure that the wget command is installed before compiling the source code
Download the latest version of the HugeGraph-Tools source package:
# 1. get from github git clone https://github.com/apache/hugegraph-toolchain.git # 2. get from direct (e.g. here is 1.0.0, please choose the latest version) wget https://downloads.apache.org/incubator/hugegraph/1.0.0/apache-hugegraph-toolchain-incubating-1.0.0-src.tar.gz
Compile and generate tar package:
cd hugegraph-tools mvn package -DskipTests
Generate tar package hugegraph-tools-${version}.tar.gz
After decompression, enter the hugegraph-tools directory, you can use bin/hugegraph or bin/hugegraph help to view the usage information. mainly divided:
Usage: hugegraph [options] [command] [command options]
options is a global variable of HugeGraph-Tools, which can be configured in hugegraph-tools/bin/hugegraph, including:
The above global variables can also be set through environment variables. One way is to use export on the command line to set temporary environment variables, which are valid until the command line is closed
| Global Variable | Environment Variable | Example |
|---|---|---|
| --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 |
| --timeout | HUGEGRAPH_TIMEOUT | export HUGEGRAPH_TIMEOUT=30 |
| --trust-store-file | HUGEGRAPH_TRUST_STORE_FILE | export HUGEGRAPH_TRUST_STORE_FILE=/tmp/trust-store |
| --trust-store-password | HUGEGRAPH_TRUST_STORE_PASSWORD | export HUGEGRAPH_TRUST_STORE_PASSWORD=xxxx |
Another way is to set the environment variable in the bin/hugegraph script:
#!/bin/bash # Set environment here if needed #export HUGEGRAPH_URL= #export HUGEGRAPH_GRAPH= #export HUGEGRAPH_USERNAME= #export HUGEGRAPH_PASSWORD= #export HUGEGRAPH_TIMEOUT= #export HUGEGRAPH_TRUST_STORE_FILE= #export HUGEGRAPH_TRUST_STORE_PASSWORD=
When you need to restore the backup graph to a new graph, you need to set the graph mode to RESTORING mode; when you need to merge the backup graph into an existing graph, you need to first set the graph mode to MERGING model.
--file and --script are mutually exclusive, one of them must be set
--file and --script are mutually exclusive, one of them must be set
'./{graphName}' for local directory, and '{fs.default.name}/{graphName}' for HDFS`'./{graphName}' for local directory, and '{fs.default.name}/{graphName}' for HDFSrestore command can be used only if --format is executed as backup for json
'./{graphName}'; for HDFS, the default is '{fs.default.name}/{graphName}'vertex vertex-edge1 vertex-edge2...JSON format by default. Users can also customize the storage format, just need to be in hugegraph-tools/src/main/java/com/baidu/hugegraph/formatter Implement a class inherited from Formatter in the directory, such as CustomFormatter, and specify this class as formatter when using it, for example bin/hugegraph dump -f CustomFormatterThere is an optional parameter -u in the deploy command. When provided, the specified download address will be used instead of the default download address to download the tar package, and the address will be written into the
~/hugegraph-download-url-prefixfile; if no address is specified later When -u and~/hugegraph-download-url-prefixare not specified, the tar package will be downloaded from the address specified by~/hugegraph-download-url-prefix; if there is neither -u nor~/hugegraph-download-url-prefix, it will be downloaded from the default download address
The specific parameters of each subcommand are as follows:
Usage: hugegraph [options] [command] [command options] Options: --graph Name of graph Default: hugegraph --password Password of user --timeout Connection timeout Default: 30 --trust-store-file The path of client truststore file used when https protocol is enabled --trust-store-password The password of the client truststore file used when the https protocol is enabled --url The URL of HugeGraph-Server Default: http://127.0.0.1:8080 --user Name of user 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, LOADING] 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 tasks 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-8 encoded, 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-8 encoded, 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. For exmaple: -Dfs.default.name=hdfs://localhost:9000 Usage: backup [options] Options: --all-properties All properties to be backup flag Default: false --compress compress flag Default: true --directory, -d Directory of graph schema/data, default is './{graphname}' in local file system or '{fs.default.name}/{graphname}' in HDFS --format File format, valid is [json, text] Default: json --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] --label Vertex or edge label, only valid when type is vertex or edge --log, -l Directory of log Default: ./logs --properties Vertex or edge properties to backup, only valid when type is vertex or edge Default: [] --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 --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: --clean Whether to remove the directory of graph data after restored Default: false --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: {} migrate Migrate graph Usage: migrate [options] Options: --directory, -d Directory of graph schema/data, default is './{graphname}' in local file system or '{fs.default.name}/{graphname}' in HDFS --graph-mode, -m Mode used when migrating to target graph, include: [RESTORING, MERGING] Default: RESTORING Possible Values: [NONE, RESTORING, MERGING, LOADING] --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] --keep-local-data Whether to keep the local directory of graph data after restored Default: false --log, -l Directory of log Default: ./logs --retry Retry times, default is 3 Default: 3 --split-size, -s Split size of shard Default: 1048576 --target-graph The name of target graph to migrate Default: hugegraph --target-password The password of target graph to migrate --target-timeout The timeout to connect target graph to migrate Default: 0 --target-trust-store-file The trust store file of target graph to migrate --target-trust-store-password The trust store password of target graph to migrate --target-url The url of target graph to migrate Default: http://127.0.0.1:8081 --target-user The username of target graph to migrate -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
# Execute gremlin synchronously ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph gremlin-execute --script 'g.V().count()' # Execute gremlin asynchronously ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph gremlin-schedule --script 'g.V().count()'
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph task-list ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph task-list --limit 5 ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph task-list --status success
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-mode-set -m RESTORING MERGING NONE ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-mode-set -m RESTORING ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-mode-get ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-list
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-clear -c "I'm sure to delete all data"
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph backup -t all --directory ./backup-test
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph --interval */2 * * * * schedule-backup -d ./backup-0.10.2
# set graph mode ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-mode-set -m RESTORING # recovery graph ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph restore -t all --directory ./backup-test # restore graph mode ./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-mode-set -m NONE
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph migrate --target-url http://127.0.0.1:8090 --target-graph hugegraph