# Schedule encrypted backups

> Back up both databases and the uploaded files every day into one encrypted archive, keep copies off the server, and restore them with one command.

Source: https://artavolo.com/page/scheduled-backups

On your own server, Artavolo can write one encrypted archive a day that holds everything needed to rebuild the instance: both databases and the uploaded files. It keeps as many days as you choose, locally and in any S3-compatible storage, and one command puts an archive back.

## Set the encryption key first

Set `BACKUP_ENCRYPTION_KEY` in `includes/config.php`, or `ARTAVOLO_BACKUP_ENCRYPTION_KEY` in Docker's `.env`, to 32 or more random characters. Backups are refused until it exists. **Keep a copy of the key away from the server**, in a password manager or a safe: an archive cannot be opened without it, and there is no way round that.

## Turn on the schedule

1. Sign in as an administrator, choose **Control panel** in the account menu, then **Settings**, **Backups**.
2. Tick **Run a backup every day** and choose the hour under **Run from (hour of day, server time)**. Pick a quiet one.
3. Set a **Local folder** outside the web root, ideally a separate disk. Leave it empty to use `data/backups`.
4. Set **Keep backups for (days)**. 0 keeps everything.
5. Leave **Include uploaded files (attachments, avatars)** ticked unless you copy the files another way.
6. For a copy off the server, fill in the S3-compatible section: **Endpoint**, **Bucket**, **Region**, **Key prefix**, **Access key** and the secret key. Hetzner, MinIO, Scaleway, Wasabi and AWS S3 all work.
7. Press **Run a backup now** once, to see a first archive in the list below.

The cron job, which runs every 5 minutes, starts the backup at its first run after the chosen hour.

## Check and restore an archive

Check an archive without touching anything: `php utilities/restore.php /path/to/archive.abk --dry-run`. It verifies it, decrypts it to a temporary folder, lists what it holds and cleans up. Do this every month.

To restore, stop the web server, then run the same command with `--yes` instead of `--dry-run`. It replaces both databases and copies the uploads back. Restore once onto a spare machine now, while nothing is wrong: it is the only way to know the procedure works for you.

## Good to know

- Each archive is encrypted with AES-256 and carries an HMAC-SHA256 tag over the whole file, checked before anything is decrypted. A wrong key or a damaged file is refused, never half-restored.
- A failed run e-mails every administrator. Every run, success or failure, is in the [audit log](https://artavolo.com/page/audit-log).
- The schedule is part of Pro on your own server and needs a licence key that includes it. Without one, `php utilities/backup.php` makes the same archive from the shell in every edition.
- The archive does not hold `includes/config.php` (it has your database passwords and secrets). Keep that file with the key.
- Archives older than the days you keep are removed after each successful run, locally and in the bucket.
- In our cloud we run the backups. A base's own snapshots are under **Settings**, **Backups** in the base: Free keeps 10 per base, Standard 25 and Pro 50.

## Related

- [Install Artavolo on your own server](https://artavolo.com/page/install-artavolo)
- [Apply a licence key](https://artavolo.com/page/apply-a-licence-key)
- [Export your data](https://artavolo.com/page/export-your-data)
- [Backups and restore guide](https://artavolo.com/docs/backups)
