Skip to content

Commit 296b52a

Browse files
committed
fix(docs): add new backup and restore guide
Signed-off-by: Fatih Acar <[email protected]>
1 parent 8d4c407 commit 296b52a

File tree

2 files changed

+79
-54
lines changed

2 files changed

+79
-54
lines changed

docs/docs/guides/database-backup.mdx

Lines changed: 74 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,28 @@ title: Database backup and restore
44

55
import EnterpriseBadge from '@site/src/components/EnterpriseBadge';
66

7-
# Standalone database backup and restore examples
7+
## Backup and restore using infrahubops CLI tool
88

9-
This is a guide on how to backup and restore your database using an Infrahub command line tool.
10-
Please [see this topic](../topics/database-backup.mdx) for the requirements for using the tool and an explanation of how it works.
11-
12-
This guide assumes that you cloned the Infrahub repository to your machine, but you can also copy the content of [this tool's Python file](https://github.com/opsmill/infrahub/tree/stable/utilities/db_backup/__main__.py) into a local Python file and run it that way.
13-
14-
An alternative to avoid cloning the Infrahub repository is to directly run it through the Infrahub Docker image:
9+
`infrahubops` is a simple to use tool that allows you to backup and restore an Infrahub instance following the process described [here](#full-backup-and-restore-procedure).
1510

16-
```python
17-
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock registry.opsmill.io/opsmill/infrahub python -m utilities.db_backup
18-
```
11+
Copy the following command to install the tool:
1912

20-
## Backup tool usage
21-
22-
### Backup a remote Infrahub database
23-
24-
```python
25-
python -m utilities.db_backup neo4j backup --database-url=172.28.64.1 /infrahub_backups
26-
```
27-
28-
In this example, the "remote" Infrahub database is accessible at `172.28.64.1` and I want to store the generated backup files in the `/infrahub_backups` directory.
29-
Since the tool starts a helper container, the database may not be directly accessible from Docker depending on your network. You can try using the `--host-network` option:
30-
31-
```python
32-
python -m utilities.db_backup neo4j backup --host-network --database-url=172.28.64.1 /infrahub_backups
13+
```bash
14+
curl https://infrahub.opsmill.io/ops/$(uname -s)/$(uname -m) -o infrahubops && chmod +x infrahubops
3315
```
3416

35-
### Backup a local Infrahub database with a non-default backup port
17+
Then use the following command to backup a running instance:
3618

37-
```python
38-
python -m utilities.db_backup neo4j backup --database-backup-port=12345 /infrahub_backups
19+
```bash
20+
./infrahubops backup create
3921
```
4022

41-
In this example, I am running the backup command on the same machine that is running the Infrahub Docker containers. In this case, port `12345` must also have been set using the `NEO4J_server_backup_listen__address` environment variable in the Infrahub database container.
42-
43-
### Restore a backup on a non-default cypher port
23+
To restore from a backup:
4424

45-
```python
46-
python -m utilities.db_backup neo4j restore /infrahub_backups --database-cypher-port=9876
25+
```bash
26+
./infrahubops backup restore path_to_backup_file.tar.gz
4727
```
4828

49-
In this example, I am restoring `.backup` files that exist in the `/infrahub_backups` directory and my Infrahub database container uses a non-standard port for cypher access: `9876` instead of `7687`.
50-
5129
## Full backup and restore procedure
5230

5331
Backing Infrahub up consists of:
@@ -79,27 +57,27 @@ Restoring Infrahub consists of:
7957

8058
5. Restarting Infrahub (API servers, then task workers)
8159

82-
# Cluster Database backup and restore examples
60+
## Cluster Database backup and restore examples
8361

8462
<EnterpriseBadge />
8563

86-
## Cluster topology
64+
### Cluster topology
8765

8866
| Node | Role |
8967
|------------------|----------|
9068
| `database` | Leader |
9169
| `database-core2` | Follower |
9270
| `database-core3` | Follower |
9371

94-
## Context
72+
### Context
9573

9674
We are going to back up the Neo4j database from `database-core2` and restore it on `database-core3`, after having dropped the Neo4j database cluster-wide.
9775

9876
:::caution Important
9977
Always run backup/restore commands as the `neo4j` user inside the container to avoid permission issues with the data files.
10078
:::
10179

102-
## Step 1: Create backup from database-core2
80+
### Step 1: Create backup from database-core2
10381

10482
```bash
10583
docker exec -it -u neo4j infrahub-database-core2-1 bash
@@ -110,14 +88,14 @@ ls backups
11088
# neo4j-2025-03-24T19-57-18.backup
11189
```
11290

113-
## Step 2: Copy the backup to database-core3
91+
### Step 2: Copy the backup to database-core3
11492

11593
```bash
11694
docker cp infrahub-database-core2-1:/var/lib/neo4j/backups/neo4j-2025-03-24T19-57-18.backup \
11795
infrahub-database-core3-1:/var/lib/neo4j/neo4j-2025-03-24T19-57-18.backup
11896
```
11997

120-
## Step 3: drop the Neo4j database across the cluster
98+
### Step 3: drop the Neo4j database across the cluster
12199

122100
Connect to any node
123101

@@ -131,7 +109,7 @@ SHOW SERVERS;
131109
![drop database](../media/guides/database_backup_restore_step3.png)
132110
</center>
133111

134-
## Step 4: Clean residual data on database-core3
112+
### Step 4: Clean residual data on database-core3
135113

136114
Connect to the container:
137115

@@ -152,7 +130,7 @@ Then restart the container to ensure a clean state:
152130
docker restart infrahub-database-core3-1
153131
```
154132

155-
## Step 5: Restore the backup on database-core3
133+
### Step 5: Restore the backup on database-core3
156134

157135
Reconnect to the container:
158136

@@ -171,7 +149,7 @@ neo4j-admin database restore \
171149
![Restore database](../media/guides/database_backup_restore_step3.png)
172150
</center>
173151

174-
## Step 6: Identify the seed instance id
152+
### Step 6: Identify the seed instance id
175153

176154
Connect via Cypher shell (on the system database):
177155

@@ -193,7 +171,7 @@ SHOW SERVERS;
193171
![Seed database](../media/guides/database_backup_restore_step5.png)
194172
</center>
195173

196-
## Step 7: recreate the Neo4j database from the seed
174+
### Step 7: recreate the Neo4j database from the seed
197175

198176
Run the following Cypher command:
199177

@@ -210,7 +188,7 @@ OPTIONS {
210188
![Choose seed database](../media/guides/database_backup_restore_step7.png)
211189
</center>
212190

213-
## Step 8: Verify cluster sync
191+
### Step 8: Verify cluster sync
214192

215193
Check that the database is coming online:
216194

@@ -234,19 +212,19 @@ SHOW SERVERS;
234212

235213
All nodes should eventually show the Neo4j database as online.
236214

237-
## 📝 Notes
215+
### 📝 Notes
238216

239217
- If any node shows as **dirty** or **offline**, check the logs and ensure that the file `/data/databases/neo4j/neostore` exists.
240218
- Restoring the database on a single node does **not** automatically register it with the cluster.
241219
You **must** run the `CREATE DATABASE ... OPTIONS { existingData: 'use' }` command to register the restored data properly.
242220

243-
# Restore a database cluster backup on a standalone instance (for debug)
221+
## Restore a database cluster backup on a standalone instance (for debug)
244222

245-
## Context
223+
### Context
246224

247225
We are taking a backup from a Neo4j cluster and restoring it on a standalone local Neo4j instance (non-clustered), for the purpose of debugging and data analysis in a safe, isolated environment.
248226

249-
## Step 1: Backup from a cluster node <EnterpriseBadge />
227+
### Step 1: Backup from a cluster node <EnterpriseBadge />
250228

251229
The backup was created from a cluster node (either follower or leader) using:
252230

@@ -255,14 +233,14 @@ neo4j-admin database backup --to-path=backups/
255233
# Resulting file: neo4j-2025-03-24T19-57-18.backup
256234
```
257235

258-
## Step 2: Copy the backup to database
236+
### Step 2: Copy the backup to database
259237

260238
```bash
261239
docker cp neo4j-2025-03-24T19-57-18.backup \
262240
infrahub-database-1:/var/lib/neo4j/neo4j-2025-03-24T19-57-18.backup
263241
```
264242

265-
## Step 3: prepare the local Neo4j instance
243+
### Step 3: prepare the local Neo4j instance
266244

267245
Connect to the container:
268246

@@ -289,7 +267,7 @@ SHOW SERVERS;
289267
![Choose seed database](../media/guides/database_backup_restore_step7.png)
290268
</center>
291269

292-
## Step 4. Restore the backup
270+
### Step 4. Restore the backup
293271

294272
Run the restore command from the directory where the backup file is located:
295273

@@ -298,15 +276,15 @@ neo4j-admin database restore \
298276
--from-path=/var/lib/neo4j/neo4j-2025-03-24T19-57-18.backup neo4j
299277
```
300278

301-
## Step 5: recreate the Neo4j database
279+
### Step 5: recreate the Neo4j database
302280

303281
Run the following Cypher command:
304282

305283
```bash
306284
CREATE DATABASE neo4j
307285
```
308286

309-
## Step 6: Verify the status
287+
### Step 6: Verify the status
310288

311289
Check that the database is coming online:
312290

@@ -328,6 +306,48 @@ SHOW SERVERS;
328306
![Choose seed database](../media/guides/database_backup_restore_standalone_step6_2.png)
329307
</center>
330308

331-
## 📝 Notes
309+
### 📝 Notes
332310

333311
- This process *restores only data* — not cluster roles, replication, or configuration.
312+
313+
## Old database backup tool usage guide
314+
315+
This is a guide on how to backup and restore your database using an Infrahub command line tool.
316+
Please [see this topic](../topics/database-backup) for the requirements for using the tool and an explanation of how it works.
317+
318+
This guide assumes that you cloned the Infrahub repository to your machine, but you can also copy the content of [this tool's Python file](https://github.com/opsmill/infrahub/tree/stable/utilities/db_backup/__main__.py) into a local Python file and run it that way.
319+
320+
An alternative to avoid cloning the Infrahub repository is to directly run it through the Infrahub Docker image:
321+
322+
```python
323+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock registry.opsmill.io/opsmill/infrahub python -m utilities.db_backup
324+
```
325+
326+
### Backup a remote Infrahub database
327+
328+
```python
329+
python -m utilities.db_backup neo4j backup --database-url=172.28.64.1 /infrahub_backups
330+
```
331+
332+
In this example, the "remote" Infrahub database is accessible at `172.28.64.1` and I want to store the generated backup files in the `/infrahub_backups` directory.
333+
Since the tool starts a helper container, the database may not be directly accessible from Docker depending on your network. You can try using the `--host-network` option:
334+
335+
```python
336+
python -m utilities.db_backup neo4j backup --host-network --database-url=172.28.64.1 /infrahub_backups
337+
```
338+
339+
### Backup a local Infrahub database with a non-default backup port
340+
341+
```python
342+
python -m utilities.db_backup neo4j backup --database-backup-port=12345 /infrahub_backups
343+
```
344+
345+
In this example, I am running the backup command on the same machine that is running the Infrahub Docker containers. In this case, port `12345` must also have been set using the `NEO4J_server_backup_listen__address` environment variable in the Infrahub database container.
346+
347+
### Restore a backup on a non-default cypher port
348+
349+
```python
350+
python -m utilities.db_backup neo4j restore /infrahub_backups --database-cypher-port=9876
351+
```
352+
353+
In this example, I am restoring `.backup` files that exist in the `/infrahub_backups` directory and my Infrahub database container uses a non-standard port for cypher access: `9876` instead of `7687`.

docs/docs/topics/database-backup.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ title: Database backup and restore
44

55
# Database backup and restore command line interface
66

7+
:::warning
8+
This topic is about the old backup and restore tool for Infrahub.
9+
Please refer to the [backup and restore guide](../guides/database-backup) for more information about the new `infrahubops` tool.
10+
:::
11+
712
Infrahub provides a command-line interface tool to help backup and restore a full Neo4j database. It is designed to be run from almost any host machine and has a much smaller set of requirements than running the full Infrahub application. We use Docker containers to run commands against the Neo4j database to make this tool easier to install.
813

914
Please see [this guide](../guides/database-backup.mdx) for concrete examples of running backup and restore commands.

0 commit comments

Comments
 (0)