Backups and restore
This page is for you as the person who runs the site. After reading it you know what a backup holds, where it can go, how to check one, and how to bring one back.
Your server makes a backup every night and checks every week that the newest one really restores. You choose where the backups go.
What a backup holds
| In every backup | Why |
|---|---|
The three databases: the site's (stream), the homeserver's (synapse) and the sign-in service's (mas) |
Every account, message, setting, payment record and point balance |
| The homeserver's uploaded media | Avatars, images and files posted in rooms |
| The homeserver's signing key | Your server's identity to other servers. It can never be made again. See The signing key. |
The install's settings file, .env |
Every secret the data above is locked with |
The sign-in service's keys (matrix/mas-keys.yaml) |
Without them, everyone is signed out |
Tunnel mode: the tunnel's settings and credentials (cloudflared/) |
So a restored install can run the same tunnel |
| A manifest | Fingerprints of each part, so a check can tell a damaged backup from a good one |
Not in a backup:
- the software itself (a restore uses the release the server runs, and downloads its images again);
- your own icons in
/opt/blackbranch/site-files/(keep your own copy of what you put there); - the router's certificates (fetched again in direct mode);
- short-lived sound files;
- the Cloudflare account certificate, which the installer deletes (why).
The databases are copied one after another while the site keeps running.
How backups are stored
Backups are made with restic, a well-known open-source backup tool. Each backup is a snapshot. restic splits files into pieces, stores each piece once, and encrypts everything with the backup passphrase from your recovery sheet. A nightly backup therefore adds only what changed since the night before, and whoever holds your bucket or SFTP server sees only encrypted pieces.
restic keeps 7 daily and 4 weekly snapshots. Older ones are removed after each successful backup. If removing them fails, the backup still counts, and the old snapshots stay until the next run manages it. Change the numbers in Admin Panel → Site → Site, card Backups: daily 1 to 90, weekly 0 to 104.
restic counts days and weeks that have a backup, not calendar days. After a gap, the oldest snapshot can be older than a month (restic: removing snapshots). What that means for deleted data is on Where deleted data can still be.
Where backups go
You choose the target on the last setup page. To change it, open Admin Panel → Site → Site, card Backups. A change applies at the next backup. To try it at once, run sudo blackbranch backup.
| Target | Address | Notes |
|---|---|---|
| This server | none | Backups go to /opt/blackbranch/backups/. Simple, but they are lost with the server or its disk. |
| A storage bucket (S3-compatible) | s3:https://<endpoint>/<bucket>, optionally followed by /<folder> |
Backblaze B2, Cloudflare R2, Wasabi, Amazon S3 and others. Create the bucket at the provider before the first backup: Black Branch never creates one. The endpoint must have a certificate browsers trust. Give the access key id, the secret key, and a region if the provider asks for one (R2: auto). |
| Another server over SFTP | sftp:<user>@<host>:/<folder> for a folder counted from that server's root, or sftp://<user>@<host>:<port>/<folder> for another port, where the folder is inside that account's home |
Run sudo blackbranch backup key (or press Show this server's key in setup) and add the printed line to that account's ~/.ssh/authorized_keys. The other server's own key is trusted the first time and remembered. |
Only s3:https:// and sftp: addresses are accepted. An address that points back at the server itself, its private network or a local address is refused. The bucket's keys are stored encrypted, and are never put on a command line.
Recommended: use a storage bucket at a different company from your server's provider. Then one company's outage or account problem cannot take your site and its backups at once. Give the bucket's key access to that one bucket only.
When backups run, and how you know
- Every night at the quiet hour, a backup.
- Every Sunday, half an hour later, a restore check of the newest one.
- Before every update, a backup of its own, made after the site stops so nothing written during the update's preparation is lost.
Results show on the Doctor's Backups rows and in sudo blackbranch status. When the nightly backup or the weekly check fails, or no good backup has been made for 36 hours, the server sends an alert to the ntfy topic or email command you set (Alerts from the server). Without one, the result waits on those pages for you to look (see A routine for you).
To back up right now:
sudo blackbranch backup
It prints the snapshot id and what was written, or BACKUP FAILED: and why.
To list the snapshots at the target, with their ids and times:
sudo blackbranch backup list
Checking a backup without touching anything
sudo blackbranch restore latest --verify
This is what the weekly check runs. It restores the newest snapshot into a throwaway container that cannot reach the live data, loads the three databases into a separate database there, and checks:
- each part's fingerprint against the manifest, and each database's table count;
- that one stored platform sign-in decrypts with the snapshot's own key ("none stored yet" is not a failure);
- that the homeserver's signing key and the sign-in service's keys are there and unchanged;
- that the snapshot's
.envholds the secrets a restore needs; - that the media came back whole. If the disk has no room for all of it, it checks a sample and says so.
A damaged snapshot is reported clearly, with VERIFY FAILED: naming what is wrong. A damaged backup cannot be mended: make a new one with sudo blackbranch backup and check that.
Restoring a backup
To take the same server back to an earlier state, restore the newest snapshot:
sudo blackbranch restore latest
Or use a snapshot id from sudo blackbranch backup list in place of latest.
- It asks you to type your domain, so a restore never happens by accident.
--yesskips the question, for scripts. - It reads the snapshot and checks it before changing anything. It refuses a snapshot of another domain, and one made with different secrets from this server's
.env. - It stops the site, the chat and ingest services, and the homeserver.
- It replaces the three databases, and puts back the media, the signing key, the sign-in service's keys and the tunnel's files.
- It starts everything again, applying any database change newer than the snapshot.
⚠ Everything written after that snapshot is gone: messages, sign-ups, payments recorded, settings changed. A payment made at Stripe or PayPal after the snapshot still happened there. The site learns about it again only if the payment service resends the event.
If a restore stops part-way (a full disk, a lost connection to the bucket), it says exactly what was and was not done. The site stays stopped. Run the same restore again.
Restoring onto a new server
If the old server and its .env are both gone, you need only the backups and the passphrase from your recovery sheet. You install a new server with the same domain, then restore with --with-env, which brings back your old .env too. The full steps are on Moving to a new server.
For a restore without anyone at the keyboard, the passphrase can come from BB_RECOVERY_PASSPHRASE, and a bucket's keys from BB_S3_ACCESS_KEY_ID and BB_S3_SECRET_ACCESS_KEY (and BB_S3_REGION).
Two things nothing can replace
- The backup passphrase. Without it no backup can be opened, by anyone. It is in
.envand on your recovery sheet. Keep the sheet off the server. - The homeserver's signing key. It is in every backup, so as long as you have a backup and its passphrase, you have it.
Encrypted messages
A backup cannot open anyone's end-to-end encrypted messages, and nothing you hold as the operator can. After a restore, encrypted messages come back still locked, and each member reads them again with a device that still holds their keys or with their own recovery key. What this means for you and your members is on Encryption.
Next: Updates and rollback