Skip to content

Commit e18a9a3

Browse files
Clarify how to restore a database backup in cluster
1 parent 038514b commit e18a9a3

4 files changed

Lines changed: 235 additions & 22 deletions

File tree

modules/ROOT/pages/backup-restore/copy-database.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
You can use the `neo4j-admin database copy` command to copy a database, create a compacted/defragmented copy of a database, clean up database inconsistencies, or do a direct migration from Neo4j 4.4 to any 5.x version.
88
`neo4j-admin database copy` reclaims the unused space, creates a defragmented copy of the _data store_, and creates the node label and relationship type lookup indexes.
99

10+
[[neo4j-admin-copy-command-limitations]]
1011
.Command limitations
1112
[NOTE]
1213
====

modules/ROOT/pages/backup-restore/restore-backup.adoc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ The `LOWEST TX` and `HIGHEST TX` columns show the transaction IDs of the first a
172172
That means, if you restore `neo4j-2023-06-29T14-50-45.backup`, your database will have `14` as the last transaction ID.
173173

174174

175-
=== Restore a database backup
175+
=== Restore a database backup in a standalone environment
176176

177177
The following examples assume that you want to restore your data in a new database, called `mydatabase`.
178-
If you want to replace an existing database, you need to stop it first and add the option `--overwrite-destination=true` to the restore command.
178+
If you want to replace an existing standalone database, you need to stop it first and add the option `--overwrite-destination=true` to the restore command.
179179

180180
. Restore a database backup by running the following command:
181181
+
@@ -235,6 +235,7 @@ For example, `--restore-until=123`.
235235
CREATE DATABASE mydatabase;
236236
----
237237

238+
238239
[[restore-cloud-storage]]
239240
=== Restore a backup located in cloud storage
240241

@@ -292,17 +293,26 @@ bin/neo4j-admin database restore --from-path=azb://myStorageAccount/myContainer/
292293
======
293294
=====
294295

296+
295297
=== Restore a database backup in a cluster
296298

297-
To restore a database backup in a cluster, designate one of the servers to be used as a seeder, and restore the database backup on that server.
298-
Then, use that server to create the restored database on other servers in the cluster.
299-
For more information, see xref:clustering/databases.adoc#cluster-seed[Designated seeder].
299+
To restore a database backup in a cluster, you can use one of the following methods:
300+
301+
* Designate one of the servers to be used as a seeder, and restore the database backup on that server.
302+
For more information, see xref:clustering/databases.adoc#cluster-designated-seeder[Restore a database using a server as a designated seeder].
303+
* Recreate a database from a backup or server URI.
304+
See xref:clustering/databases.adoc#restore-database-using-uri-approach[Restore a database using URI approach] for more information.
305+
* Recreate a database using the `dbms.recreateDatabase()` procedure.
306+
See xref:clustering/databases.adoc#restore-database-using-recreate-procedure[Restore a database using `dbms.recreateDatabase()`] for more details.
307+
* label:new[Introduced in 2026.03] Use the xref:backup-restore/copy-database.adoc[`neo4j-admin database copy`] command.
308+
See xref:clustering/databases.adoc#restore-database-using-copy-command[Restore a database backup using the `neo4j-admin database copy` command] for more details.
309+
300310

301311
=== Restore users and roles metadata
302312

303-
If you have backed up a database with the option `--include-metadata`, you can manually restore the users, roles, and auth rules metadata.
313+
Roles and users metadata are backed up during the backup process by default.
304314

305-
From the _<NEO4J_HOME>_ directory, you run the Cypher script _/data/scripts/databasename/restore_metadata.cypher_, which the `neo4j-admin database restore` command outputs, using xref:cypher-shell.adoc[]:
315+
If you need to restore the users and roles metadata, you have to do it manually by running the Cypher script from the _<NEO4J_HOME>_ directory, _/data/scripts/databasename/restore_metadata.cypher_, which the `neo4j-admin database restore` command outputs, using xref:cypher-shell.adoc[]:
306316

307317
*Using `cat` (UNIX)*
308318
[source, shell, role=nocopy noplay]
@@ -315,3 +325,4 @@ cat ../data/scripts/databasename/restore_metadata.cypher | bin/cypher-shell -u u
315325
----
316326
type ..\data\scripts\databasename\restore_metadata.cypher | bin\cypher-shell.bat -u user -p password -a ip_address:port -d system --param "database => 'databasename'"
317327
----
328+

modules/ROOT/pages/backup-restore/restore-dump.adoc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,8 @@ The `--overwrite-destination` option is required because you are replacing the e
108108

