Docker maintenance operations

This chapter describes some basic maintenance operations when running Neo4j in a Docker container.

This section covers the following:

1. Dump and load a Neo4j database (offline)

The Neo4j dump and load commands can be run locally to dump and load an offline database.

The following are examples of how to dump and load the default neo4j database. Because these commands are run on a stopped database, you have to launch two containers for each operation (dump and load), with the --rm flag.

Example 1. Invoke neo4j-admin dump to dump your database.
docker run --interactive --tty --rm \
   --publish=7474:7474 --publish=7687:7687 \
   --volume=$HOME/neo4j/data:/data \  (1)
   --volume=$HOME/neo4j/backups:/backups \  (2)
   --user="$(id -u):$(id -g)" \
   neo4j:{neo4j-version} \
neo4j-admin dump --database=neo4j --to=/backups/<dump-name>.dump
1 The volume that contains the database that you want to dump.
2 The volume that will be used for the dumped database.
Example 2. Invoke neo4j-admin load to load your data into the new database.
docker run --interactive --tty --rm \
    --publish=7474:7474 --publish=7687:7687 \
    --volume=$HOME/neo4j/data:/data \ (1)
    --volume=$HOME/neo4j/backups:/backups \ (2)
    --user="$(id -u):$(id -g)" \
    neo4j:{neo4j-version} \
neo4j-admin load --from=/backups/<dump-name>.dump --database=neo4j --force
1 The volume that contains the database, into which you want to load the dumped data.
2 The volume that stores the database dump.

Finally, you launch a container with the volume that contains the newly loaded database, and start using it.

For more information on the neo4j-admin dump and load syntax and options, see Dump and load databases.
For more information on managing volumes, see the official Docker documentation.

2. Back up and restore a Neo4j database (online)

The Neo4j backup and restore commands can be run locally to backup and restore a live database.

2.1. Back up a database

The following are examples of how to back up a database.

Example 3. A docker run command that creates a container to be used for backing up an online database.
docker run --name <container name> \
    --detach \
    --publish=7474:7474 --publish=7687:7687 \
    --volume=$HOME/neo4j-enterprise/data:/data \ (1)
    --volume=$HOME/neo4j-enterprise/backups:/backups \ (2)
    --user="$(id -u):$(id -g)" \
    --env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \ (3)
    --env NEO4J_dbms_backup_enabled=true \ (4)
    neo4j:{neo4j-version}-enterprise
1 The volume that contains the database that you want to back up.
2 The volume that will be used for the database backup.
3 The environment variable that states that you have accepted the Neo4j Enterprise Edition license agreement.
4 The environment variable that enables online backups.
Example 4. Invoke neo4j-admin backup to back up an online database.
docker exec --interactive --tty <container name> neo4j-admin backup --backup-dir=/backups --database=<database name>
For more information on the neo4j-admin backup syntax and options, see Perform a backup.

2.2. Restore a database

The following are examples of how to restore a database backup on a stopped database in a running Neo4j instance.

Example 5. A docker run command that creates a container to be used for restoring a database backup.
docker run --name <container name> \
    --detach \
    --publish=7474:7474 --publish=7687:7687 \
    --volume=$HOME/neo4j-enterprise/data:/data \ (1)
    --volume=$HOME/neo4j-enterprise/backups:/backups \ (2)
    --user="$(id -u):$(id -g)" \
    --env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \ (3)
    neo4j:{neo4j-version}-enterprise
1 The volume that contains all your databases.
2 The volume that contains the database backup.
3 The environment variable that states that you have accepted the Neo4j Enterprise Edition license agreement.
Example 6. Invoke cypher-shell to stop the database that you want to use for the backup restore.
docker exec -it <containerID/name> cypher-shell -u neo4j -p <my-password> -d system "stop database <database name>;"
Example 7. Invoke neo4j-admin restore to restore a database backup.
docker exec --interactive --tty <containerID/name> neo4j-admin restore --from=/backups/<database backup name> --database=<database name>
For more information on the neo4j-admin restore syntax and options, see Restore a backup.

Finally, you can use the Cypher Shell tool to verify that your data has been restored.

3. Upgrade Neo4j on Docker

The following is an example of a docker run command that launches a container and upgrades a Neo4j database stored in a Docker volume or a host folder.

docker run \
    --publish=7474:7474 --publish=7687:7687 \
    --volume=$HOME/neo4j/data:/data \ (1)
    --env dbms_allow__upgrade=true \ (2)
    neo4j:{neo4j-version} \(3)
1 The volume that contains the database that you want to upgrade.
2 The environment variable that enables the upgrade.
3 The new version of the Neo4j Docker image to which you want to upgrade your database.

For more details on upgrading, see: