Restore a database backup

This section describes how to restore a database backup in a live Neo4j deployment.

1. Command

A database backup can be restored using the restore command of neo4j-admin. You must create the database (using CREATE DATABASE against the system database) after the restore operation finishes, unless you are replacing an existing database. neo4j-admin restore must be invoked as the neo4j user to ensure the appropriate file permissions.

For more information, see Administrative commands.

1.1. Syntax

neo4j-admin restore  --from=<path>[,<path>...]
                    [--verbose]
                    [--database=<database>]
                    [--force]
                    [--move]
                    [--to-data-directory=<path>]
                    [--to-data-tx-directory=<path>]

1.2. Options

Option Default Description

--from

Path or paths to the database backup that is going to be restored. Every path may contain asterisks or question marks in the last subpath. Multiple paths can be separated by a comma, but paths themselves must not contain commas.

--verbose

Enable verbose output.

--database

neo4j

Name for the restored database.

--force

Replace an existing database.

--move

Move the backup files to the destination, rather than copying.

--to-data-directory

Base directory for databases. Usage of this option is only allowed if the --from parameter points to one directory.

--to-data-tx-directory

Base directory for transaction logs. Usage of this option is only allowed if the --from parameter points to one directory.

2. Example

The following is an example of how to perform an online restore of the database backup created in the section Back up an online database, using the neo4j-admin restore command.

bin/neo4j-admin restore --from=/mnt/backups/neo4j --database=neo4j --force

Unless you are replacing an existing database, you must create the database (using CREATE DATABASE against the system database) after the restore operation finishes.

If you have backed up a database with the option --include-metadata, you have to restore the users and roles metadata manually.

From the <neo4j-home> directory, you run the Cypher script data/scripts/databasename/restore_metadata.cypher, which the neo4j-admin restore command outputs, using Cypher Shell:

Using cat (UNIX)

cat data/scripts/databasename/restore_metadata.cypher | bin/cypher-shell -u user -p password -a ip_address:port -d system --param "database => 'databasename'"

Using type (Windows)

type data\scripts\databasename\restore_metadata.cypher | bin\cypher-shell.bat -u user -p password -a ip_address:port -d system --param "database => 'databasename'"

For a detailed example on how to back up and restore a database in a Causal cluster, see Back up and restore a database in Causal Cluster.