109109
If you are not replacing an existing database in Enterprise Edition, you must create the database (using `CREATE DATABASE` against the `system` database) after the load operation finishes.
110110

111-
[NOTE]
112-
====
113-
When using the `load` command to seed a cluster, and a previous version of the database exists, you must delete it (using `DROP DATABASE`) first.
114-
Alternatively, you can stop the Neo4j instance and unbind it from the cluster using `neo4j-admin server unbind` to remove its cluster state data.
115-
If you fail to DROP or unbind before loading the dump, that database’s store files will be out of sync with its cluster state, potentially leading to logical corruptions.
116-
For more information, see xref:clustering/databases.adoc#cluster-seed[Seed a cluster].
117-
====
118111

119-
[NOTE]
112+
[IMPORTANT]
120113
====
121114
`neo4j-admin database load` cannot be applied to xref:scalability/composite-databases/concepts.adoc[Composite databases].
122115
It must be run directly on the databases that are associated with that Composite database.
@@ -200,3 +193,18 @@ bin/neo4j-admin database load mydatabase --from-path=azb://myStorageAccount/myCo
200193
======
201194
=====
202195

196+
197+
[role=label--enterprise-edition]
198+
[[restore-dump-in-cluster]]
199+
=== Restore a clustered database from a dump
200+
201+
When using the `neo4j-admin database load` command to seed a cluster, and a previous version of the database exists, you must delete it (using `DROP DATABASE`) first.
202+
203+
Alternatively, you can stop the Neo4j server and unbind it from the cluster using xref:clustering/unbind.adoc[`neo4j-admin server unbind`] to remove its cluster state data.
204+
205+
If you fail to `DROP` the database or unbind a server before loading the dump, that database’s store files will be out of sync with its cluster state, potentially leading to logical corruptions.
206+
For more information, see xref:clustering/databases.adoc#cluster-designated-seeder[Restore a database using a designated seeder].
207+
208+
It is recommended to restore a database dump using a URI approach.
209+
See xref:database-administration/standard-databases/seed-from-uri.adoc[] for details.
210+

modules/ROOT/pages/clustering/databases.adoc

Lines changed: 200 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,27 @@ neo4j@neo4j> DRYRUN REALLOCATE DATABASES;
275275

276276

277277
[[cluster-seed]]
278-
== Seed a cluster
278+
== Restore a clustered database from a `.backup`/`.dump`
279279

280-
There are two different ways to seed a cluster with data:
280+
To restore a clustered database from a backup, or to seed a cluster with data:
281281

282-
* The first option is to use a _designated seeder_, where a designated server is used to create a backed-up database on other servers in the cluster.
283-
* The other option is to seed the cluster from a URI, where all servers to host the database are seeded with an identical seed from an external source specified by that URI.
282+
* You can use a _designated seeder_, where a designated server is used to create a backed-up database on other servers in the cluster.
283+
* You can seed the cluster from a URI, where all servers to host the database are seeded with an identical seed from an external source specified by that URI.
284284
For more details, see xref:database-administration/standard-databases/seed-from-uri.adoc[Create a database from a URI].
285+
* You can use the `dbms.recreateDatabase()` procedure.
286+
* You can also use the `neo4j-admin database copy` command.
285287

288+
[NOTE]
289+
====
286290
Keep in mind that using a designated seeder can be problematic in some situations as it is not known in advance how a database is going to be allocated to the servers in a cluster.
287291
Also, this method relies on the seed already existing on one of the servers.
292+
====
288293

289294

290295
[[cluster-designated-seeder]]
291-
=== Designated seeder
296+
=== Restore a database using a designated seeder
292297

293-
In order to designate a server in the cluster as a seeder, a database backup is transferred to that server using the xref:backup-restore/restore-backup.adoc[`neo4j-admin database restore`] command.
298+
In order to designate a server in the cluster as _a seeder_, a database backup is transferred to that server using the xref:backup-restore/restore-backup.adoc[`neo4j-admin database restore`] command.
294299
Subsequently, that server is used as the source for other cluster members to copy the backed-up database from.
295300

296301
This example creates a user database called `foo`, hosted on three servers in primary mode.
@@ -332,7 +337,7 @@ This may be different from the topology of `foo` when it was backed up.
332337
If you want to ensure a certain allocation across the cluster, you can specify the desired topology with the `TOPOLOGY` clause in the `CREATE DATABASE` command.
333338
See <<create-database, `CREATE DATABASE`>> for more information.
334339
+
335-
[source, cypher, role=noplay]
340+
[source, cypher5, role=noplay]
336341
----
337342
CREATE DATABASE foo
338343
TOPOLOGY [desired number of primaries] PRIMARIES [desired number of secondaries] SECONDARIES
@@ -359,6 +364,193 @@ SHOW DATABASE foo;
359364
9 rows available after 3 ms, consumed after another 1 ms
360365
----
361366

