Backup and restore
This page lists what you need to back up and how to restore MicroB2B from a backup.
What to back up
| What | Why |
|---|---|
| The database | Configuration, users, certificates, messages and their history |
| The payload storage | The contents of the messages |
SECRETS_KEY and any keys in SECRETS_PREVIOUS_KEYS | Without them, private keys and stored passwords in the backup cannot be used |
SESSION_KEY and AUDIT_KEY | So sessions and the audit log’s checks keep working after a restore |
Your environment file, such as /etc/microb2b.env | The rest of the configuration |
Back up the database and the payload storage together. The database records which contents each message has. The payload storage holds the bytes. One without the other gives you messages without contents, or contents without messages.
Keep the keys apart from the database backup. Store them in a password manager or a safe of your company. A key stored next to the database protects nothing. A lost SECRETS_KEY cannot be recovered. See secrets.
SQLite
You can back up while MicroB2B runs:
sqlite3 /var/lib/microb2b/microb2b.db ".backup /backup/microb2b.db"A plain file copy is only safe when MicroB2B is stopped. Otherwise, copy the -wal and -shm files with it.
PostgreSQL
Use pg_dump in its custom format:
pg_dump -F c -f /backup/microb2b.dump "postgres://user:password@host:5432/db"Payload storage
- Local directory: copy the directory, for example with
rsync. You find its location under System > Settings. - S3: turn on versioning or replication for the bucket.
See payload storage.
Restore
- Stop MicroB2B.
- Put back the database: copy the SQLite file in place, or load the dump with
pg_restoreinto an empty database. - Put back the payload storage from the same moment.
- Set the same
SECRETS_KEYas when the backup was made. If the key was replaced since, put the old key inSECRETS_PREVIOUS_KEYS. - Start MicroB2B and check
/healthand the log.
MicroB2B refuses to start when SECRETS_KEY does not match the database. The log names the problem. See secrets.