Docs Self-hosting
Backups
Back up APP_KEY and the .env file, the database and the storage volume of a Docker instance.
Back up three things: the .env file with APP_KEY, the MySQL database, and the storage volume. The app has no backup command. Use the Docker commands on this page or your own tools.
What to back up
| Item | Where | Why |
|---|---|---|
.env, with APP_KEY |
The folder of docker-compose.yml |
APP_KEY decrypts the secrets in the database. |
| The database | The mysql volume |
All accounts, contacts, campaigns, statistics and settings. |
| The uploaded images | The storage volume |
The public disk and the MaxMind database. See Storage. |
The redis volume holds the queued jobs, the cache and the sessions. Laravel writes failed jobs to the failed_jobs table of the database.
APP_KEY
BYOMailer encrypts these values with APP_KEY:
- The AWS access key and secret key of each account.
- The bucket keys in the storage settings of each user.
- The secret of each webhook endpoint.
- The two-factor secret and the recovery codes of each user.
The setup token of /setup also comes from APP_KEY.
Warning: Keep a copy of APP_KEY outside the server. If you lose the key, BYOMailer cannot decrypt these values. Every account must then enter its AWS credentials again.
To change APP_KEY, put the old key in APP_PREVIOUS_KEYS. This variable is a comma-separated list. Laravel then also decrypts values with the old keys.
Back up .env
- Copy
.envto a safe place outside the server, for example a password manager or an encrypted backup. - Make a new copy each time that you change
.env.
Back up the database
The mysql service has the environment variables MYSQL_ROOT_PASSWORD and MYSQL_DATABASE. This command uses them and writes the dump on the host:
docker compose exec -T mysql sh -c 'exec mysqldump --single-transaction --no-tablespaces -uroot -p"$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE"' > byomailer-$(date +%F).sql
-Tturns off the terminal, so the output is a clean file.--single-transactionmakes a consistent dump of InnoDB tables while BYOMailer runs.- The single quotes make the shell of the container read the variables, not the shell of the host.
Back up the storage volume
docker-compose.yml mounts the volume at /var/www/html/storage/app in the web service. This command writes a compressed archive on the host:
docker compose exec -T web tar -czf - -C /var/www/html/storage/app . > byomailer-storage-$(date +%F).tar.gz
Before an update
Back up the database before you update BYOMailer. The web service runs the new migrations when it starts. See Upgrading.
Restore
The app has no restore command. Restore with the Docker commands below, in this order. The procedure stops the app services during the restore, so it does not use maintenance mode. While the web service is stopped, the reverse proxy answers with an error.
byomailer-2026-11-24.sql and byomailer-storage-2026-11-24.tar.gz are the backup files. Use the names of your files.
-
Put the
.envfile of the backup in the folder ofdocker-compose.yml. It must have theAPP_KEYof the backup. -
Stop the app services. MySQL and Redis continue to run:
docker compose --profile ses stop web horizon scheduler ses-events -
Remove the database and create it again, empty. The grants of the database user stay:
docker compose exec -T mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "DROP DATABASE IF EXISTS $MYSQL_DATABASE; CREATE DATABASE $MYSQL_DATABASE"' -
Load the dump:
docker compose exec -T mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE"' < byomailer-2026-11-24.sql -
Erase the Redis data. The queued jobs and the cache refer to rows that the restore replaced. If they stay, the workers can send email again or update the wrong rows:
docker compose exec redis redis-cli FLUSHALL -
Extract the storage archive into the
storagevolume:docker compose run --rm --no-deps -T --entrypoint tar web -xzf - -C /var/www/html/storage/app < byomailer-storage-2026-11-24.tar.gz -
Start the stack:
docker compose up -dIf you run the SES events worker, start it with
docker compose --profile ses up -d. -
Wait until
docker compose psshows thewebservice as healthy. -
Sign in, and open a newsletter and Settings > Email Credentials. Make sure that the data and the AWS credentials show.
FLUSHALL also ends the web sessions, so each user signs in again. The SES events that arrived during the restore wait in the SQS queue. The worker reads them after step 7.
These rules come from the code:
- Restore the same
APP_KEYthat was in use when you made the database backup. If you use a new key, put the old key inAPP_PREVIOUS_KEYS. - The
webservice runs the migrations when it starts. A dump from an older version gets the new migrations at the next start.