26.2. Performing Backups

[Tip]Tip

When using Neo4j in embedded mode, the way to perform backup is still the same.

Backup Commands

# Performing a full backup: create a blank directory and run the backup tool
mkdir /mnt/backup/neo4j-backup
./bin/neo4j-backup -host 192.168.1.34 -to /mnt/backup/neo4j-backup

# Performing an incremental backup: just specify the location of your previous backup
./bin/neo4j-backup -host 192.168.1.34 -to /mnt/backup/neo4j-backup

# Performing an incremental backup where the service is listening on a non-default port
./bin/neo4j-backup -host 192.168.1.34 -port 9999 -to /mnt/backup/neo4j-backup

Incremental Backups

An incremental backup is performed whenever an existing backup directory is specified. The backup tool will then copy any new transactions from the Neo4j server and apply them to the backup. The result will be an updated backup that is consistent with the current server state.

However, the incremental backup may fail for a number of reasons:

  • If the existing directory doesn’t contain a valid backup.
  • If the existing directory contains a backup of a different database store.
  • If the existing directory contains a backup from a previous database version.
[Note]Note

Note that when copying the outstanding transactions, the backup tool needs access to the historical logical logs. These logical logs are kept by Neo4j and automatically removed after a period of time, based on the dbms.tx_log.rotation.retention_policy configuration. If the required logical logs have already been removed, the backup tool will do a full backup instead.

Online Backup from Java

In order to programmatically backup your data full or subsequently incremental from a JVM based program, you need to write Java code like the following:

OnlineBackup backup = OnlineBackup.from( "127.0.0.1" );
backup.full( backupPath.getPath() );
assertTrue( "Should be consistent", backup.isConsistent() );
backup.incremental( backupPath.getPath() );

For more information, please see the Javadocs for OnlineBackup.