# Back up and restore an instance

Source: https://docs.savorum.app/admin/backup-restore/

> Make a full backup of your Savorum server, check it, and restore it.

A library backup saves your library in one file: recipes, photos, books, tags, history, and the original files you kept from imports. Make one regularly, keep a copy somewhere else, and practice a restore now and then so you know it works.

Choose your deployment method in the tabs. Native commands run as the system user that owns the database and assets folder. If `savorum` isn’t on your `PATH`, use its full path, such as `./bin/savorum`.

Container examples use the container or Compose service name `savorum`. Create `/var/backups/savorum` on the host and give user and group `65532:65532` read and write access. It is mounted at `/backups` in the temporary container. Docker CLI examples read the server’s image ID and reuse its data mounts; Compose examples use the service’s image and mounts.

## Make and check a backup

A copy of the live `.db` file can be incomplete. The `backup` command is safe while Savorum is running.

1. Back up to a folder outside Savorum’s data folder, then verify the file:

   Docker CLIComposeContainer managerNative binary`savorum_image=$(docker inspect --format '{{.Image}}' savorum) &&docker run --rm --read-only --volumes-from savorum \ -v /var/backups/savorum:/backups \ "$savorum_image" backup \ --database /data/savorum.db --assets /data/assets \ --output /backups/instance.savorum-backup &&docker run --rm --read-only --volumes-from savorum \ -v /var/backups/savorum:/backups:ro \ "$savorum_image" verify --input /backups/instance.savorum-backup`

2. Copy the backup somewhere else, such as another disk or a cloud drive, and run `verify` on the copy. For a container, mount the copy’s folder at `/backups` instead.

3. Every so often, practice a restore.

`verify` checks that the file is complete and undamaged, and that this version of Savorum can restore it. It doesn’t change your running server. Verify with the same version you’ll restore with.

**Checksums catch damage, not tampering.** Verifying finds a corrupted backup, but can’t tell who made it. Someone who can replace a backup can replace its checksums too. Protect where you store backups, and only restore one you trust.

## Encrypted backups

Add `--encrypt` to seal the backup, and your webhook signing keys, in one password-protected file. Savorum asks for the password twice, or reads it from `--password-file FILE` (`-` reads standard input), which also turns on encryption:

- Docker CLI
- Compose
- Container manager
- Native binary

```sh
savorum_image=$(docker inspect --format '{{.Image}}' savorum) &&
docker run --rm -it --read-only --volumes-from savorum \
  -v /var/backups/savorum:/backups \
  "$savorum_image" backup \
    --database /data/savorum.db --assets /data/assets \
    --encrypt --output /backups/instance.savorum-backup.age
```

