Skip to content

Commit 4670eaf

Browse files
authored
Add backup script, allowing selection of pod & db to select (#148)
* Add backup script, allowing selection of pod & db to select * Shellcheck * Ns as var * Add readme
1 parent 2ad23ee commit 4670eaf

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,58 @@
33
## Usage
44

55
### Clone
6+
67
To use this repo, you must first clone it locally
8+
79
```sh
810
git clone [email protected]:Linkurious/docker-neo4j.git
911
cd ./docker-neo4j
1012
```
1113

1214
### Configure
15+
1316
Configure variables in .env. See .env.example for template.
1417
Reasonable defaults are provided. Simply use them when working localy.
18+
1519
```sh
1620
ln -s .env.example .env
1721
ln -s .env.neo4j.v4.example .env.neo4j.v4.dev
1822
```
1923

2024
### Start Neo4j
25+
2126
Run with docker-compose
2227
Neo4j v4
2328

2429
```sh
2530
docker-compose up -d
2631
```
32+
2733
Neo4j v5
2834

2935
```sh
3036
docker-compose -f docker-compose.v5.yml -f docker-compose.override.yml up -d
3137
```
3238

3339
### Start Neo4j cluster
40+
3441
Neo4j v4
42+
3543
```sh
3644
ln -s .env.neo4j.v4.example .env.neo4j.v4.dev
3745
docker-compose -f docker-compose.cluster.v4.yml -f docker-compose.cluster.override.yml up -d
3846

3947
```
4048
Neo4j v5
49+
4150
```sh
4251
ln -s .env.neo4j.v5.example .env.neo4j.v5.dev
4352
docker-compose -f docker-compose.cluster.v5.yml -f docker-compose.cluster.override.yml up -d
4453

4554
```
4655

4756
## Browse database when working localy
57+
4858
Go to http://localhost:7474 and connect with the following parameters:
4959

5060
- Connect URL: bolt://localhost:7687
@@ -54,6 +64,7 @@ Go to http://localhost:7474 and connect with the following parameters:
5464
- Password: neo3j
5565

5666
## Neo4j v3 restore
67+
5768
```sh
5869
docker-compose -f docker-compose.yml -f docker-compose.shell.yml run --rm neo4j bash
5970
```
@@ -63,80 +74,104 @@ docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-c
6374
```
6475

6576
## Backup and restore (Neo4j V4)
77+
6678
see https://neo4j.com/docs/operations-manual/current/backup/
6779

6880
When working localy, docker-compose.override.yml adds a local bind mount to the /backups folder.
6981

7082
Backups can be downloaded from Nexus. They have to be decompressed in the ./backups bind mounted folder.
7183

7284
Create an online backup (command to be executed in the context of the neo4j container, with `docker-compose exec neo4j`):
85+
7386
```sh
7487
neo4j-admin backup --backup-dir /backups --database crunchbase-1.0.0
7588
```
7689

7790
Restore/create from dataset:
91+
7892
```sh
7993
neo4j-admin restore --from /datasets/4.2.0/crunchbase --database crunchbase-1.0.0 --verbose
8094
```
8195

8296
Restore from backup:
97+
8398
```sh
8499
neo4j-admin restore --from /backups/4.2.0/crunchbase --database crunchbase-1.0.0 --verbose
85100
```
86101
in v3.5.x
102+
87103
```sh
88104
neo4j-admin restore --from /backups/3.5.15/fincrime-1.0.0/ --database graph.db
89105
```
90106

91107
On first creation of a db, you will have to:
108+
92109
```
93110
:use system
94111
CREATE DATABASE `crunchbase-1.0.0` WAIT;
95112
```
96113

97114
You can then check that the db has succesfully been restored with:
115+
98116
```
99117
:use crunchbase-1.0.0
100118
match (n) return n limit 10
101119
```
102120

103121
### Offline load
122+
104123
```
105124
neo4j-admin load --from=/datasets/crunch.3.5.15 --database=crunchbase-1.0.0
106125
```
126+
107127
and create the database via cypher-shell (the credential are specified in the .env.neo4j.dev at the root of you repository) :
128+
108129
```
109130
cypher-shell
110131
CREATE DATABASE crunchbase;
111132
```
112133

113134
## Plugins
114135
### Apoc
136+
115137
see https://neo4j.com/labs/apoc/4.4/installation/
116138

117139
Download the appropriate version of apoc plugin and drop it in the plugins folder:
140+
118141
```sh
119142
curl -L https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/4.4.0.11/apoc-4.4.0.11-all.jar -o plugins/apoc-4.4.0.11-all.jar
120143
```
144+
121145
Warning: Check the matching version for your version of Neo4j
122146

123147
### Aura
124148
## load db
125149
From a shell, stoped database :
150+
126151
```sh
127152
bin/neo4j-admin push-to-cloud --bolt-uri neo4j+s://XXXXX.databases.neo4j.io --database=fincrime-1.0.0 --overwrite
128153
```
129154

130155
### Nexus datasets
131156

157+
## Retrieve backup
158+
159+
We provide a script automating retrieving a backup from a given instance running in K8s:
160+
161+
```sh
162+
./scripts/backup.sh
163+
```
132164

133165
## Manual upload for large datasets
166+
134167
```sh
135168
export dataset_name=fincrime-sales
136169
export dataset_version=1.0.0
137170
curl -L -v --user [email protected]:${USER_PWD} --upload-file ${dataset_name}-${dataset_version}.tgz https://nexus3.linkurious.net/repository/datasets/com/linkurious/neo4j/4.2.4/${dataset_name}/${dataset_name}-${dataset_version}.tgz
138171
```
172+
139173
## Download dataset
174+
140175
```sh
141176
export dataset_name=fincrime-sales
142177
export dataset_version=1.0.0

scripts/backup.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -o pipefail
4+
set -e
5+
set -u
6+
set -x
7+
8+
##########
9+
# Functions
10+
##########
11+
12+
##########
13+
# Main
14+
##########
15+
path='/tmp'
16+
namespace='neo4j-preprod'
17+
neo4j_pod=$(kubectl get pods -n "${namespace}" --no-headers -o custom-columns=':metadata.name' | fzf)
18+
database=$(kubectl exec -it -n "${namespace}" "$neo4j_pod" -c "neo4j" -- sh -c 'neo4j-admin database info --format=json' | jq -r '.[].databaseName' | fzf)
19+
echo "${database}"
20+
kubectl exec -it -n ${namespace} "$neo4j_pod" -c "neo4j" -- sh -c "exec /var/lib/neo4j/bin/neo4j-admin database backup ${database} --to-path=${path} --type=full --verbose"
21+
22+
#we change the name of the backup
23+
kubectl exec -t -n "${namespace}" "$neo4j_pod" -c "neo4j" -- bash -c "mv ${path}/${database}*.backup ${path}/${database}.backup"
24+
#we copy it to local
25+
kubectl cp --retries=-1 "${namespace}/${neo4j_pod}:${path}/${database}.backup" "/tmp/${database}.backup"
26+
#we check local file
27+
ls -lah "/tmp/$database.backup"

0 commit comments

Comments
 (0)