Restore a backup

How to restore from backups of a Neo4j deployment.

1. Restore command

A Neo4j database can be restored using the restore command of neo4j-admin.

Restoring a database does not automatically cause it to be created by the Neo4j DBMS.

That configuration lives in the system database and if a backup of the system database is restored, then any configuration for other databases in it will also be restored. If the restored database has not been created yet, use the CREATE DATABASE command after restoring, to create it. See Administrative commands for more information.

If you have backed up database which includes --include-metadata, you will need to restore users and roles metadata manually on the core member. To do this you need to run data/scripts/databasename/restore_metadata.cypher using Cypher Shell:

Using cat (UNIX)

$neo4j-home> cat data/scripts/databasename/restore_metadata.cypher | ./cypher-shell -u user -p password -a core_member -d system --param "database => 'databasename'"

Using type (Windows)

$neo4j-home> type data\scripts\databasename\restore_metadata.cypher | bin\cypher-shell.bat -u user -p password -a core_member -d system --param "database => 'databasename'"

For more information, see Cypher Shell.

Syntax

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

Options

Option Default Description

--from

Path, or paths, from which to restore.

Every path can contain asterisks or question marks in the last subpath. Multiple paths may be separated by a comma, but paths themselves must not contain commas.

--verbose

false

Enable verbose output.

--database

Name of the database after restore.

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

--force

If an existing database should be replaced.

--move

Moves 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 exact one directory.

--to-data-tx-directory

Base directory for transaction logs.

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

2. Restore a standalone server

To restore from backups, follow these steps:

  1. If the server is running, shut it down.

  2. Run neo4j-admin restore for every database.

  3. Start up the server.

Example 1. Restore a standalone server

Restore the databases system and neo4j from the backups located in /mnt/backups.

neo4j-home> bin/neo4j stop
neo4j-home> bin/neo4j-admin restore --from=/mnt/backups/system --database=system --force
neo4j-home> bin/neo4j-admin restore --from=/mnt/backups/neo4j --database=neo4j --force
neo4j-home> bin/neo4j start

3. Restore a cluster

To restore a Causal Cluster from backups, follow these steps:

  1. Shut down all server instances in the cluster.

  2. Run the neo4j-admin unbind command on each of the Core Servers.

  3. Restore the backups on each instance, using neo4j-admin restore.

  4. If you are restoring onto new hardware, please review the Causal Clustering settings in neo4j.conf.

  5. Start the server instances.

Refer to Seed a cluster for more detailed information.

When restoring a backup on a Core Server where a database of the same name already exists, you must execute DROP DATABASE first. If you are unable to (e.g. because Neo4j is not running), you must run neo4j-admin unbind first instead. If you fail to do this, the store files you have (post restore) will be out of sync with the cluster state you have for that database, leading to logical corruption.