14.9. Copy a database

This chapter describes the copy command of Neo4j Admin.

The copy command of neo4j-admin is used to copy data from an existing database to a new database.

The syntax follows:

neo4j-admin copy --to-database=<database>
                (--from-database=<database> | --from-path=<path>)
                [--from-pagecache=<size>]
                [--from-path-tx=<path>]
                [--to-format=<format>]
                [--to-pagecache=<size>]
                [--delete-nodes-with-labels=<label>[,<label>...]]
                [--skip-labels=<label>[,<label>...]]
                [--skip-properties=<property>[,<property>...]]
                [--skip-relationships=<relationship>[,<relationship>...]]`
                [--force]
                [--verbose]

The existing database must be stopped before copying from it, and the destination database must not yet exist.

The copy command can process an optional set of filters. This can be used to remove data that is unwanted in the destination database.

The schema definitions, i.e. index and constraint, are not automatically transferred. However, they will be extracted and presented as Cypher statements so you can recreate the ones you want.

Options

Option Description

--from-database

The database name to copy from. Will assume the database is in the configured location.

--from-pagecache

The size of the page cache to use for reading.

--from-path

The path to the database to copy from. It can be used to target databases outside of the installation, e.g. backups.

--from-path-tx

The path to the transaction log files. You only need to use this if the command is unable to determine where they are located.

--to-database

The destination database name.

--to-format

The store format of the destination database. Valid values are same, standard, high_limit. The default value for this option is the format of the source database.

--to-pagecache

The size of the page cache to use for writing.

--delete-nodes-with-labels

A list of labels. Any node matching any of the labels will be ignored during copy.

--skip-properties

A list of property keys to ignore during the copy.

--skip-labels

A list of labels to ignore during the copy.

--skip-relationships

A list of relationship types to ignore during the copy.

--verbose

Will instruct the tool to print more verbose output.

--force

Will force the command to proceed even if the integrity of the database can not be verified.

Due to the way filters are processed, the id of the node might change. This is true even if no filters are specified.

Examples

Example 14.16. Use the copy command to take a copy of the database neo4j.

To begin, you must stop the database named neo4j; this can be done by issuing the following Cypher statement:

STOP DATABASE neo4j

You can now copy the data from neo4j, to a new database called copy:

$neo4j-home> bin/neo4j-admin copy --from-database=neo4j --to-database=copy

A new database with the name copy now exists on the server, but it is not automatically picked up by Neo4j. To start the new database you have to insert it into Neo4j with the following Cypher query:

CREATE DATABASE copy

Neo4j will then detect the copied database and begin to use that.

Remember to start the database you copied from, if you still want it, using:

START DATABASE neo4j

The console output is saved to logs/neo4j-admin-copy-<date>.log.

Example 14.17. Use the copy command with filters.

The command can perform some basic forms of processing. You can remove nodes, labels, properties, and/or relationships.

The difference with --skip-labels and --delete-nodes-with-labels is that --skip-labels will just remove the labels, potentially leaving nodes without any labels.

$neo4j-home> bin/neo4j-admin copy --from-database=neo4j --to-database=copy --delete-nodes-with-labels="Cat,Dog"

After this command, you will have a copy of the database neo4j, without nodes with the labels :Cat and :Dogs.

Labels are processed independently, i.e. the filter described above will delete any node with either :Cat or :Dogs, and not only nodes that have both of the labels.