Is there a tool to dump a Neo4j graph as Cypher and re-load it from Cypher?
Asked Answered
C

3

9

Everyone familiar with MySQL has likely used the mysqldump command which can generate a file of SQL statements representing both the schema and data in a MySQL database. These SQL text files are commonly used for many purposes: backups, seeding replicas, copying databases between installations (- copy prod DBs to staging environments etc) and others.

Is there a similar tool for Neo4j that can dump an entire graph into a text file of Cypher statements, that when executed on an empty database would reconstruct the original data?

Thanks.

Creight answered 26/7, 2013 at 1:47 Comment(0)
O
16

In neo4j version 2 (e.g. 2.0.0M3), using neo4j-shell, you can use the command

dump

which will create the cypher statements (pretty much like mysqldump would do. To read in the file you can use

cat dump.cql | neo4j-shell

Organelle answered 26/7, 2013 at 12:26 Comment(3)
This work, but it is very slow. Is there a way to make the cypher creation much faster?Dybbuk
It's in one transaction? Why size of my db is not increasing?Sidewalk
QueryExecutionKernelException: Invalid input 'c': expected whitespace, comment, ';' or end of input (line 2, column 1 (offset: 60)) "create constraint on (n:target) assert n.type is unique" ^Spiculate
M
5

Cypher is just a query language for Neo4J just as SQL is for MySQL or other relational databases. If you wish to transfer the db, then you just need to copy the folder containing the database files. Simple.

For example my folder simple-graph contains all the db files. Just copy the folder and store it at some other location. You can directly start using it as:

GraphDatabaseServiceraphDb = new EmbeddedGraphDatabase(DB_PATH);//DB_PATH is path to the new location
Maui answered 26/7, 2013 at 11:7 Comment(0)
B
1

You can use the procedure apoc.export.cypher.all() to dump all the data in your database.

For example, you can dump the database into a single file called dump-file.cypher:

neo4j@neo4j> CALL apoc.export.cypher.all('dump-file.cypher');

For details of the procedure, please see the documentation: https://neo4j.com/labs/apoc/4.4/overview/apoc.export/apoc.export.cypher.all/.

Baresark answered 3/8, 2022 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.