Skip to content

Backup and restore

This page lists what you need to back up and how to restore MicroB2B from a backup.

What to back up

WhatWhy
The databaseConfiguration, users, certificates, messages and their history
The payload storageThe contents of the messages
SECRETS_KEY and any keys in SECRETS_PREVIOUS_KEYSWithout them, private keys and stored passwords in the backup cannot be used
SESSION_KEY and AUDIT_KEYSo sessions and the audit log’s checks keep working after a restore
Your environment file, such as /etc/microb2b.envThe 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

  1. Stop MicroB2B.
  2. Put back the database: copy the SQLite file in place, or load the dump with pg_restore into an empty database.
  3. Put back the payload storage from the same moment.
  4. Set the same SECRETS_KEY as when the backup was made. If the key was replaced since, put the old key in SECRETS_PREVIOUS_KEYS.
  5. Start MicroB2B and check /health and the log.

MicroB2B refuses to start when SECRETS_KEY does not match the database. The log names the problem. See secrets.