---
title: "Backups"
description: "Scheduled encrypted backups, copies off the server, and a tested restore."
---

Heptapod backs itself up every day at 02:30 UTC. Each backup is a password-encrypted ZIP with a PostgreSQL dump and the uploaded files, such as client logos. Archives land on the `backups` volume of the same server.

A backup on the same server does not survive the loss of that server. Copy archives elsewhere, or point `BACKUP_DISK` at S3-compatible storage.

## See and start backups

Owners see recent archives and the outcome of each run under **Settings → Backups**. They can also start a backup there. The app cannot restore a backup; restoring is a server task.

On the server:

shell

```sh
dc() { docker compose --env-file .env.prod "$@"; }
dc exec app php artisan backup:run --no-interaction
dc cp app:/backups /srv/heptapod-backup-export
```

Restrict the export directory to its owner (`chmod 700`).

## Keep the keys separately

A backup needs three things to be useful: the archive, `BACKUP_ARCHIVE_PASSWORD` and every `APP_KEY` the instance used. Store `.env.prod` in a password manager or another safe place, not only beside the archives.

## Restore

Restore onto a fresh instance with the same release, the same `APP_KEY` and the same archive password, into an empty database. Never restore over live tables.

1. Stop the workers and enter maintenance mode:

   shell

   ```sh
   dc stop horizon dispatcher scheduler
   dc exec app php artisan down
   dc cp /srv/restore/backup.zip app:/tmp/restore.zip
   ```

2. Decrypt the archive inside the container. The password comes from the environment, not from your shell history:

   shell

   ```sh
   dc exec app php -r '$z = new ZipArchive; if ($z->open("/tmp/restore.zip") !== true) { throw new RuntimeException("Cannot open archive"); } $z->setPassword(getenv("BACKUP_ARCHIVE_PASSWORD")); if (!$z->extractTo("/tmp/restore")) { throw new RuntimeException("Cannot decrypt archive"); } $z->close();'
   ```

3. Import the dump and the files. Replace `DUMP.sql` with the file name in `/tmp/restore/db-dumps`:

   shell

   ```sh
   dc exec -T app cat /tmp/restore/db-dumps/DUMP.sql | dc exec -T postgres sh -c 'psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
   dc exec app cp -a /tmp/restore/storage/app/. /app/storage/app/
   dc exec app rm -rf /tmp/restore /tmp/restore.zip
   ```

4. Migrate, leave maintenance mode and start the workers:

   shell

   ```sh
   dc exec app php artisan migrate --force --no-interaction
   dc exec app php artisan up
   dc up -d horizon dispatcher scheduler
   ```

Tip

Test a restore on a separate server before you need one. A readable archive is not proof of a working database.

A failed backup, or no successful backup for 26 hours, shows in **System health** and is mailed to Owners and opted-in Admins. A stopped server cannot report itself; use `INSTANCE_HEARTBEAT_URL` for an independent alert, see [configuration](/docs/running-it/configuration/#watch-the-watcher).
