For administrators
← All topics

Backup and restore

The daily database backup and one on request, why to copy them off the server together with MASTER_KEY, and how to restore a dump.

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

  1. The database — draften dumps it into the backups/ folder itself (see below); you make sure the dumps get off the server.
  2. .env, above all MASTER_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:

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:

VariableWhat for
DRAFTEN_DAILY_BACKUPShow 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_TIMEZONEthe time of the daily backup and its time zone (default 01:00, Europe/Prague); a time set in the interface wins
DRAFTEN_BACKUPShow 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

Plain text version