2022-10-26 00:18:25 +02:00
|
|
|
# Backup and Restore
|
|
|
|
|
|
|
|
With any Identity Management (IDM) software, it's important you have the capability to restore in
|
2022-12-26 23:52:03 +01:00
|
|
|
case of a disaster - be that physical damage or a mistake. Kanidm supports backup and restore of the
|
|
|
|
database with three methods.
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2024-05-23 03:48:37 +02:00
|
|
|
It is important that you only attempt to restore data with the same version of the server that the
|
|
|
|
backup originated from.
|
|
|
|
|
2022-10-26 00:18:25 +02:00
|
|
|
## Method 1 - Automatic Backup
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
Automatic backups can be generated online by a `kanidmd server` instance by including the
|
|
|
|
`[online_backup]` section in the `server.toml`. This allows you to run regular backups, defined by a
|
|
|
|
cron schedule, and maintain the number of backup versions to keep. An example is located in
|
2022-10-26 00:18:25 +02:00
|
|
|
[examples/server.toml](https://github.com/kanidm/kanidm/blob/master/examples/server.toml).
|
|
|
|
|
|
|
|
## Method 2 - Manual Backup
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
This method uses the same process as the automatic process, but is manually invoked. This can be
|
|
|
|
useful for pre-upgrade backups
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
To take the backup (assuming our docker environment) you first need to stop the instance:
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```bash
|
|
|
|
docker stop <container name>
|
|
|
|
docker run --rm -i -t -v kanidmd:/data -v kanidmd_backups:/backup \
|
|
|
|
kanidm/server:latest /sbin/kanidmd database backup -c /data/server.toml \
|
|
|
|
/backup/kanidm.backup.json
|
|
|
|
docker start <container name>
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
You can then restart your instance. DO NOT modify the backup.json as it may introduce data errors
|
|
|
|
into your instance.
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
To restore from the backup:
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```bash
|
|
|
|
docker stop <container name>
|
|
|
|
docker run --rm -i -t -v kanidmd:/data -v kanidmd_backups:/backup \
|
|
|
|
kanidm/server:latest /sbin/kanidmd database restore -c /data/server.toml \
|
|
|
|
/backup/kanidm.backup.json
|
|
|
|
docker start <container name>
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
## Method 3 - Manual Database Copy
|
|
|
|
|
2023-01-03 21:33:52 +01:00
|
|
|
This is a simple backup of the data volume containing the database files. Ensure you copy the whole
|
|
|
|
folder, rather than individual files in the volume!
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```bash
|
|
|
|
docker stop <container name>
|
|
|
|
# Backup your docker's volume folder
|
2023-01-03 21:33:52 +01:00
|
|
|
# cp -a /path/to/my/volume /path/to/my/backup-volume
|
2022-12-26 23:52:03 +01:00
|
|
|
docker start <container name>
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2023-01-03 21:33:52 +01:00
|
|
|
Restoration is the reverse process where you copy the entire folder back into place.
|