Training Backup Recovery Windows - tomgeudens/practical-neo4j GitHub Wiki
Context: Information for the Backup & Recovery training.
Prerequisite: The document will assume you have done a Setup Neo4j Enterprise on Windows (4.3) and have an instance running in a regular (non-elevated) powershell window.
Version: this document is current for version 4.3.5
Setting the stage
If you have at least one modestly sized database running on your instance, you can use that for the remainder of this training. The instructions will assume this is the neo4j database, adapt accordingly if it is not.
If you don't have any data loaded yet, we're going to load the example movies set. Fire up a regular webbrowser (a recent Chrome, Firefox, Microsoft Edge or Opera GX are all fine, Microsoft IE and Safari may give issues) and browse to your running instance. Log on to the default database (username is neo4j, password is trinity).
:use neo4j
:play movies
And run the create script on the second page of that guide. Additionally, create the following constraints and index.
CREATE CONSTRAINT uc_Movie_title ON (m:Movie) ASSERT m.title IS UNIQUE;
CREATE CONSTRAINT uc_Person_name ON (p:Person) ASSERT p.name IS UNIQUE;
CREATE INDEX index_Movie_tagline FOR (m:Movie) ON (m.tagline);
With the data loaded, open a second powershell window. Position yourself once more in the neo4j folder.
First check that you are in the right spot
dir
d---- __/__/2021 __:__ install
d---- __/__/2021 __:__ neo4j-enterprise-4.3.5
d---- __/__/2021 __:__ scripts
d---- __/__/2021 __:__ zulu11.50.19-ca-jre11.0.12-win_x64
Create some additional folders
mkdir dump
mkdir backup
And verify
dir
d---- __/__/2021 __:__ backup
d---- __/__/2021 __:__ dump
d---- __/__/2021 __:__ install
d---- __/__/2021 __:__ neo4j-enterprise-4.3.5
d---- __/__/2021 __:__ scripts
d---- __/__/2021 __:__ zulu11.50.19-ca-jre11.0.12-win_x64
Last but not least, set the enviroment
. .\scripts\environment.ps1
Note that there are two dots (with a blank in between) there. All that follows will assume you have done this and are positioned right here. So if you have to do it over, position again, verify and set the enviroment again.
Dump
Stop the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "STOP DATABASE neo4j;"
Check that it worked
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "SHOW DATABASES;"
Take the dump
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 dump --database=neo4j --to=..\dump\neo4j.dump
Verify that it worked
dir .\dump\neo4j.dump
Start the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "START DATABASE neo4j;"
Check that it worked
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "SHOW DATABASES;"
Load
Load the dump
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 load --database=loaded --from=..\dump\neo4j.dump
Create the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "CREATE DATABASE loaded;"
Verify
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d loaded "MATCH () RETURN COUNT(*);"
Backup
Take a backup
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 backup --database=neo4j --backup-dir=..\backup
Verify
dir .\backup\neo4j
Make a change on the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d neo4j "CREATE (:Person {name: 'Tom Geudens'});"
Backup again (it's the same command)
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 backup --database=neo4j --backup-dir=..\backup
Restore
Prepare the restore
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 prepare-restore --target=..\backup\neo4j
Do the restore
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 restore --database=restored --from=..\backup\neo4j
Create the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "CREATE DATABASE restored;"
Verify
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d restored "MATCH (p:Person {name: 'Tom Geudens'}) RETURN p;"
Copy
Stop the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "STOP DATABASE neo4j;"
Verify
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "SHOW DATABASES;"
Take the copy
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 copy --from-database=neo4j --to-database=copied
Make sure you cut-and-paste the schema syntax into a text editor of some sort.
Create the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "CREATE DATABASE copied;"
Enter an interactive Cypher Shell and paste the schema syntax
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d copied
# paste the schema syntax
:quit
Verify the count
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d copied "MATCH () RETURN COUNT(*);"
Verify the constraints
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d copied "CALL db.constraints();"
Start the database
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "START DATABASE neo4j;"
Verify
.\neo4j-enterprise-4.3.5\bin\cypher-shell.bat -u neo4j -p trinity -d system "SHOW DATABASES;"
Remote
Create a directory
mkdir backup\remote
Your teacher will provide you with the IP to use for the below command.
.\neo4j-enterprise-4.3.5\bin\neo4j-admin.ps1 backup --from=<theprovidedip>:6362 --backup-dir=..\backup\remote --database=remoted