Copy a database store
This section describes how to copy the data store of an existing offline database to a new database.
A user database or backup can be copied to a Neo4j instance using the copy
command of neo4j-admin
.
1. Command
neo4j-admin copy
copies the data store of an existing offline database to a new database.
1.1. Usage
The neo4j-admin copy
command can be used to clean up database inconsistencies, compact stores, and do a direct migration from Neo4j 3.5 to any 4.x version.
It can process an optional set of filters, which you can use to remove any unwanted data before copying the database.
The command copies only the data store but not the schema store (index and constraints), and therefore, it allows for a large range of migrations.
However, if there is a schema defined, you have to recreate it by running the Cypher commands that the neo4j-admin copy
operation outputs.
The neo4j-admin copy
command also reclaims the unused space of a database and creates a defragmented copy of that database or backup in the destination Neo4j instance.
For a detailed example of how to reclaim unused space, see Reclaim unused space. For a detailed example of how to back up a 3.5 database and use the neo4j-admin copy command to compact its store and migrate it to a 4.x Neo4j standalone instance, see Migration Guide → Tutorial: Back up and copy a database.
|
|
1.2. Syntax
neo4j-admin copy [--verbose]
[--from-database=<database>]
[--from-path=<path>]
[--from-path-tx=<path>]
--to-database=<database>
[--neo4j-home-directory=<path>]
[--force]
[--to-format=<format>]
[--delete-nodes-with-labels=<label>[,<label>...]]
[--keep-only-node-properties=<label.property>[,<label.property>...]]
[--keep-only-nodes-with-labels=<label>[,<label>...]]
[--keep-only-relationship-properties=<relationship.property>[,<relationship.property>...]]
[--skip-labels=<label>[,<label>...]]
[--skip-node-properties=<label.property>[,<label.property>...]]
[--skip-properties=<property>[,<property>...]]
[--skip-relationship-properties=<relationship.property>[,<relationship.property>...]]
[--skip-relationships=<relationship>[,<relationship>...]]
[--from-pagecache=<size>]
[--to-pagecache=<size>]
1.3. Options
Option | Default | Description |
---|---|---|
|
Enable verbose output. |
|
|
The database name to copy from. |
|
|
The path to the database to copy from. It can be used to target databases outside of the installation, e.g., backups. |
|
|
The path to the transaction log files. Use if the command cannot determine where they are located. |
|
|
The destination database name. |
|
|
The same as the database copied from. |
Path to the home directory for the copied database. |
|
Force the command to proceed even if the integrity of the database can not be verified. |
|
|
The format of the source database. |
Set the format for the new database. Valid values are |
|
A comma-separated list of labels. All nodes that have ANY of the specified labels will be deleted. Any node matching any of the labels will be ignored during copy. |
|
|
A list of property keys to keep for nodes with the specified label. Any labels not explicitly mentioned will keep their properties. Cannot be combined with |
|
|
A list of labels. All nodes that have any of the specified labels will be kept. Cannot be combined with |
|
|
A list of property keys to keep for relationships with the specified type. Any relationship types not explicitly mentioned will keep their properties. Cannot be combined with |
|
|
A comma-separated list of labels to ignore during the copy. |
|
|
A list of property keys to ignore for nodes with the specified label. Cannot be combined with |
|
|
A comma-separated list of property keys to ignore during the copy. Cannot be combined with |
|
|
A comma-separated list of relationship types to ignore during the copy. |
|
|
A list of property keys to ignore for relationships with the specified type. Cannot be combined with |
|
|
The size of the page cache to use for reading. |
|
|
The size of the page cache to use for writing. |
You can use the |
2. Examples
neo4j-admin copy
to copy the data store of the database neo4j
.-
Stop the database named
neo4j
:STOP DATABASE neo4j
-
Copy the data store from
neo4j
to a new database calledcopy
:bin/neo4j-admin copy --from-database=neo4j --to-database=copy
-
Run the following command to verify that database has been successfully copied.
ls -al ../data/databases
Copying a database does not automatically create it. Therefore, it will not be visible if you do SHOW DATABASES
at this point. -
Create the copied database.
CREATE DATABASE copy
-
Verify that the
copy
database is online.SHOW DATABASES
-
If your original database has a schema defined, change your active database to
copy
and recreate the schema using theneo4j-admin copy
output.The console output is saved to logs/neo4j-admin-copy-<timestamp>.log.
neo4j-admin copy
to filter the data you want to copy.The command can perform some basic forms of processing. You can filter the data that you want to copy by removing nodes, labels, properties, and relationships.
bin/neo4j-admin copy --from-database=neo4j --to-database=copy --delete-nodes-with-labels="Cat,Dog"
The command creates a copy of the database neo4j
but without the nodes with the labels :Cat
and :Dog
.
Labels are processed independently, i.e., the filter deletes any node with a label :Cat , :Dog , or both.
|
For a detailed example of how to use |
Was this page helpful?