Neo4j Admin and Neo4j CLI

Introduction

neo4j-admin and neo4j are command-line tools for managing and administering a Neo4j DBMS. Both are installed as part of the product and can be executed with a number of commands. The neo4j commands are equivalent to the most important commands in the neo4j-admin server category.

Both neo4j-admin and neo4j commands support the --help option, which prints the command’s usage and options, and the --version option, which prints the version of the command. All admin command options can also be provided in a file and passed to the command using the @ prefix. This is useful when the command line becomes too long to manage. For example, neo4j-admin database import full @/path/to/your/<args-filename> mydb. For more information, see Picocli → AtFiles official documentation.

All admin commands must be invoked with the same user as Neo4j runs as. This guarantees that Neo4j will have full rights to start and work with the database files you use.

The neo4j-admin tool

The neo4j-admin command-line tool is located in the bin directory.

General synopsis

neo4j-admin has the following general synopsis:

neo4j-admin [category] [command] [subcommand]

neo4j-admin commands per category

All administration commands, except for help and version, are organized into the following three categories:

  • dbms - DBMS-wide (for single and clustered environments) administration tasks

  • server - server-wide administration tasks

  • database - database-specific administration tasks

Table 1. Available commands per category
Category Command Description

dbms

set-default-admin

Sets the default admin user when no roles are present.

set-initial-password

Sets the initial password of the initial admin user (neo4j).

For details, see Set an initial password.

unbind-system-db

Removes and archives the cluster state of the system database so the instance can rebind to a new cluster state of the system database.

server

console

Starts DBMS server in the console.

get-id

Displays the server ID of an instance. The server ID can be used to specify a server in Cypher commands.

license

Accept the license agreement.

memory-recommendation

Prints recommendations for Neo4j heap and page cache memory usage.

For details, see Memory recommendations.

migrate-configuration

Migrates server configuration from the previous major version.

report

Produces a ZIP/TAR of the most common information needed for remote assessments.

For details, see Neo4j Admin report.

restart

Restarts the server daemon.

start

Starts the server as a daemon.

status

Gets the status of the server.

stop

Stops the server daemon.

unbind

Removes cluster state data from a stopped Neo4j server.

For details, see Unbind a Neo4j cluster server.

validate-config

Performs configuration validation without starting the server.

windows-service

A command whose subcommands can be used to install, uninstall, and update Neo4j as a Windows service.

database

aggregate-backup

Aggregates a chain of backup artifacts into a single artifact.

backup

Performs an online backup from a running Neo4j enterprise server.

check

Checks the consistency of a database.

For details, see Consistency checker.

copy

Copies a database and optionally applies filters.

For details, see Copy a database store.

dump

Dumps a database into a single-file archive.

import

Imports a collection of CSV files.

For details, see Import.

info

Prints information about a Neo4j database store.

For details, see Display store information.

load

Loads a database from an archive created with the dump command.

migrate

Migrates a database from one store format to another or between versions of the same format.

restore

Restores a backed up database.

upload

Pushes a local database to a Neo4j Aura instance.

For details, see Upload to Neo4j AuraDB.

The neo4j tool

The neo4j command-line tool is located in the bin directory.

General synopsis

neo4j has the following general synopsis:

neo4j [command]

neo4j commands

The command is an alias for the most important commands in the neo4j-admin server category.

Table 2. Equivalence between neo4j and neo4j-admin commands
neo4j command Equivalent neo4j-admin command

neo4j console

neo4j-admin server console

neo4j restart

neo4j-admin server restart

neo4j start

neo4j-admin server start

neo4j status

neo4j-admin server status

neo4j stop

neo4j-admin server stop

neo4j windows-service

neo4j-admin server windows-service

Version command

Version can be obtained by invoking the version command, --version command option, or its short alternative -V, on the root level of both neo4j and neo4j-admin commands. For example, neo4j --version, neo4j-admin -V, neo4j-admin version, or neo4j version.

Help command

Help can be obtained by invoking the help command, --help command option, or its short alternative -h, with both neo4j and neo4j-admin commands. --help and -h options can be invoked on any level, namely root, category, command, and subcommand. For example, neo4j --help, neo4j [command] -h, neo4j-admin -h, neo4j-admin [category] --help, or neo4j-admin [category] [command] [subcommand] -h.

