Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup neo4j community edition offline in unix: mac or linux

Previously I had a problem when making a 'backup' as shown in this question where I get an error when trying to restore the database because I did a copy when the database was running.

So I did an experiment with a new database from another computer (this time with ubuntu) I tried this:

  • I created some nodes and relations, very few like 10 (the matrix example).
  • Then I stopped the service neo4j
  • I copied the folder data that contains graph.db to another location
  • After that I deleted the graph.db folder and started neo4j
  • It created automatically a new graph.db folder and the database runs as new without any data, that is normal.
  • Then I stopped again and paste the old graph.db folder

I get an error:

 Starting Neo4j Server...WARNING: not changing user waiting 
 for server to be ready... Failed to start within 120 seconds.

The error appears after 5 seconds not after 120 seconds.

  • I tried pasting the folder called data. Same error.

How should I backup and restore in neo4j community offline manually?

I read in some posts that you only copy and restore but that does not work.

Thank you for your help

like image 391
perseus Avatar asked Aug 29 '14 11:08

perseus


People also ask

How to take backup of neo4j database?

Command. A Neo4j database can be backed up in online mode using the backup command of neo4j-admin . The command must be invoked as the neo4j user to ensure the appropriate file permissions.

What is a neo4j dump?

The neo4j-admin dump command can be used for performing a full backup of an offline database. It dumps a database into a single-file archive, called <database>. dump. Alternatively, neo4j-admin dump can stream dump to standard output, enabling the output to be piped to another program, for example to neo4j-admin load .


2 Answers

Online backup, in a sense of taking a consistent backup while Neo4j is running, is only available in Neo4j enterprise edition. Enterprise edition's backup also features a verbose consistency check of the backup, something you do not get in community either.

The only safe option in community edition is to shutdown Neo4j cleanly and copy away the graph.db folder recursively. I'm typically using:

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

For restoring you shut down neo4j, clean out a existing graph.db folder and restore the original graph.db folder from your backup:

cd data
rm -rf graph.db
tar -zxf graph.db.tar.gz
like image 124
Stefan Armbruster Avatar answered Oct 01 '22 18:10

Stefan Armbruster


I also ran into this issue and wrote following two codes:

Make backup of momentary state

service neo4j stop && now=$(date +"%m_%d_%Y") && cd /var/lib/neo4j/data/databases/ && tar -cvzf /var/backups/neo4j/$now.gb.tar.gz graph.db && service neo4j start

  • service neo4j stop = stop the neo4j service
  • now=$(date +"%m_%d_%Y") = declare the current date as variable
  • cd /var/lib/neo4j/data/databases/ = change directories to your neo4j dir where the graph.db is located
  • tar -cvzf /var/backups/neo4j/$now.gb.tar.gz graph.db = make a compressed copy of the graph.db and save it to /var/backups/neo4j/$now.gb.tar.gz
  • service neo4j start = restart neo4j

Restore neo4j database from a backup

service neo4j stop && cd /var/lib/neo4j/data/databases/ && rm -r graph.db && tar xf /var/backups/neo4j/10_25_2016.gb.tar.gz -C /var/lib/neo4j/data/databases/ && service neo4j start

  • service neo4j stop = stop the neo4j service
  • cd /var/lib/neo4j/data/databases/ = change directories to your neo4j dir where the graph.db is located
  • rm -r graph.db = remove the current graph.db and all its contents
  • tar xf /var/backups/neo4j/10_25_2016.gb.tar.gz -C /var/lib/neo4j/data/databases/ = Extract the backup to the directory where the old graph.db was located. Be sure to adjust the filename 10_25_2016.gb.tar.gz to what you called your file
  • service neo4j start = restart neo4j

Info: This seems to work for me but as I do not have alot of experience with bash scripting I doubt this is the optimal way. But I think it is understandable and easy to customize :)

Cheers

like image 23
Mfbaer Avatar answered Oct 01 '22 18:10

Mfbaer