Neo4j - Database Backup and Restore



In Real-time applications, we should take backup of our application Database regularly so that we can restore to some working condition at any failure point.

This rule is applicable for both RDBMS and No SQL databases.

In this section, we are going to discuss about two important DBA tasks.

  • How to backup a Neo4j Database.
  • How to restore Neo4j Database to a specific backup.

NOTE:-

These steps are applicable to Windows Operating System only. We should use similar kind of commands to do the same steps in other Operating Systems.

Neo4j Database Backup

Step 1 - Click on "Neo4j Community" as shown below

Windows "Start" button >> "All Programs" >> "Neo4j Community" >> "Neo4j Community"

By default, it selects c:\Users\[username]\Documents\Neo4j\default.graphdb. If you want, you can change your path to different directory. Here we have changed to our Neo4j Database folder

C:\Ne04j2.0db

Neo4j CQL Tutorial

Click on "Start" button.

Neo4j CQL Tutorial

Once the server is started, we can observe our Neo4j Database files are generated at specified directory

Neo4j CQL Tutorial

Before taking Database backup, first and foremost thing we should do is shutdown the Neo4j Database server.

Click on "Stop" Button to shutdown the server

Neo4j CQL Tutorial

Step 2 - Our Neo4j Database files are available at C:\Ne04j2.0db

Neo4j CQL Tutorial

Step 3 - Open command prompt

Neo4j CQL Tutorial

Step 4 - Create a folder "Neo4jDbBackup-01" at C:\Neo4j ( This may be any location in your file system)

mkdir C:\Neo4j\Neo4jDbBackup-01
Neo4j CQL Tutorial

It creates a new folder "Neo4jDbBackup-01" at specified file system location "C:\Neo4j\"

Neo4j CQL Tutorial

Step 5 - Type the below command and press Enter key

copy C:\Ne04j2.0db C:\Neo4j\Neo4jDbBackup-01
Neo4j CQL Tutorial
Neo4j CQL Tutorial

That means our files are copied to required destination folder. Access that folder and observe that folder has our database files.

Neo4j CQL Tutorial

Step 6 - Use any Windows compression/decompression tool like WinZip, 7 Zip, or WinRar to zip our Database folder.

Neo4j CQL Tutorial

Now our Neo4jDbBackup-01.zip file is created. If you have any memory constraints in your file system, then remove "Neo4jDbBackup-01" folder at "C:\Neo4j\"

Neo4j CQL Tutorial

Neo4j Database Restore

Step 1 - Shutdown the database server. Please refer previous steps to shutdown the server.

Neo4j CQL Tutorial

Step 2 - Empty the current database folder

Neo4j CQL Tutorial

Step 3 - Use any Windows compression/decompression tool like WinZip, 7 Zip, or WinRar to unzip our backup folder.

Neo4j CQL Tutorial

Step 4 - Open command prompt and execute the following command

Copy C:\Neo4j\Neo4jDbBackup-01 C:\Ne04j2.0db
Neo4j CQL Tutorial

Step 5 - Now we can observe that our database folder contains working backup files

Step 6 - Start the server by clicking on "Start" button.

Neo4j CQL Tutorial
Neo4j CQL Tutorial

Now execute some MATCH + RETURN commands to verify whether we have restored our database properly or not

Advertisements