0

I have a backup copy of my Neo4j database deployed alongside my regular database. I'd like to restore data from the backup database that I am able to retrieve with a cypher query. Is there an easy way to export that data from my backup and have it replace the corresponding fields in the current database?

I can export the results of the query as JSON or CSV easily from the web GUI for neo4j, but I'm not sure how to upload the results back into my main database.

There are similar questions to this for SQL but I have not been able to find out how to do it in neo4j.

Community
  • 1
  • 1
jkeuhlen
  • 4,401
  • 23
  • 36

2 Answers2

0

If you're on neo4j 3.0 you can install the apoc library. It has an apoc.export.cypherQuery() procedure which stores the result of an cypher query as "create" commands in the specified file.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
0

As Stefan pointed out in the comments, neo4j-shell has a dump command that recreates the output of a cypher query as a series of creation statements that allow you to rebuild a subgraph from the ground up.

For my case,

  1. Ensure both databases are offline (may not be necessary for enterprise edition)
  2. From the bin directory in neo4j run ./neo4j-shell -path /path/to/neo4j-1/data/graph.db/ -c 'dump CYPHER QUERY HERE;' | ./neo4j-shell -path /path/to/neo4j-2/data/graph.db/ -file -
  3. Turn the database servers back online.

This will get a single query from your old database located in neo4j-1 into the newer copy at neo4j-2.

jkeuhlen
  • 4,401
  • 23
  • 36