Backup and restore¶
This page lets you create an encrypted backup of a Ninlil installation and restore it on the same machine or on another one. The README holds the complete reference: Backup and restore.
Backup & Restore writes one file, with the extension .ltbk. It holds:
- the database tables for configuration and identity: zones and records, keys and credentials, users, roles, sessions, API tokens, filtering, clients, forwarders, rewrites, webhooks, cluster peers and every DHCP table;
- the Data Protection key ring (
key-*.xml), because every secret in the database opens only with it; - the shared TLS certificate, including its private key;
- the runtime configuration file (
appsettings.json), which holds the settings you saved in the console.
It leaves out the query log, the operational log and metrics, the zone change journal, webhook delivery attempts, secondary-zone refresh state and cluster sync tombstones. It also leaves out the JWT signing key, the cluster node id, the root trust anchor file and the ACME certificate files. A restore replaces all stored data with the content of the file. There is no partial or merged restore. Ninlil takes no backups by itself.
Before you start¶
- An account with
backup:readto create a backup andbackup:writeto restore one (the bootstrap administrator has both), and its access token, called<token>below. The commands use the HTTPS port18443from the quick start. - A passphrase of at least 12 characters
(
NINLIL_DNS_SERVER_BACKUP_MINIMUM_PASSPHRASE_LENGTH). Ninlil keeps no copy of it, and a lost passphrase makes the file unreadable. Keep it apart from the file, in a password manager for example. The commands call it<passphrase>. - Memory for the whole archive. Ninlil holds it in memory while it builds or restores it, and it refuses a request body above 2 GiB.
- To restore: a running Ninlil you can sign in to, and the
.ltbkfile. A restore replaces the accounts too, so sign-in afterwards uses the accounts from the backup.
The examples call the API on 127.0.0.1 with curl -k, which skips the certificate check.
That is safe only on the machine that runs Ninlil; see Self-signed certificate.
Create a backup¶
-
In the console, open Backup & Restore (
/backup), enter the passphrase twice and choose Download backup. Or call the API:curl -k -o ninlil-backup.ltbk https://127.0.0.1:18443/api/backup -H "Authorization: Bearer <token>" -H 'Content-Type: application/json' -d '{"passphrase":"<passphrase>"}'The file
ninlil-backup.ltbkappears in the current folder.curl -ocreates it with your shell's default permissions, which usually let other users read it. The file holds your whole configuration, even though it is encrypted, so restrict it at once (or runumask 077before the call):chmod 600 ninlil-backup.ltbkWithout a
passphrase, Ninlil writes the file unencrypted. An unencrypted file holds the key ring and the certificate's private key in plain text, so always set a passphrase. 2. Copy the file to a place that is not on the same machine, and keep the passphrase elsewhere.
Check that it worked¶
A file made with a passphrase starts with the five characters LTBK1. An unencrypted file starts
with LTBK0:
head -c 5 ninlil-backup.ltbk; echo
LTBK1
Restore a backup¶
- On another machine, install Ninlil first (Installation) and start it once, so you can sign in with its bootstrap administrator.
-
Sign in. In the console, open Backup & Restore, choose the file under Restore from a backup, type the passphrase and confirm the warning. Or call the API:
curl -k https://127.0.0.1:18443/api/backup/restore -H "Authorization: Bearer <token>" -F archive=@ninlil-backup.ltbk -F passphrase='<passphrase>'{"totalEntitiesImported":10,"entityCounts":{"Roles":2,"Users":2,"Sessions":4,"ApiTokens":1,"Zones":1,"Records":0, ...},"note":"Restore succeeded. Restart this process now so the restored database connection, Data Protection key ring, and TLS certificate are actually picked up -- none of them take effect for this already-running process on their own."}(your counts differ). Leave out
-F passphrase=...for an unencrypted file. 3. Restart Ninlil (sudo systemctl restart ninlil,docker restart ninlilorRestart-Service Ninlil). The restored key ring, certificate and settings take effect at the restart. 4. To keep access tokens from the old machine valid, setNINLIL_JWT_SIGNING_KEYon the other machine to the content of the old machine'sdata/jwt-signing-key.txtbefore the restart. Without it, clients get a fresh access token from their refresh token, or sign in again.
Check that it worked¶
After the restart, Ninlil is healthy, the old accounts sign in, and the restored data is there:
curl http://127.0.0.1:18080/status
curl -k https://127.0.0.1:18443/api/zones -H "Authorization: Bearer <token>"
{"status":"Healthy","components":null}
{"items":[{"id":"...","name":"example.test", ...}],"skip":0,"take":50,"totalCount":1}
Sign in first with an account from the backup, because the restore replaced the accounts of the
machine you restored on. The bootstrap password of that machine answers 401.
Behaviour worth knowing¶
- A restore checks the whole file before it writes anything. A wrong passphrase, a damaged file or
an unknown format returns
400and leaves your data as it is. - On a relational database the restore is all or nothing. On MongoDB it is not atomic (Ninlil logs a warning): an error after the wipe can leave a partly restored database.
- The key ring is merged. The keys from the file are added and no key on the machine is deleted.
- A restore refuses a key ring this server cannot read. If the backup's key files are encrypted with
DPAPI from another machine or account, or with a certificate that is neither
NINLIL_DATA_PROTECTION_CERTIFICATE_PATHnorNINLIL_DATA_PROTECTION_PREVIOUS_CERTIFICATE_PATH, the restore returns400before it changes anything. Set the certificate the key ring was encrypted with as the previous certificate, restart and restore again (Security). - Only one restore runs at a time. A second request returns
409. - Tokens after a restore. Refresh tokens and API tokens come back, because they are database
rows. Access tokens are signed with the JWT key, which a backup does not hold, so on a machine with
another key an old access token answers
401until the client refreshes it. The console does that for you. API tokens keep working. - The query log and other history stay as they are. A backup never captures them, and a restore never touches them.
- SQLite files. To copy the database file itself instead, stop Ninlil first, or copy
ninlil-dns.sqlite3,-waland-shmtogether.
When something goes wrong¶
- The restore answers
400withFailed to decrypt this backup archive. The passphrase may be incorrect, or the archive may be corrupted or have been tampered with.Check the passphrase for typing errors and the file for damage (compare its size with the original). - Creating a backup answers
400withA backup passphrase must be at least 12 characters long. (Parameter 'passphrase'). Use a longer passphrase, or none. - The restore answers
400withAn archive file is required.Thearchiveform field is missing or empty. Use-F archive=@<file>. - The restore answers
409. Another restore is still running. Wait for it to finish. - Sign-in fails after the restore. The accounts and passwords are those of the backup. Use an account that existed when the backup was made.
- Requests fail with
401after you restore on another machine. The access token is signed by the old JWT key. Sign in again, or refresh the token.