Migrate a cluster (Helm)

This example shows how to migrate a Neo4j cluster deployed on Kubernetes with the neo4j/neo4j-cluster-core Helm chart from version 4.4 to 5.x.
Migration to Neo4j 5 is supported only from version 4.4.

It is recommended to read the following pages before continuing:

The following example steps assume that Neo4j DBMS 4.4 is installed with the Helm release names (core-1, core-2 & core-3).

Prepare the 4.4 cluster for migration

Prepare the 4.4 cluster for migration by recreating the indexes and the index-backed constraints to match the new index types, and by backing up each of your databases.

Recreate indexes and index-backed constraints

In 5.0, the BTREE index type is no longer available. Therefore, it is recommended to recreate all your BTREE indexes and index-backed constraints with index providers native-btree-1.0 or lucene+native-3.0 before switching to 5.x. During the migration, 5.x checks whether each BTREE index and index-backed constraint has an equivalent type of index and provider, and drops them.

What type of index to use instead of BTREE?

In most cases, RANGE indexes can replace BTREE. However, there might be occasions when a different index type is more suitable, such as:

  • Use POINT indexes if the property value type is point and distance or bounding box queries are used for the property.

  • Use TEXT indexes if the property value type is text and the values can be larger than 8Kb.

  • Use TEXT indexes if the property value type is text and CONTAINS and ENDS WITH are used in queries for the property.

If more than one of the conditions is true, it is possible to have multiple indexes of different index types on the same schema. For more information on each index type, see Operations Manual 5.0 → Index configuration.

Steps

  1. Recreate each of your BTREE indexes on the same schema but using the new type (RANGE, POINT, or TEXT) as per your use case. The following example creates a range index on a single property for all nodes with a particular label:

    CREATE RANGE INDEX range_index_name FOR (n:Label) ON (n.prop1)
  2. Recreate each of your index-backed constraints with index providers native-btree-1.0 or lucene+native-3.0 on the same schema but with the new provider. The following example creates a unique node property constraint on a single property for all nodes with a particular label. The backing index is of type range with range-1.0 index provider.

    CREATE CONSTRAINT constraint_with_provider FOR (n:Label) REQUIRE (n.prop1) IS UNIQUE OPTIONS {indexProvider: 'range-1.0'}
  3. Run SHOW INDEXES to verify that the indexes have been populated and constraints have been created with the correct index provider.

For more information about creating indexes, see Cypher® Manual → Creating indexes.

Backup each of your databases

  1. To ensure the databases do not get updated during the backup, put them into read-only mode using the Cypher command ALTER DATABASE <databasename> SET ACCESS READ ONLY.

  2. Run the Cypher command SHOW DATABASES YIELD * and choose the member that is up-to-date with the last committed transaction on all databases as a backup source.

  3. Create a directory to store backups. This tutorial uses /migration-backups.

  4. Run the neo4j-admin backup command to back up all your databases.

    • All databases that you want to back up must be online.

    • Use the option --include-metadata=all to include all roles and users associated with each of your databases.

    kubectl exec -t -i core-1-0 -- neo4j-admin backup --database=*  --backup-dir=/backups --include-metadata=all --expand-commands
  5. Copy the backups from the Kubernetes Pod to an intermediate to the /migration-backups folder on your local filesystem:

    kubectl cp core-1-0:/backups /path/to/migration-backups

    The result is a folder for each database, called <databasename> and located in the /migration-backups folder, and a metadata script for each database, located in /migration-backups/<databasename>/tools/metadata_script.cypher. For more information about the neo4j-admin backup command, see Operations Manual → Backup an online database.

    The file system copy-and-paste of databases is not supported and may result in unwanted behavior.

Set up 5.x cluster

Follow the Quickstart guide for detailed information about installing a 5.x cluster using the neo4j/neo4j Helm chart.

Prepare the 5.x cluster for the migration

  1. Update the neo4j helm repository:

    helm repo update neo4j
  2. Make a note of any user-supplied values that need to be migrated from the 4.4 Helm installation. The use supplied-values can be printed out using the command:

    helm get values core-1
  3. After reading the Quickstart guide, install a Neo4j 5.x cluster, for example:

    helm install server1 neo4j/neo4j --set neo4j.edition=enterprise --set neo4j.acceptLicenseAgreement=yes --set volumes.data.mode=defaultStorageClass --set neo4j.password="password" --set neo4j.minimumClusterSize=3 --set neo4j.name=v5-cluster
    
    helm install server2 neo4j/neo4j --set neo4j.edition=enterprise --set neo4j.acceptLicenseAgreement=yes --set volumes.data.mode=defaultStorageClass --set neo4j.password="password" --set neo4j.minimumClusterSize=3 --set neo4j.name=v5-cluster
    
    helm install server3 neo4j/neo4j --set neo4j.edition=enterprise --set neo4j.acceptLicenseAgreement=yes --set volumes.data.mode=defaultStorageClass --set neo4j.password="password" --set neo4j.minimumClusterSize=3 --set neo4j.name=v5-cluster

    If you are using TLS and want to reuse the keys from the 4.4 installation, install 5.x in the same namespace as 4.4.

Restore the database backups

  1. Copy the backup files from the /migration-backups to one of the 5.x cluster servers:

    kubectl cp /path/to/migration-backups/<databasename> server1:/backups/<databasename>
  2. If restoring the default neo4j database or another database that already exists, it must first be dropped:

    kubectl exec -t -i server1-0 -- cypher-shell -u neo4j -p password "DROP DATABASE neo4j IF EXISTS"
  3. Use the neo4j-admin restore command to restore each of your databases except the system database:

    kubectl exec -t -i server1-0 -- neo4j-admin database restore <databasename> --from-path=/backups/<databasename> --expand-commands
  4. Migrate each of your restored databases:

    kubectl exec -t -i server1-0 -- neo4j-admin database migrate <databasename> --expand-commands
  5. Run SHOW SERVERS YIELD address, serverId to retrieve the server ID for server1:

    kubectl exec -t -i server1-0 -- cypher-shell -d system -u neo4j -p password "SHOW SERVERS YIELD address, serverId"
  6. Recreate each of your migrated databases:

    kubectl exec -t -i server1-0 -- cypher-shell -d system -u neo4j -p password "CREATE DATABASE <databasename> OPTIONS {existingData: 'use', existingDataSeedInstance: '<ServerId for server1>'}"
  7. (Optional) Restore the roles and privileges associated with each of your databases by running the respective metadata script data/scripts/databasename/restore_metadata.cypher, which the neo4j-admin restore command output, using Cypher Shell:

    kubectl exec -t -i server1-0 -- cypher-shell -u neo4j -p password -d system --param "database => 'neo4j'" -f /data/scripts/neo4j/restore_metadata.cypher
  8. If you have kept your 4.4 cluster running while setting up the new one, you can uninstall it now.