Oftentimes you want to export a full (or partial) database to a file and import it again without copying the actual database files.
If you want to do the latter, use
Here are two ways on how to create a Cypher script file from your database or Cypher statement.
Some notes on the format written from these tools:
- recreate indexes and constraints
- simple statements per node (CREATE) / relationship (2x MATCH + CREATE)
data creation in batches (by default 40k) surrounded with
- uses existing constraints for node-lookup
if no constraint on that label exist, use an artificial constraint + property (
UNIQUE IMPORT LABEL.
UNIQUE IMPORT ID) where the property value is the node-id, on node creation
- clean up artificial label + property + constraint at the end in batches
You can install the APOC procedure library.
And then use the
apoc.export.cypher.* procedures to create the
export.cypher file from your graph or data.
There is more in the documentation but below are some examples.
Please note that you have to enable the capability to write to files first in
Install neo4j-shell-tools into your
Enable remote shell in your
./bin/neo4j-shell -path data/databases/graph.db when your server is not running.
Run the command
export-cypher -o export.cypher;
export-cypher -o export.cypher MATCH (p1:Person)-[r:KNOWS]→(p:Person) RETURN *;
Import with cypher-shell
If you edit the file to replace
then you can import them with
export.cypher | sed -e 's/^(begin|commit)/:$1/g' ./bin/cypher-shell -u user -p password
Import with neo4j-shell
You can import files generated by these exports with
./bin/neo4j-shell -file export.cypher