Backup and Restore

This feature is not available in AuraDS

This feature is in the alpha tier. For more information on feature tiers, see Operations reference.

In the Neo4j Graph Data Science library, graphs and machine learning models are stored in-memory. This is necessary mainly for performance reasons but has the disadvantage that data will be lost after shutting down the database. There are already concepts to circumvent this limitation, such as running algorithms in write mode, exporting graphs to csv or storing models. The back-up and restore procedures described in this section will provide a simple and uniform way of saving graphs and models in order to load them back into memory after a database restart.

The gds.export.location parameter must be configured for this feature.

1. Syntax

Back-up in-memory graphs and models
CALL gds.alpha.backup(configuration: Map)
YIELD
  backupId: String,
  backupTime: LocalDateTime,
  exportMillis: Long
Table 1. Parameters
Name Type Optional Description

configuration

Map

yes

Additional parameters to configure the backup.

Table 2. Configuration
Name Type Default Description

concurrency

Integer

4

The number of concurrent threads used for performing the backup.

Table 3. Results
Name Type Description

graphName

String

The name of the persisted graph or an empty string if a model was persisted instead.

modelName

String

The name of the persisted model or an empty string if a graph was persisted instead.

exportPath

String

Path where the backups are stored at.

backupTime

LocalDateTime

Point in time when the backup was created.

exportMillis

Long

Milliseconds for creating the backup

status

String

Status of the persistence operation. Either SUCCESSFUL or FAILED.

Restore graphs and models
CALL gds.alpha.restore(configuration: Map)
YIELD
  restoredGraph: String,
  restoredModel: String,
  status: String,
  restoreMillis: Long
Table 4. Parameters
Name Type Optional Description

configuration

Map

yes

Additional parameters to configure the restore.

Table 5. Configuration
Name Type Default Description

concurrency

Integer

4

The number of concurrent threads used for performing the restore.

Table 6. Results
Name Type Description

restoredGraph

String

The name of the restored graph or an empty string if a model was restored instead.

restoredModel

String

The name of the restored model or an empty string if a graph was restored instead.

status

String

Status of the restore operation. Either SUCCESSFUL or an error message.

restoreMillis

Long

Amount of time restoring took in milliseconds.

2. Examples

First we need to create a graph in the corresponding Neo4j database.

The following Cypher statement will create the example graph in the Neo4j database:
CREATE
  (alice:Person {name: 'Alice'}),
  (bridget:Person {name: 'Bridget'}),

  (alice)-[:KNOWS]->(bridget)

Now we need to project an in-memory graph which we want to back-up.

The following statement will project a graph using a native projection and store it in the graph catalog under the name 'myGraph'.
CALL gds.graph.project(
  'myGraph',
  'Person',
  'KNOWS'
)

We can now run the back-up procedure in order to store the in-memory graph on disk.

The following will run the back-up procedure:
CALL gds.alpha.backup()
YIELD graphName, status
Table 7. Results
graphName status

"myGraph"

"SUCCESSFUL"

It is now safe to drop the in-memory graph or shutdown the db, as we can restore it at a later point.

The following will drop the in-memory graph:
CALL gds.graph.drop('myGraph')

If we want to restore the backed-up graph, we can simply run the restore procedure to load it back into memory.

The following will run the restore procedure:
CALL gds.alpha.restore()
YIELD restoredGraph
Table 8. Results
restoredGraph

"myGraph"

As we can see, one graph with name myGraph was restored by the procedure.