`verify` and `restore` ask for the password, or read it from `--password-file`. The file is an [age](https://age-encryption.org/) file, so the standard `age` tool can decrypt it too.

The password can’t be recovered. Without it, the backup is lost.

## Restore a backup

Restore replaces everything on the target server. Don’t merge restored files into a current assets folder, and don’t use a full backup to bring back selected recipes. Stop the server before restoring. Don’t restore inside a running container.

- Docker CLI
- Compose
- Container manager
- Native binary

Stop the server and use its image and data mounts for verification and restore:

```sh
savorum_image=$(docker inspect --format '{{.Image}}' savorum) &&
docker stop savorum &&
docker run --rm --read-only --volumes-from savorum \
  -v /var/backups/savorum:/backups:ro \
  "$savorum_image" verify --input /backups/instance.savorum-backup &&
docker run --rm --read-only --volumes-from savorum \
  -v /var/backups/savorum:/backups:ro \
  "$savorum_image" restore --input /backups/instance.savorum-backup \
    --database /data/savorum.db --assets /data/assets &&
docker start savorum
```

Open a few recipes and books, check history and the trash, and load some photos.

If you use Connect, [set it up on the replacement server](https://docs.savorum.app/admin/connect/#backups-and-moving-servers).

An encrypted restore also puts back the webhook signing keys. It refuses if `<database>.webhook-secrets` already holds keys.

## Practice a restore

Restore into a new, empty folder or volume, so your real server isn’t touched. With the [source build](https://docs.savorum.app/start/getting-started/#build-from-source-instead):

```sh
./bin/savorum backup \
  --database ./data/savorum.db \
  --assets ./data/assets \
  --output ./data/instance.savorum-backup
./bin/savorum verify --input ./data/instance.savorum-backup
install -d -m 700 ./restore-data
./bin/savorum restore \
  --input ./data/instance.savorum-backup \
  --database ./restore-data/savorum.db \
  --assets ./restore-data/assets
./bin/savorum check-database --database ./restore-data/savorum.db
```

Write down the backup date, the Savorum version, how long it took, and what you checked.

## Move from Savorum Cloud

Savorum Cloud gives the library owner a `.savorum-backup.age` download in the encrypted backup format. It restores with the Savorum command-line tools; it is not a recipe file to import in the app. Keep the password you chose when preparing it. To move it to your own server:

1. Restore the download with its password. This also installs its webhook signing keys.
2. Run `hosting show` and note the `owner_user_id` it prints.
3. Give the owner a local password. Leave out `--login` if the account already has a local login.
4. Release the hosting link. This requires a local administrator with a password.

```sh
savorum verify --input library.savorum-backup.age
savorum restore --input library.savorum-backup.age \
  --database /data/savorum.db --assets /data/assets
savorum hosting show --database /data/savorum.db
savorum user reset-password --database /data/savorum.db \
  --user-id OWNER_ID --login owner
savorum hosting release --database /data/savorum.db
```

Replace `OWNER_ID` with `owner_user_id` from `hosting show`. The password reset asks for a new local sign-in password; verify and restore ask for the backup password. Add `--password-file FILE` or `--password-file -` when running without an interactive terminal.

Releasing turns off the Cloud sign-in and signs out its sessions and tokens. Your recipes, libraries, and roles stay. Then remove the Cloud provider from your [provider file](https://docs.savorum.app/admin/single-sign-on/) if you copied one, set `--public-url` to your own address, and start Savorum with `--auth-enabled`.

Passkeys stay tied to the old address, so they stop working. Sign in with the password, then add new passkeys.

## Good to know

- Webhook signing keys, in the `<database>.webhook-secrets` folder beside the database, aren’t in a plain backup. Back them up separately with the same care, use an encrypted backup, or replace every webhook secret after a restore.
- Resized photos aren’t in the backup; Savorum makes them again. Temporary job files aren’t backed up.
- Backup refuses to start unless the destination has room for about twice the database, plus all original files, plus 512 MiB. `savorum storage --backup-directory DIR` shows the expected size and free space.
- Verify and restore need free space of about three times the database, plus the original files, plus 512 MiB.
- A backup holds the database’s write lock while it copies, so run a large backup at a quiet time.
- Encrypting or decrypting needs about 528 MiB of free memory. A server with 512 MiB refuses before writing anything. Plain backups still work there; open encrypted ones on a machine with more memory.
- `verify` and `restore` accept at most 64 GiB of uncompressed content. For a larger backup you trust, add `--max-expanded-bytes BYTES` to both, such as `--max-expanded-bytes 137438953472`.
- Backup files are readable only by their owner (`0600`). Never make them world-readable. If your server uses [group storage](https://docs.savorum.app/admin/configure/#protect-stored-data), set `SAVORUM_STORAGE_ACCESS=group` for every `backup` and `restore` too. For Docker CLI examples, add `-e SAVORUM_STORAGE_ACCESS=group` before the image name; Compose inherits the service’s environment.
- If a restore is interrupted, start Savorum normally with the same paths so it can finish recovering. **Never delete the lock file, recovery journal, SQLite `-wal` or `-shm` files, or older copies to force it to start.**
