6.1. Backup

6.1.1. How to make backups in embedded mode

Neo4j makes incremental backups using the transaction logs. You have to prepare the database by copying the current database. Once the database is copied, the transactions in the log will be applied to the backup database, to keep them in sync.

6.1.1. How to make backups in embedded mode

First off, make sure that your database is configured to the keep logical logs around, like this:

keep_logical_logs=true 

See Chapter 2, Configuration & Performance for information on how you can give the database its settings.

[Warning]Warning

If you want to do incremental backups, you need to do make sure that the logical logs are kept anytime you modify data or start up the database. Otherwise your incremental backups might not work properly.

Shut down the Neo4j database and copy its files to the backup location. Once this has been prepared, backups can be run by executing the following Java statements:

Java code to perform backup. 

EmbeddedGraphDatabase graphDb = getTheGraphDbFromApp();
String location = "/var/backup/neo4j-db";
Backup backup = Neo4jBackup.allDataSources( graphDb, location );
backup.doBackup();

[Tip]Tip

A ZFS snapshot can be used instead of having to shut down the database to copy the files when preparing the database for backups.