Backup Neo4j - Community Edition (Plain Linux and Docker)

Backing up data is crucial - also for NoSQL databases such as Neo4j graph db. Here are some hints on how to properly proceed for taking consistent backups for both Community and Enterprise Edition.

Enterprise Edition

Only Neo4j's Enterprise Edition provides a dedicated tool neo4j-backup for consistent and (consistency checked) backups while Neo4j is running.

Please refer to Neo4j's online documentation for detailed instructions:

Neo4j Operations Manual: https://neo4j.com/docs/operations-manual/current/backup/

Community Edition

In community edition however it takes the following steps for creating a backup:

  1. Shutdown Neo4j.
  2. Copy (via tar or rsync) graph.db folder
  3. Restart Neo4j

For restoring this backup:

  1. Shutdown Neo4j
  2. Remove the existing graph.db folder
  3. Copy (via tar or rsync) the backup graph.db folder to new location
  4. Restart Neo4j

Note: If using rsync ownership will be mapped to the user running rsync.

Plain Linux

The following steps are based on Stefan Armbruster's recommendation on stack overflow and have been adapted to Neo4j's current folder structure:

Stack Overflow: http://stackoverflow.com/questions/25567744/backup-neo4j-community-edition-offline-in-unix-mac-or-linux

Creating the backup:

After shutting down Neo4j just do:

cd data/databases

tar -zcf graph.db.tar.gz graph.db/

After these tasks have completed restart Neo4j.

Restoring the backup:

After shutting down Neo4j just do:

cd data/databases

rm -rf graph.db

tar -zxf graph.db.tar.gz

After these tasks have completed restart Neo4j.

Note: This will only backup and restore payload data (and not e.g. user and authentication data which currently resides in the data/dbms folder).

Docker Container

The following steps are based on Docker's tutorial on Docker Volumes and have been adapted to Neo4j's official Docker image (with its /data volume) and to host binds (-v instead of a data volume container).

Docker Docs: https://docs.docker.com/engine/tutorials/dockervolumes/#/backup-restore-or-migrate-data-volumes

Creating the backup:

After stopping the Neo4j container just do:

docker run --rm --volumes-from <neo4j_container_name> -v $(pwd):/backup debian:jessie tar cvf /backup/backup.tar /data

After this task has completed restart the Neo4j container.

Restoring the backup:

After stopping the Neo4j container just do:

docker run --rm -v $(pwd):/backup -v <new_neo4j_host_bind>:/data debian:jessie bash -c "cd /data && tar xvf /backup/backup.tar --strip 1"

You can check if the data has successfully been copied to the new host bind by:

docker run --rm -v <new_neo4j_host_bind>:/data debian:jessie bash -c "ls /data"

After this task has completed and checking the data restart the Neo4j container.

Note: This will also backup and restore all data (e.g. also user and authentication data) and not only payload data.