- HugeGraph-Tools Quick Start
- 1 HugeGraph-Tools Overview
- 2 Get HugeGraph-Tools
- 3 How to use
- 3.1 Function overview
- 3.2 [options]-Global Variable
- 3.3 Graph Management Type,graph-mode-set、graph-mode-get、graph-list、graph-get and graph-clear
- 3.4 Asynchronous task management Type,task-list、task-get and task-delete
- 3.5 Gremlin Type,gremlin-execute and gremlin-schedule
- 3.6 Backup/Restore Type
- 3.7 Install the deployment type
- 3.8 Specific command parameters
- 3.9 Specific command example
- 3.1 Function overview
HugeGraph-Tools Quick Start
1 HugeGraph-Tools Overview
HugeGraph-Tools is an automated deployment, management and backup/restore component of HugeGraph.
2 Get HugeGraph-Tools
There are two ways to get HugeGraph-Tools:
- Download the compiled tarball
- Clone source code then compile and install
2.1 Download the compiled archive
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.gztar zxf *hugegraph*.tar.gz
2.2 Clone source code to compile and install
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 githubgit 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-toolsmvn package -DskipTests
Generate tar package hugegraph-tools-${version}.tar.gz
3 How to use
3.1 Function overview
After decompression, enter the hugegraph-tools directory, you can use bin/hugegraph or bin/hugegraph help to view the usage information. mainly divided:
- Graph management Type,graph-mode-set、graph-mode-get、graph-list、graph-get and graph-clear
- Asynchronous task management Type,task-list、task-get、task-delete、task-cancel and task-clear
- Gremlin Type,gremlin-execute and gremlin-schedule
- Backup/Restore Type,backup、restore、migrate、schedule-backup and dump
- Install the deployment Type,deploy、clear、start-all and stop-all
Usage: hugegraph [options] [command] [command options]
3.2 [options]-Global Variable
options is a global variable of HugeGraph-Tools, which can be configured in hugegraph-tools/bin/hugegraph, including:
- –graph,HugeGraph-Tools The name of the graph to operate on, the default value is hugegraph
- –url,The service address of HugeGraph-Server, the default is http://127.0.0.1:8080
- –user,When HugeGraph-Server opens authentication, pass username
- –password,When HugeGraph-Server opens authentication, pass the user’s password
- –timeout,Timeout when connecting to HugeGraph-Server, the default is 30s
- –trust-store-file,The path of the certificate file, when –url uses https, the truststore file used by HugeGraph-Client, the default is empty, which means using the built-in truststore file conf/hugegraph.truststore of hugegraph-tools
- –trust-store-password,The password of the certificate file, when –url uses https, the password of the truststore used by HugeGraph-Client, the default is empty, representing the password of the built-in truststore file of hugegraph-tools
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=
3.3 Graph Management Type,graph-mode-set、graph-mode-get、graph-list、graph-get and graph-clear
- graph-mode-set,set graph restore mode
- –graph-mode or -m, required, specifies the mode to be set, legal values include [NONE, RESTORING, MERGING, LOADING]
- graph-mode-get,get graph restore mode
- graph-list,list all graphs in a HugeGraph-Server
- graph-get,get a graph and its storage backend type
- graph-clear,clear all schema and data of a graph
- –confirm-message Or -c, required, delete confirmation information, manual input is required, double confirmation to prevent accidental deletion, “I’m sure to delete all data”, including double quotes
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.
3.4 Asynchronous task management Type,task-list、task-get and task-delete
- task-list,List the asynchronous tasks in a graph, which can be filtered according to the status of the tasks
- –status,Optional, specify the status of the task to view, i.e. filter tasks by status
- –limit,Optional, specify the number of tasks to be obtained, the default is -1, which means to obtain all eligible tasks
- task-get,Get detailed information about an asynchronous task
- –task-id,Required, specifies the ID of the asynchronous task
- task-delete,Delete information about an asynchronous task
- –task-id,Required, specifies the ID of the asynchronous task
- task-cancel,Cancel the execution of an asynchronous task
- –task-id,ID of the asynchronous task to cancel
- task-clear,Clean up completed asynchronous tasks
- –force,Optional. When set, it means to clean up all asynchronous tasks. Unfinished ones are canceled first, and then all asynchronous tasks are cleared. By default, only completed asynchronous tasks are cleaned up
3.5 Gremlin Type,gremlin-execute and gremlin-schedule
gremlin-execute, send Gremlin statements to HugeGraph-Server to execute query or modification operations, execute synchronously, and return results after completion
- –file or -f, specify the script file to execute, UTF-8 encoding, mutually exclusive with –script
- –script or -s, specifies the script string to execute, mutually exclusive with –file
- –aliases or -a, Gremlin alias settings, the format is: key1=value1,key2=value2,…
- –bindings or -b, Gremlin binding settings, the format is: key1=value1,key2=value2,…
- –language or -l, the language of the Gremlin script, the default is gremlin-groovy
–file and –script are mutually exclusive, one of them must be set
gremlin-schedule, send Gremlin statements to HugeGraph-Server to perform query or modification operations, asynchronous execution, and return the asynchronous task id immediately after the task is submitted
- –file or -f, specify the script file to execute, UTF-8 encoding, mutually exclusive with –script
- –script or -s, specifies the script string to execute, mutually exclusive with –file
- –bindings or -b, Gremlin binding settings, the format is: key1=value1,key2=value2,…
- –language or -l, the language of the Gremlin script, the default is gremlin-groovy
–file and –script are mutually exclusive, one of them must be set
3.6 Backup/Restore Type
- backup, back up the schema or data in a certain graph out of the HugeGraph system, and store it on the local disk or HDFS in the form of JSON
- –format, the backup format, optional values include [json, text], the default is json
- –all-properties, whether to back up all properties of vertices/edges, only valid when –format is text, default false
- –label, the type of vertices/edges to be backed up, only valid when –format is text, only valid when backing up vertices or edges
- –properties, properties of vertices/edges to be backed up, separated by commas, only valid when –format is text, valid only when backing up vertices or edges
- –compress, whether to compress data during backup, the default is true
- –directory or -d, the directory to store schema or data, the default is ‘./{graphName}’ for local directory, and ‘{fs.default.name}/{graphName}’ for HDFS
- –huge-types or -t, the data types to be backed up, separated by commas, the optional value is ‘all’ or a combination of one or more [vertex, edge, vertex_label, edge_label, property_key, index_label], ‘all’ Represents all 6 types, namely vertices, edges and all schemas
- –log or -l, specify the log directory, the default is the current directory
- –retry, specify the number of failed retries, the default is 3
- –split-size or -s, specifies the size of splitting vertices or edges when backing up, the default is 1048576
- -D, use the mode of -Dkey=value to specify dynamic parameters, and specify HDFS configuration items when backing up data to HDFS, for example: -Dfs.default.name=hdfs://localhost:9000
restore, restore schema or data stored in JSON format to a new graph (RESTORING mode) or merge into an existing graph (MERGING mode)
- –directory or -d, the directory to store schema or data, the default is ‘./{graphName}’ for local directory, and ‘{fs.default.name}/{graphName}’ for HDFS
- –clean, whether to delete the directory specified by –directory after the recovery map is completed, the default is false
- –huge-types or -t, data types to restore, separated by commas, optional value is ‘all’ or a combination of one or more [vertex, edge, vertex_label, edge_label, property_key, index_label], ‘all’ Represents all 6 types, namely vertices, edges and all schemas
- –log or -l, specify the log directory, the default is the current directory
- –retry, specify the number of failed retries, the default is 3
- -D, use the mode of -Dkey=value to specify dynamic parameters, which are used to specify HDFS configuration items when restoring graphs from HDFS, for example: -Dfs.default.name=hdfs://localhost:9000
restore command can be used only if –format is executed as backup for json
migrate, migrate the currently connected graph to another HugeGraphServer
- –target-graph, the name of the target graph, the default is hugegraph
- –target-url, the HugeGraphServer where the target graph is located, the default is http://127.0.0.1:8081
- –target-username, the username to access the target map
- –target-password, the password to access the target map
- –target-timeout, the timeout for accessing the target map
- –target-trust-store-file, access the truststore file used by the target graph
- –target-trust-store-password, the password to access the truststore used by the target map
- –directory or -d, during the migration process, the directory where the schema or data of the source graph is stored. For a local directory, the default is ‘./{graphName}’; for HDFS, the default is ‘{fs.default.name}/ {graphName}’
- –huge-types or -t, the data types to be migrated, separated by commas, the optional value is ‘all’ or a combination of one or more [vertex, edge, vertex_label, edge_label, property_key, index_label], ‘all’ Represents all 6 types, namely vertices, edges and all schemas
- –log or -l, specify the log directory, the default is the current directory
- –retry, specify the number of failed retries, the default is 3
- –split-size or -s, specify the size of the vertex or edge block when backing up the source graph during the migration process, the default is 1048576
- -D, use the mode of -Dkey=value to specify dynamic parameters, which are used to specify HDFS configuration items when the data needs to be backed up to HDFS during the migration process, for example: -Dfs.default.name=hdfs://localhost: 9000
- –graph-mode or -m, the mode to set the target graph when restoring the source graph to the target graph, legal values include [RESTORING, MERGING]
- –keep-local-data, whether to keep the backup of the source map generated in the process of migrating the map, the default is false, that is, the backup of the source map is not kept after the default migration map ends
- schedule-backup, periodically back up the graph and keep a certain number of the latest backups (currently only supports local file systems)
- –directory or -d, required, specifies the directory of the backup data
- –backup-num, optional, specifies the number of latest backups to save, defaults to 3
- –interval, an optional item, specifies the backup cycle, the format is the same as the Linux crontab format
- dump, export all the vertices and edges of the entire graph, and store them in
vertex vertex-edge1 vertex-edge2...JSON format by default. Users can also customize the storage format, just need to be inhugegraph-tools/src/main/java/com/baidu/hugegraph/formatterImplement a class inherited fromFormatterin the directory, such asCustomFormatter, and specify this class as formatter when using it, for examplebin/hugegraph dump -f CustomFormatter- –formatter or -f, specify the formatter to use, the default is JsonFormatter
- –directory or -d, the directory where schema or data is stored, the default is the current directory
- –log or -l, specify the log directory, the default is the current directory
- –retry, specify the number of failed retries, the default is 3
- –split-size or -s, specifies the size of splitting vertices or edges when backing up, the default is 1048576
- -D, use the mode of -Dkey=value to specify dynamic parameters, and specify HDFS configuration items when backing up data to HDFS, for example: -Dfs.default.name=hdfs://localhost:9000
3.7 Install the deployment type
- deploy, one-click download, install and start HugeGraph-Server and HugeGraph-Studio
- -v, required, specifies the version number of HugeGraph-Server and HugeGraph-Studio installed, the latest is 0.9
- -p, required, specifies the installed HugeGraph-Server and HugeGraph-Studio directories
- -u, optional, specifies the link to download the HugeGraph-Server and HugeGraph-Studio compressed packages
- clear, clean up HugeGraph-Server and HugeGraph-Studio directories and tarballs
- -p, required, specifies the directory of HugeGraph-Server and HugeGraph-Studio to be cleaned
- start-all, start HugeGraph-Server and HugeGraph-Studio with one click, and start monitoring, automatically pull up the service when the service dies
- -v, required, specifies the version number of HugeGraph-Server and HugeGraph-Studio to be started, the latest is 0.9
- -p, required, specifies the directory where HugeGraph-Server and HugeGraph-Studio are installed
- stop-all, close HugeGraph-Server and HugeGraph-Studio with one click
There 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
3.8 Specific command parameters
The specific parameters of each subcommand are as follows:
Usage: hugegraph [options] [command] [command options]Options:--graphName of graphDefault: hugegraph--passwordPassword of user--timeoutConnection timeoutDefault: 30--trust-store-fileThe path of client truststore file used when https protocol is enabled--trust-store-passwordThe password of the client truststore file used when the https protocolis enabled--urlThe URL of HugeGraph-ServerDefault: http://127.0.0.1:8080--userName of userCommands:graph-list List all graphsUsage: graph-listgraph-get Get graph infoUsage: graph-getgraph-clear Clear graph schema and dataUsage: graph-clear [options]Options:* --confirm-message, -cConfirm message of graph clear is "I'm sure to delete all data".(Note: include "")graph-mode-set Set graph modeUsage: graph-mode-set [options]Options:* --graph-mode, -mGraph mode, include: [NONE, RESTORING, MERGING]Possible Values: [NONE, RESTORING, MERGING, LOADING]graph-mode-get Get graph modeUsage: graph-mode-gettask-list List tasksUsage: task-list [options]Options:--limitLimit number, no limit if not providedDefault: -1--statusStatus of tasktask-get Get task infoUsage: task-get [options]Options:* --task-idTask idDefault: 0task-delete Delete taskUsage: task-delete [options]Options:* --task-idTask idDefault: 0task-cancel Cancel taskUsage: task-cancel [options]Options:* --task-idTask idDefault: 0task-clear Clear completed tasksUsage: task-clear [options]Options:--forceForce to clear all tasks, cancel all uncompleted tasks firstly,and delete all completed tasksDefault: falsegremlin-execute Execute Gremlin statementsUsage: gremlin-execute [options]Options:--aliases, -aGremlin aliases, valid format is: 'key1=value1,key2=value2...'Default: {}--bindings, -bGremlin bindings, valid format is: 'key1=value1,key2=value2...'Default: {}--file, -fGremlin Script file to be executed, UTF-8 encoded, exclusive to--script--language, -lGremlin script languageDefault: gremlin-groovy--script, -sGremlin script to be executed, exclusive to --filegremlin-schedule Execute Gremlin statements as asynchronous jobUsage: gremlin-schedule [options]Options:--bindings, -bGremlin bindings, valid format is: 'key1=value1,key2=value2...'Default: {}--file, -fGremlin Script file to be executed, UTF-8 encoded, exclusive to--script--language, -lGremlin script languageDefault: gremlin-groovy--script, -sGremlin script to be executed, exclusive to --filebackup Backup graph schema/data. If directory is on HDFS, use -D toset HDFS params. For exmaple:-Dfs.default.name=hdfs://localhost:9000Usage: backup [options]Options:--all-propertiesAll properties to be backup flagDefault: false--compresscompress flagDefault: true--directory, -dDirectory of graph schema/data, default is './{graphname}' inlocal file system or '{fs.default.name}/{graphname}' in HDFS--formatFile format, valid is [json, text]Default: json--huge-types, -tType of schema/data. Concat with ',' if more than one. 'all' meansall 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]--labelVertex or edge label, only valid when type is vertex or edge--log, -lDirectory of logDefault: ./logs--propertiesVertex or edge properties to backup, only valid when type isvertex or edgeDefault: []--retryRetry times, default is 3Default: 3--split-size, -sSplit size of shardDefault: 1048576-DHDFS config parametersSyntax: -Dkey=valueDefault: {}schedule-backup Schedule backup taskUsage: schedule-backup [options]Options:--backup-numThe number of latest backups to keepDefault: 3* --directory, -dThe directory of backups stored--intervalThe 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 allDefault: "0 0 * * *"dump Dump graph to filesUsage: dump [options]Options:--directory, -dDirectory of graph schema/data, default is './{graphname}' inlocal file system or '{fs.default.name}/{graphname}' in HDFS--formatter, -fFormatter to customize format of vertex/edgeDefault: JsonFormatter--log, -lDirectory of logDefault: ./logs--retryRetry times, default is 3Default: 3--split-size, -sSplit size of shardDefault: 1048576-DHDFS config parametersSyntax: -Dkey=valueDefault: {}restore Restore graph schema/data. If directory is on HDFS, use -D toset HDFS params if needed. Forexmaple:-Dfs.default.name=hdfs://localhost:9000Usage: restore [options]Options:--cleanWhether to remove the directory of graph data after restoredDefault: false--directory, -dDirectory of graph schema/data, default is './{graphname}' inlocal file system or '{fs.default.name}/{graphname}' in HDFS--huge-types, -tType of schema/data. Concat with ',' if more than one. 'all' meansall 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, -lDirectory of logDefault: ./logs--retryRetry times, default is 3Default: 3-DHDFS config parametersSyntax: -Dkey=valueDefault: {}migrate Migrate graphUsage: migrate [options]Options:--directory, -dDirectory of graph schema/data, default is './{graphname}' inlocal file system or '{fs.default.name}/{graphname}' in HDFS--graph-mode, -mMode used when migrating to target graph, include: [RESTORING,MERGING]Default: RESTORINGPossible Values: [NONE, RESTORING, MERGING, LOADING]--huge-types, -tType of schema/data. Concat with ',' if more than one. 'all' meansall 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-dataWhether to keep the local directory of graph data after restoredDefault: false--log, -lDirectory of logDefault: ./logs--retryRetry times, default is 3Default: 3--split-size, -sSplit size of shardDefault: 1048576--target-graphThe name of target graph to migrateDefault: hugegraph--target-passwordThe password of target graph to migrate--target-timeoutThe timeout to connect target graph to migrateDefault: 0--target-trust-store-fileThe trust store file of target graph to migrate--target-trust-store-passwordThe trust store password of target graph to migrate--target-urlThe url of target graph to migrateDefault: http://127.0.0.1:8081--target-userThe username of target graph to migrate-DHDFS config parametersSyntax: -Dkey=valueDefault: {}deploy Install HugeGraph-Server and HugeGraph-StudioUsage: deploy [options]Options:* -pInstall path of HugeGraph-Server and HugeGraph-Studio-uDownload url prefix path of HugeGraph-Server and HugeGraph-Studio* -vVersion of HugeGraph-Server and HugeGraph-Studiostart-all Start HugeGraph-Server and HugeGraph-StudioUsage: start-all [options]Options:* -pInstall path of HugeGraph-Server and HugeGraph-Studio* -vVersion of HugeGraph-Server and HugeGraph-Studioclear Clear HugeGraph-Server and HugeGraph-StudioUsage: clear [options]Options:* -pInstall path of HugeGraph-Server and HugeGraph-Studiostop-all Stop HugeGraph-Server and HugeGraph-StudioUsage: stop-allhelp Print usageUsage: help
3.9 Specific command example
1. gremlin statement
# 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()'
2. Show task status
./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
3. Set and show graph mode
./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
4. Cleanup Graph
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph graph-clear -c "I'm sure to delete all data"
5. Backup Graph
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph backup -t all --directory ./backup-test
6. Periodic Backup Graph
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph --interval */2 * * * * schedule-backup -d ./backup-0.10.2
7. Recovery Graph
# 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
8. Graph Migration
./bin/hugegraph --url http://127.0.0.1:8080 --graph hugegraph migrate --target-url http://127.0.0.1:8090 --target-graph hugegraph
Last modified October 9, 2023: doc: enhance a string of problems to improve UE (#288) (69c20091)