Cloning a Neo4j database refers here to the process of creating an exact or near-exact copy of an existing database on the same cluster. The cloned database will have the same data, indexes.
When you clone a database, you create a new version or copy of the database, preserving its data and schema. This allows you to have multiple independent copies of the same database, which can be useful for various purposes such as development, testing, analysis.
There are 3 ways to clone a database.
Option 1 - Using Neo4j Admin Backup/Restore command.
- Here's a working example on how to clone a database using neo4j-admin backup, i.e. when the database is online and it can serve read/write operations. The following command will take a backup of database test and store it locally to the /backups folder locally.
- You should be able to see Backup complete successful message in the end.
aayushbhardwaj@Aayushs-MacBook-Pro bin % ./neo4j-admin backup --database=test --backup-dir=/backups --from=localhost:6312
2023-06-12 07:40:02.155+0000 INFO [c.n.b.v.BackupOutputMonitor] Finished, took 4s 379ms
Backup complete successful.
- Perform neo4j-admin restore from the backup and set the database name to a desired databaseName , Here I have named it CloneTestDb
aayushbhardwaj@Aayushs-MacBook-Pro bin % ./neo4j-admin restore --from=/backups/test --database=CloneTestDb
Selecting JVM - Version:11.0.19+0, Name:OpenJDK 64-Bit Server VM, Vendor:Homebrew
restorePath=/backups/test, restoreStatus=successful, reason= - Now, go to cypher shell or Neo4j Browser of this instance and Create the database.
CREATE DATABASE clonetestdb;
- Match the counts of clonetestdb and test database and it should match i.e Run CALL db.stats.retrieve('GRAPH COUNTS'); against each database and compare the counts.
Option 2 - Using Neo4j Admin Dump/Load command.
- Here's a working example on cloning a database in offline mode.
- Stop the database by running below on cypher shell or Neo4j browser.
- STOP DATABASE test
- Perform neo4j-admin dump as shown below.
aayushbhardwaj@Aayushs-MacBook-Pro bin % ./neo4j-admin dump --database=test --to=/backups
Selecting JVM - Version:11.0.19+0, Name:OpenJDK 64-Bit Server VM, Vendor:Homebrew
Done: 70 files, 917.2KiB processed.
aayushbhardwaj@Aayushs-MacBook-Pro bin % cd ../backups
aayushbhardwaj@Aayushs-MacBook-Pro backups % ls
test.dump - Perform neo4j-admin load command, change the --database option to a desired name. Here, I have named it CloneTestDB2 . Please note that this database is not present in the cluster at this moment.
aayushbhardwaj@Aayushs-MacBook-Pro bin % ./neo4j-admin load --from=/backups/test.dump --database=CloneTestDB2
Selecting JVM - Version:11.0.19+0, Name:OpenJDK 64-Bit Server VM, Vendor:Homebrew
Done: 70 files, 917.2KiB processed. - Confirm that there the following directory should be created after the load command /data/databases/clonetestdb2
- Now, go to cypher shell or Neo4j Browser of this instance and Create the database.
CREATE DATABASE clonetestdb2;
- Match the counts of clonetestdb2 and test database and it should match i.e Run CALL db.stats.retrieve('GRAPH COUNTS'); against each database and compare the counts.
Option 3 - Using Neo4j Admin Copy
- Stop the database by running below command on cypher-shell or Neo4j Browser
- STOP DATABASE test
- Perform Neo4j Admin copy command as demonstrated below. Please note that the name of new database is clonetestdb3
aayushbhardwaj@Aayushs-MacBook-Pro bin % ./neo4j-admin copy --from-database=test --to-database=clonetestdb3
Selecting JVM - Version:11.0.19+0, Name:OpenJDK 64-Bit Server VM, Vendor:Homebrew
Starting to copy store, output will be saved to: /instance1/neo4j-enterprise-4.4.19/logs/neo4j-admin-copy-2023-06-13.14.56.31.log
2023-06-13 09:26:32.498+0000 INFO [StoreCopy] ### Copy Data ###
2023-06-13 09:26:32.498+0000 INFO [StoreCopy] Source: /instance1/neo4j-enterprise-4.4.19/data/databases/test (page cache 8m)
2023-06-13 09:26:32.498+0000 INFO [StoreCopy] Target: /instance1/neo4j-enterprise-4.4.19/data/databases/clonetestdb3
2023-06-13 09:26:32.498+0000 INFO [StoreCopy] Empty database created, will start importing readable data from the source.2023-06-13 09:26:36.708+0000 INFO [o.n.i.b.ImportLogic] Import starting - Confirm that there the following directory should be created after the load command /data/databases/clonetestdb3
- Now, go to cypher shell or Neo4j Browser of this instance and Create the database.
CREATE DATABASE clonetestdb3;
- Match the counts of clonetestdb3 and test database and it should match i.e Run CALL db.stats.retrieve('GRAPH COUNTS'); against each database and compare the counts.
Comments
0 comments
Please sign in to leave a comment.