Backups and upgrades#
What to back up, how to upgrade, and what a rollback will not restore.
What holds state#
| State | Where |
|---|---|
| Control-plane data — projects, services, environments, deployments, audit ledger | Your Postgres database |
| Encrypted variable material | Postgres, encrypted under a key envelope |
| Encryption and integrity keys | /var/lib/midnight — cursor, credential-MAC, variable-intent and variable-encryption keys |
| Configuration | /etc/midnight |
| Logs | /var/log/midnight |
| Built images | Your registry |
The database alone is not a complete backup. Variables are
encrypted under keys held on the host. A database restored without the
matching /var/lib/midnight keys leaves every secret undecryptable.
Back up#
- Back up Postgres with your normal tooling, to a known-consistent point.
- Back up
/var/lib/midnight, including the generated keys. - Back up
/etc/midnight. - Record the package version installed on the host.
- Store the key backup with the protection you would give a private key — separately from the database backup, encrypted.
Taking the database and the keys as one logical set is what makes the backup restorable.
Restore#
- Restore Postgres.
- Restore
/var/lib/midnightand/etc/midnight. - Install the same package version you recorded.
- Start the units and read the doctor report.
- Verify the audit ledger. See Monitoring and audit.
Upgrade#
- Back up first, as above.
- Read the release notes for migrations.
- Install the new package. It runs available migrations when a connection string is configured, and writes a fresh doctor report.
- Read the doctor report before enabling or restarting units.
- Verify the ledger and deploy a low-risk service to confirm the path works end to end.
Migrations change the database. Restoring an older package against a migrated database is not supported by simply reinstalling. Your database backup is the rollback path.
What rollback does not cover#
midnight rollback --previous returns a deployment. It does not:
- reverse a database migration your application ran;
- revert variables you changed; or
- restore control-plane state.
Decide what else needs reversing before relying on it. See Deploying and rolling back.
Key rotation#
The variable vault supports rotating the key-encryption key, and keeps immutable encrypted version history. Rotation is an operation to plan and back up around, not a routine command.
Verify#
- A restored installation starts with all six units active.
- A sealed variable can still be used by a deployment, proving the keys match the database.
midnight audit verifysucceeds.
If it does not work#
| Symptom | Check | Recovery |
|---|---|---|
| Secrets fail to decrypt after a restore | Whether /var/lib/midnight keys came from the same backup set |
Restore the matching keys; the database alone is insufficient |
| Units fail after an upgrade | The doctor report | Resolve findings before enabling |
| Migrations did not run | Whether a connection string was configured | Configure it and re-run available migrations |
| An old package refuses a migrated database | Downgrades are not a supported path | Restore the database backup taken before the upgrade |