367+
368+
[[restore-database-using-uri-approach]]
369+
=== Restore a database from a URI
370+
371+
Before restoring a database, you have to take its backup and drop the database on all servers.
372+
If you have not dropped the database before restoring it, use `CREATE OR REPLACE DATABASE` instead of the `CREATE DATABASE` command.
373+
374+
The seed can be a full backup, a differential backup, or a dump from an existing database.
375+
When using `CloudSeedProvider`, the URI can point also to a folder which contains a backup chain.
376+
The sources of seeds are called _seed providers_. +
377+
For detailed information about seed providers in Neo4j, see xref:database-administration/standard-databases/seed-from-uri.adoc[].
378+
379+
Remember that the dump file created with the xref:backup-restore/offline-backup.adoc#offline-backup-command[`neo4j-admin database dump`] command contains only the database data.
380+
The associated users and roles metadata are not included and must be recreated manually after restore.
381+
382+
When restoring a database from a backup seed in a cluster, you have to define the database topology.
383+
You have the opportunity to create a topology that will differ from an original one.
384+
385+
The new allocations can be put on any available server in the cluster.
386+
387+
On one of the servers, run the command:
388+
389+
[.tabbed-example]
390+
=====
391+
[role=include-with-Cypher-25 label--new-2025.06]
392+
======
393+
394+
[source, cypher25]
395+
----
396+
CREATE DATABASE foo
397+
TOPOLOGY [desired number of primaries] PRIMARIES [desired number of secondaries] SECONDARIES
398+
OPTIONS { seedURI: 's3://myBucket/myBackup.backup' }
399+
----
400+
401+
======
402+
[role=include-with-Cypher-5]
403+
======
404+
405+
[source, cypher5]
406+
----
407+
CREATE DATABASE foo
408+
TOPOLOGY [desired number of primaries] PRIMARIES [desired number of secondaries] SECONDARIES
409+
OPTIONS { existingData: 'use', seedURI: 's3://myBucket/myBackup.backup' }
410+
----
411+
======
412+
=====
413+
414+
Number of primaries and secondaries must respect the number of available servers and their mode constraints.
415+
The `CREATE DATABASE` command automatically allocates the database.
416+
417+
If you restore your database from a backup file created with the xref:backup-restore/online-backup.adoc[`neo4j-admin database backup`] command, users and roles metadata is backed up by default unless you have changed the default value of the `--include-metadata` option.
418+
As a final step, you can xref:backup-restore/restore-backup.adoc#_restore_users_and_roles_metadata[restore users and roles metadata].
419+
This step is optional.
420+
421+
Verify that the restored database is online on the desired number of servers, in the desired roles by running the `SHOW DATABASES` command.
422+
423+
Starting with 2026.04, you can also restore a database from a server URI using the `server://` scheme.
424+
See xref:database-administration/standard-databases/seed-from-uri.adoc#server-seed-provider[Create a database from a URI -> `ServerSeedProvider`] for details.
425+
426+
427+
[[restore-database-using-recreate-procedure]]
428+
=== Restore a database using the `dbms.recreateDatabase()` procedure
429+
430+
For detailed information on the recreate procedure, its options and limitations, see xref:database-administration/standard-databases/recreate-database.adoc[].
431+
432+
You need xref:authentication-authorization/dbms-administration/dbms-database-management-privileges.adoc[the `CREATE DATABASE` and `DROP DATABASE` privileges] to run the recreate procedure.
433+
434+
If you provide a URI to a backup or a dump, the stores on all servers will be replaced by the backup or the dump at the given URI.
435+
The new database allocations can be put on any `ENABLED` server in the cluster.
436+
437+
To restore a database using backup as a seed and keeping the original database topology, run the command:
438+
439+
[source, shell]
440+
----
441+
CALL dbms.recreateDatabase("foo", {seedURI: "s3://myBucket/myBackup.backup",});
442+
----
443+
444+
Starting with 2026.04, you can also use server URI to recreate a database from a backup/dump located on a server in the cluster's file system:
445+
446+
[source, shell]
447+
----
448+
CALL dbms.recreateDatabase("foo", {seedURI: "server://server-id/myBackup.backup"});
449+
----
450+
451+
If a database is restored using `dbms.recreateDatabase()`, all previously granted user and role privileges on that database are preserved.
452+
453+
Verify that the restored database is online on the desired number of servers, in the desired roles by running the `SHOW DATABASES` command.
454+
455+
456+
[role=label--new-2026.03]
457+
[[restore-database-using-copy-command]]
458+
=== Restore a database backup using the `neo4j-admin database copy` command
459+
460+
See xref:backup-restore/copy-database.adoc#neo4j-admin-copy-command-limitations[Command limitations] before using this option.
461+
462+
The following example assumes that you have a backup of your existing database `foo` in an AWS S3 bucket.
463+
Before restoring a database, you do not need to stop or drop the database `foo`.
464+
465+
The following options can be specified for the `neo4j-admin database copy` command:
466+
467+
* `--source-location` -- a path to the full backup of an existing database or the last differential backup in the chain.
468+
This folder can be located locally or remotely (e.g., an S3 bucket) and must contain the full backup and all the differential backups in the chain, if any.
469+
* `--source-format=backup` -- the format of the source backup.
470+
* `--copy-schema` -- (optional) to copy the schema of the existing database if needed.
471+
* `--target-location` -- a path to a folder for target backup artifact data. Used together with `--target-format=backup`.
472+
* `--target-format` -- the format of the output data.
473+
Possible values are `backup` and `database` (default).
474+
* `--compress` -- label:new[Introduced in 2026.04] (optional) produces compressed backup artifacts.
475+
See xref:backup-restore/copy-database.adoc#copy-database-command-options[Copy a database store] for more information.
476+
477+
`--source-location` and `--source-format` cannot be used together with `--from-path-data` and/or `--from-path-txn` due to the conflict in trying to supply data from two different locations at once.
478+
479+
. Copy the data from a backup of your standard database `foo` into the database `foo-restored`.
480+
+
481+
[source, shell]
482+
----
483+
neo4j-admin database copy foo foo-restored --source-location=s3://bucket/folder/foo.backup --source-format=backup --copy-schema --target-location=s3://bucket/folder --target-format=backup
484+
----
485+
+
486+
Copying a database does not automatically create it.
487+
Therefore, it will not be visible if you do `SHOW DATABASES` at this point.
488+
489+
. Run the following command to create the database `foo-restored` by seeding it from your backup folder in the AWS S3 bucket:
490+
+
491+
[.tabbed-example]
492+
=====
493+
[role=include-with-Cypher-25 label--new-2025.06]
494+
======
495+
496+
[source, cypher]
497+
----
498+
CREATE DATABASE `foo-restored`
499+
TOPOLOGY [desired number of primaries] PRIMARIES [desired number of secondaries] SECONDARIES
500+
OPTIONS {seedUri: “s3://bucket/folder/”};
501+
----
502+
503+
======
504+
[role=include-with-Cypher-5]
505+
======
506+
507+
[source, cypher]
508+
----
509+
CREATE DATABASE foo-restored
510+
TOPOLOGY [desired number of primaries] PRIMARIES [desired number of secondaries] SECONDARIES
511+
OPTIONS {existingData: 'use', seedUri: “s3://bucket/folder/”};
512+
----
513+
======
514+
=====
515+
+
516+
Number of primaries and secondaries must respect the number of available servers and their mode constraints.
517+
518+
. Wait until the last committed transaction ID is the same for all allocations of the database and then verify that the new database is online by running the following command:
519+
+
520+
[source, cypher]
521+
----
522+
SHOW DATABASES;
523+
----
524+
. After the new database is online, you can drop the old database `foo` if it is no longer needed, or put it into read-write mode if you want to keep it for other purposes.
525+
+
526+
[.tabbed-example]
527+
=====
528+
[.include-with-drop-database]
529+
======
530+
531+
Run the following command to drop the old database `foo`:
532+
533+
[source, cypher]
534+
----
535+
DROP DATABASE foo;
536+
----
537+
======
538+
[.include-with-change-access-mode]
539+
======
540+
541+
Change the access mode of the old database `foo` to read-write:
542+
543+
[source, cypher]
544+
----
545+
ALTER DATABASE foo SET ACCESS READ WRITE;
546+
----
547+
======
548+
=====
549+
550+
551+
552+
553+
362554
[[cluster-allow-deny-db]]
363555
== Controlling locations with allowed/denied databases
364556

@@ -374,6 +566,7 @@ Note that starting from 2025.12, database name patterns (wildcards) are supporte
374566
** `modeConstraint` - controls in what mode (primary, secondary, or none) databases can be hosted on a server.
375567
If not set, there are no mode constraints on the server.
376568

569+
377570
[[cluster-default-database]]
378571
== Default database in a cluster
379572

0 commit comments

Comments
 (0)