The help command can be invoked on any level except the last one, which means command-level for commands that do not have subcommands or subcommand level for commands with subcommands. The help command also accepts a parameter. For example, neo4j help, neo4j-admin help, neo4j-admin [category] help, neo4j-admin help [category], neo4j help [command], or neo4j-admin [category] [command ] help [subcommand].

Limitations

When using both a multi-value option and a positional parameter, the multi-value option is "greedy" and pulls in the next positional parameter via its convertor. This is a limitation of the underlying library, Picocli, and is not specific to Neo4j Admin. See Picocli → Variable Arity Options and Positional Parameters official documentation for more information.

Configuration

Administration operations use the configuration specified in the neo4j.conf file. Sharing configuration between the DBMS and its administration tasks makes sense as most settings are the same. In some cases, however, it is better to override some settings specified in neo4j.conf by configuring the tasks (instead of updating the config settings in the neo4j.conf file) because administration tasks generally use fewer resources than the DBMS. For instance, if the page cache of your DBMS is configured to a very high value in neo4j.conf, and you want to override this because the admin tasks like backup do not need so much memory, you provide configuration for the admin tasks instead of updating the page cache setting in the neo4j.conf file.

There are several options for overriding settings specified in the neo4j.conf file using administration tasks:

  • --additional-config option — almost all administration commands support the --additional-config option, which you can use to provide a path to a file with additional configuration.

  • neo4j-admin.conf — a configuration file located in the same directory as the neo4j.conf file, which you can use to provide administration-task-specific settings.

  • Some commands also support a command-specific configuration file. Such files are also looked for in the same directory as the neo4j.conf file. The following table lists command-specific configuration files:

    Table 3. Command-specific configuration files
    Command Configuration file

    neo4j-admin database backup

    neo4j-admin-database-backup.conf

    neo4j-admin database check

    neo4j-admin-database-check.conf

    neo4j-admin database copy

    neo4j-admin-database-copy.conf

    neo4j-admin database dump

    neo4j-admin-database-dump.conf

    neo4j-admin database import

    neo4j-admin-database-import.conf

    neo4j-admin database load

    neo4j-admin-database-load.conf

    neo4j-admin database migrate

    neo4j-admin-database-migrate.conf

    neo4j-admin database restore

    neo4j-admin-database-restore.conf

All four configuration sources are optional and settings for administration commands are resolved from them with the following descending priority:

  1. --additional-config option

  2. command-specific configuration file

  3. neo4j-admin.conf

  4. neo4j.conf

The commands for launching the DBMS, neo4j start and neo4j console, must be configured only in the neo4j.conf file.

Environment variables

Neo4j Admin can also use the following environment variables:

Environment variable Description

NEO4J_DEBUG

Set to anything to enable debug output.

NEO4J_HOME

Neo4j home directory.

NEO4J_CONF

Path to the directory that contains neo4j.conf.

HEAP_SIZE

Set JVM maximum heap size during command execution. Takes a number and a unit, for example, 512m.

JAVA_OPTS

Additional JVM arguments.

If set, HEAP_SIZE and JAVA_OPTS override all relevant settings specified in the configuration file.

Exit codes

When neo4j and neo4j-admin finish as expected, they exit with code 0. A non-zero exit code means something undesired happened during command execution.

Table 4. Exit codes
Exit code Description

0

Successful execution.

1

The command failed to execute.

3

The command failed to execute because the database is not running.

64

The command was invoked with incorrect options/parameters. See the printed usage for details.

70

An exception was thrown, not handled otherwise.

The non-zero exit code can contain further information about the error, for example, see the backup command’s exit codes.

Command-line completion

From 5.4 onwards, Neo4j supports command-line completion.

  • For Unix-based systems, the tab completion applies to the neo4j and neo4j-admin command line interfaces in terminals such as Bash and ZSH.

  • For RPM and DEB packaged installations, the necessary files are automatically installed in bash-completion.

  • For tarball installations, the files are located in the bin/completion/ directory with detailed instructions for manual installation.