In an installation on your own server, everything that matters is in the database: settings, instructions, knowledge sources, messages, drafts and the encrypted secrets. So you back up the database — and the .env file with the MASTER_KEY.
What to back up
- The database — draften dumps it into the
backups/folder itself (see below); you make sure the dumps get off the server. .env, above allMASTER_KEY— off the server, in a safe place. Without it you cannot read the API keys, mailbox access or sign-in clients from the database; the backup would be useless. We do not have it.
A database dump contains the customers' mail. Protect it like the mailbox itself.
The backups draften takes
draften saves a database dump into the backups/ folder in the installation directory:
- every day — at 01:00 Prague time, or at the time you set under Installation → Installation, in the Database backups card. When the server was off at that time, the backup is taken as soon as it is back. When it fails, it is tried again an hour later and the card shows why.
- on request — with the Back up now button in the same card. Its progress shows under Requests as "Database backup".
- before every update — so that changes to the database can be undone too.
The daily backups and those on request are counted apart from the ones before updates: the last 7 of them are kept, and beside them the last 3 backups from before an update. The card shows the last seven backups — when they were taken, their kind, the version and the size.
The settings can be changed in .env:
| Variable | What for |
|---|---|
DRAFTEN_DAILY_BACKUPS | how many daily backups and backups on request to keep (default 7); 0 turns the daily one off, a backup on request is still taken |
DRAFTEN_BACKUP_AT, DRAFTEN_TIMEZONE | the time of the daily backup and its time zone (default 01:00, Europe/Prague); a time set in the interface wins |
DRAFTEN_BACKUPS | how many backups from before an update to keep (default 3) |
Without the updater
The daily backups and the button are the updater's work. When the installation has no updater running, the same backup is taken by:
./draften backup
For a daily backup, run it from cron, at one in the morning, say (replace the path with your installation directory):
0 1 * * * cd /srv/draften && ./draften backup
The backups in backups/ are not off the server
They lie on the same disk as the database — lose the disk or the server and you lose them too. Copy the backups/ folder together with .env elsewhere, as your other backups do, or back up the whole server after the daily backup (that is, after 01:00 or the time you set).
The backups in backups/ are not affected by the data retention: a dump keeps what the database held when it was taken.
Restoring
Every dump in backups/ carries in its name the time and the version that was running then: <time>-<version>.backup.sql.gz for the daily backups and those on request, <time>-<version>.sql.gz for the ones before an update. Stop the workers, load the dump and start the version from its name:
docker compose stop worker
gunzip -c backups/<dump>.sql.gz | docker compose exec -T db sh -c 'mariadb -uroot -p"$MARIADB_ROOT_PASSWORD"'
./draften update <version> --no-backup
Everything that happened in draften after the dump was taken is lost.
On a new server, install draften first and put the MASTER_KEY from the time the dump was made into .env.
Replacing the encryption key
MASTER_KEY can be replaced without an outage — in the interface (Installation → Installation → Encryption key → Replace the encryption key, needs the updater), or with the command:
./draften rotate-key
The new key is first written into .env, the containers take it one by one and everything stored is encrypted again with it. The old key stays in .env as MASTER_KEY_PREVIOUS as long as backups/ holds dumps from before the replacement — only it can open them. draften refuses another replacement while such a dump exists. Daily backups from before the replacement are gone after 7 days at the latest, backups from before an update only after three more updates.
After the replacement, copy the new .env off the server straight away. The new key never reaches the interface; it is only in .env on the server.
Watch out
- The
db-datavolume is the live database. Never remove the installation withdocker compose down -vunless you have a fresh dump off the server. - The
data/folder does not hold the truth — only the worker's log and reports are there. - You can always check in the interface: the Installation status card on the Installation page shows whether
MASTER_KEYis set, and the Database backups card when the last backup was taken. On the command line,./draften statusshows the same.