Repository navigation
Backups
OwnMail backs up the whole server, encrypted and incremental, to places
off the server, on a schedule, and can bring back a single mailbox or the
whole server from them. Everything runs inside ownmail serve: no root,
no cron job, no extra container. Mail can also be brought over from the
backups of another server that uses the same format (see
From another server).
| Part | What | Chosen as |
|---|---|---|
ownmail.db |
the database: admins, domains, mailboxes with their password hashes, aliases, DKIM keys (sealed), settings, activity | server settings and accounts, always |
secret.key |
the key that opens the sealed values in the database (DKIM keys, the app password key, backup credentials) | always, with the database |
mail/ |
the mail service's data: every message, calendar entry and contact, its index (mail.db), its last configuration, its own key for two-factor sign-in to mailboxes (secret.key) and the outgoing mail still waiting to be sent (queue/) |
|
tls/ |
the mail host's certificates and its account at the certificate authority | certificates |
The databases are copied with SQLite's VACUUM INTO, so a backup is
consistent while OwnMail runs. Not included: backup-cache/, the admin
socket, backup-target.json and backup-target.key of the command line,
your flags or environment, and the files of imports under way
(mail/imports/: an import still running when a backup is restored has
to be started again). Certificates can be issued again, so they are
the easiest part to leave out.
Because secret.key is in it, a backup is as sensitive as the server.
On the target everything is encrypted with a key of its own (below), so
the storage provider sees only scrambled data.
Backups in the administration's sidebar:
-
Set up backups (or Add place once there is one) opens its own
page (
/admin/#/backups/new), in sections: what the place is for, where the backups go, the connection, and what is backed up. The place can be a Hetzner Storage Box, another server you sign in to over SFTP, S3-compatible cloud storage (Amazon S3, Hetzner Object Storage, Backblaze B2, MinIO, …), or a folder on this server (a mounted disk; it must exist, be writable by OwnMail and lie outside its data directory). Test connection writes, reads back and deletes a small file. The settings are the same as for the command line (Settings); a private SSH key is pasted in. - After the first place, the page shows the recovery key once, with
copy and print. Keep it somewhere other than this server (a password
manager): without it nobody can read the backups, including you. Until
an admin confirms it was saved, it is shown again (also after the next
sign-in); after that never. Only an admin signed in with a password can
see it, and each view is in the activity log
(
backup.recovery_key_shown). Every place uses the same key; OwnMail keeps it only sealed withsecret.key. - Each place has its own page (
/admin/#/backups/<id>, opened by its name or Change settings), with sections for what is backed up, schedule and keeping, the connection, and removing it. In the connection, a saved password, key or secret key is kept when its field is left empty only while it signs in to the same place: changing the server, the lines that identify it, the user name or the folder (another server), or the storage address, region, bucket or access key (cloud storage), asks for it again, so it never goes somewhere new. It has its schedule (daily times in the server's time zone, default03:00; several or none), keeping (by default the newest backup of each of the last 7 days, 4 weeks and 6 months, plus the newest n), and what is backed up (mail and certificates can be left out; server settings and accounts are always in). A backup starts within a minute of its time; one backup runs at a time, others wait. A scheduled backup cut off by a stop or a crash of OwnMail runs again right after the next start, not a day later. After each backup, old ones are removed by the keeping rule. - Back up now starts one at once. The page shows its progress (part, files, bytes, uploaded), the recent runs with the size of each part and the files that had to be left out, and the backups stored there. A place that had no good backup for more than the set number of days (default 3) is marked, and the administrators of the whole server get a mail about it, as they do when a backup fails (see Mails to administrators). A problem is described in plain words; the technical detail is only in the server log, never with credentials.
A place that already holds backups made with this server's key (one that was removed and is added again) is taken as it is. One with backups of another key is refused; add it as a place with backups from another server instead (below). Removing a place keeps the backups on it.
Every change is in the activity log (backup.target_add,
backup.run, …). Access tokens (see MCP) can see backups
and start one, nothing else: they never add, change or remove a place
(where it leads, what it backs up, its schedule and keeping), leave a
mailbox out or see the recovery key. A place receives every mailbox and
the server's key, and backing up less with a short keeping rule would
let the next run remove every backup of the mail.
On a mailbox's page, Backups → Leave out of backups. Its messages,
calendars and contacts are then not read at all; the mailbox itself
(address, password, settings) stays in the database, which is always
backed up, and the mail index keeps its folder names and flags but not
the messages; mail it is still sending (mail/queue/) is backed up with
the rest of the mail. The command line (ownmail backup, ownmail backup-target run) leaves these mailboxes out too. Each run records how
many mailboxes it left out (mailbox.backup_excluded in the activity
log, on or off). Backups made
before keep what they hold. Only an admin signed in with a password can
leave a mailbox out (taking it in again also works with an access token).
On a mailbox's page, Backups → Restore from backup: choose a backup and
a name for a new folder (default Restored <today>). The mail the mailbox
had in that backup comes back below that folder, with its folders, read
and other flags and received dates (Restored 2026-11-30/INBOX, …).
Nothing in the mailbox is overwritten or deleted; messages marked as
deleted in the backup are left out. It runs in the background with its
progress on the page and ends in the activity log
(mail.mailbox.restored, or …restore-failed / …restore-cancelled).
- Offered are the backups of every place that holds mail and was made after the mailbox was created (its mail is kept under an id that is never used again), plus those of places with backups from another server that hold a mailbox of the same address.
- The mail is fetched into
<data>/tmp-restore, packed like Download all mail, and handed to the mail service's own import (quota, message size and free space apply). Messages over 256 MB are left out; a mailbox whose mail is larger than 20 GB cannot be restored this way. Memory stays small: messages over 1 MB pass through a file in that folder, and the backup is read in pieces of at most 8 MB. - Only admins signed in with a password can start it, not access tokens.
- Calendars and contacts of a single mailbox are not restored this way; a whole-server restore brings them back.
Add backups from another server (or the choice on the Add place page) adds a place that holds backups another server made, with that server's recovery key. OwnMail only reads there: it never backs up to it, never removes anything and never changes its keeping. Its backups are listed, and each mailbox's Restore from backup offers those that hold a mailbox with the same address (found in the backup's mail settings), marked as coming from another server.
Some servers write their backups (to a Storage Box, S3 or SFTP) in the same format as OwnMail and keep the mail the same way. Moving mail from such a server to OwnMail is:
- Create the domains and mailboxes in OwnMail (same addresses).
- Add backups from another server with the other server's backup place settings and its recovery key.
- On each mailbox, Restore from backup and choose the other server's backup.
What does not come over this way: mailbox passwords and app passwords, aliases, filters, calendars and contacts (set them up again, or ask people to sign in once and set them). A whole-server restore of such a backup is refused: it holds the other program's database, not OwnMail's.
The same backups can be made without the administration, for scripts or
servers without a browser. In Docker run them in the container
(docker compose exec ownmail ownmail …).
ownmail backup -data /data -out /backup/ownmail-$(date +%F).tar.gz # a local archive
ownmail backup-target init -data /data # once: set up the target, prints the recovery key
ownmail backup-target run -data /data # back up now
ownmail backup-target list -data /data # the backups on the target
ownmail backup-target prune -data /data # remove old ones (7 daily, 4 weekly, 6 monthly)
ownmail backup-target check -data /data [-read-data] # is every backup complete?
ownmail backup-target forget -data /data <id> # remove one backup that cannot be read any more-
ownmail backupwrites atar.gz(mode 0600, never overwrites) withownmail.db,secret.key,mail/andtls/, safe while OwnMail runs.-no-mailleaves the mail out. - Mailboxes left out of backups in the administration are left out here
too (
-exclude-mailboxadds more). -
backup-targettakes-target(default<data>/backup-target.json),-key-file(default<data>/backup-target.key: the recovery key, sealed withsecret.key;initwrites it),-cache(default<data>/backup-cache;""turns it off).runtakes-parts server,mail,certificatesand-exclude-mailbox <storage ids>;prunetakes-keep-last,-keep-daily,-keep-weekly,-keep-monthlyand-dry-run. The recovery key can also come fromOWNMAIL_BACKUP_RECOVERY_KEY. Progress goes to standard error, the id of a new backup to standard output. - These targets are separate from the places set up in the administration; use another folder or prefix for each.
backup-target.json describes the target. It holds credentials: it must
belong to the user running OwnMail (or root) and have mode 0600. Unknown
fields are refused. Every field except host_keys and
private_key_file can be overridden as OWNMAIL_BACKUP_<FIELD> (for
example OWNMAIL_BACKUP_SECRET_ACCESS_KEY).
| Field | Type | |
|---|---|---|
type |
all |
s3, sftp or local
|
endpoint |
s3 | base address, empty for Amazon S3; https:// (http:// only on 127.0.0.1/localhost) |
region, bucket
|
s3 | required; prefix optional (a folder in the bucket) |
path_style |
s3 |
true for MinIO and bucket names with dots |
access_key_id, secret_access_key
|
s3 | the access key |
addr, user
|
sftp |
host:port (22 if left out) and the user |
password or private_key_file (+ private_key_passphrase) |
sftp | how to sign in |
host_keys |
sftp |
required: the server's public keys (ssh-keyscan -p 23 host), so nobody in between can pose as it |
root |
sftp | optional folder (must exist) |
dir |
local | absolute path of an existing folder |
{"type": "sftp", "addr": "u12345.your-storagebox.de:23", "user": "u12345",
"password": "…", "host_keys": ["[u12345.your-storagebox.de]:23 ssh-ed25519 AAAA…"], "root": "ownmail"}Needs only the target's settings and its recovery key: the old server and
its secret.key may be gone. For places set up in the administration,
write their settings into a backup-target.json as above.
-
Stop OwnMail (
docker compose stop ownmail). The restore refuses to run while OwnMail runs on that data directory:ownmail serveholds a lock on<data>/ownmail.lock(and answers on its admin socket), and the restore holds that lock while it writes, so OwnMail cannot start on a half-restored directory. -
Restore into the data directory (an empty volume, or the old one with
-move-aside):ownmail restore -data /data -target /data/backup-target.json -list ownmail restore -data /data -target /data/backup-target.json -snapshot latest
In Docker, with the container stopped:
docker compose run --rm ownmail ownmail restore -data /data -target /data/backup-target.json -snapshot latest(copy the settings file into the volume first, or mount it). -
Start OwnMail again and sign in with an admin of the backup.
What it does:
- The recovery key comes from
-recovery-key-file, elseOWNMAIL_BACKUP_RECOVERY_KEY, else it is asked for (not shown while typing), or read from the first line of standard input. -
Never overwrites. If
ownmail.db,secret.key,mailortlsexist, it stops and names them; with-move-asidethey are renamed to<name>.before-restore-<UTC time>(a database with its-waland-shm). Delete those once the restored server runs. Stale-wal,-shmand-journalfiles are removed so SQLite does not apply them. -
-no-mailleaves the mail out (it is not downloaded either). - It leaves the file
mail/restored: the mail service renumbers every folder at the next start, so mail programs load them again instead of showing messages that are not there any more; calendar and contacts programs sync everything again. Mail that arrived after the backup is lost unless the sending servers deliver it again. - A mailbox left out of backups comes back without its mail, calendars and contacts.
- Everything from the target is treated as untrusted: files are written only below the part they belong to, never below a link, and links that lead outside their part are refused before anything is written.
- A backup made by a different program is refused (see From another server).
The format on a target is fixed; it is format version 1 of an earlier version, unchanged (#9):
| Name | What |
|---|---|
config |
format version, a random id and the data key, encrypted with the recovery key |
objects/<2>/<64 hex> |
file contents in pieces of at most 8 MiB, and the pages of the file lists; each encrypted on its own |
snapshots/<UTC time>-<id> |
one per backup: the parts and the pages that list their files |
locks/<id> |
present while a backup or clean-up writes |
- The recovery key is 32 random bytes shown as 11 groups of 5 letters and digits with a check sum. A random data key encrypts everything with AES-256-GCM, each blob bound to its name; names of pieces are keyed hashes of their content.
- Incremental: a piece on the target already is not uploaded again; the
file lists are cut into pages so unchanged stretches give the same
pages. A cache in
<data>/backup-cache(names, sizes, times, inode numbers, no content) saves hashing unchanged files again; deleting it only makes the next backup slower. - Safe to interrupt: the snapshot is written last, after checking every piece it needs is there; a backup that stops leaves only unused pieces, which the next clean-up removes. A lock left by a crashed run is taken over after 30 minutes.
- Files that cannot be read, disappear or change while read, and special files, are left out and listed with the backup; everything else is saved.
This wiki is copied from docs/ in the repository; changes go there, in a pull request.