# Backup and recovery

> What a recovery set holds, how to take one and how to restore an installation from it.

Source: https://docs.corfedo.ai/operate/single-host/backup-and-recovery/

A recovery set is a copy of the installation taken while every service is stopped. The installer takes one before each update to a new release and rolls back to it when the update fails. `backup` takes one at any time.

## Take a recovery set

```sh
sh ~/corfedo/install.sh backup
```

Corfedo stops while the set is written and starts again afterwards. Run it when a few minutes without Corfedo are acceptable. To back up on a schedule, run it from cron.

**Check:** the installer prints `The recovery set is backups/<time>-backup.`

If writing the set fails, Corfedo starts again and the incomplete set stays as `<time>-backup.partial`. `restore` refuses it. Remove it with `cleanup`.

## What a recovery set holds

- The installation directory without `backups/`: `.env`, `generated/` with keys and certificates, the releases and your `compose.override.yaml`.
- The data volumes: PostgreSQL for Corfedo and the account service, the index storage and Caddy's certificates.

Engine caches and the indexer's repository copies are left out. They are rebuilt after a restore.

Sets live in `~/corfedo/backups/`. `cleanup` lists them.

## Restore a recovery set

List the sets with `cleanup`. It prints each as `recovery-set:NAME`. Pass the name after `recovery-set:` to `restore`:

```sh
sh ~/corfedo/install.sh cleanup
sh ~/corfedo/install.sh restore 20261122T101500Z-0.3.1-to-0.3.2
```

`restore` asks for confirmation, restores the set and starts the release it was taken from. The data goes into new Docker volumes, numbered as the next data generation. The current directory is kept as `~/corfedo.previous-<time>`, and its volumes stay.

**Check:** the installer prints `Restored` with the new data generation, and `status` says `Ready.`

Restoring an older set loses every change made since it was taken, in Corfedo and in the account service alike. Members, repositories, conversations and audit entries created after it are gone.

## Keep a copy off the host

Recovery sets stay on the Docker host. To survive the loss of the host, copy `~/corfedo/backups/` to other storage after each update and backup. `restore` also takes the absolute path of a set, such as one copied back. It restores into an existing installation, so install Corfedo on a new host first. The set brings its own `.env`, so the address and sign-in settings come from the set, and DNS for the address must point at the new host. A recovery set holds keys, passwords and your code's indexes, so store the copy as you store secrets.

## Remove old sets and generations

After a restore, the earlier data generation and the replaced directory stay until you remove them. See [Cleanup and uninstall](https://docs.corfedo.ai/operate/single-host/cleanup-and-uninstall/).

## Related

- [Update](https://docs.corfedo.ai/operate/single-host/update/) takes a recovery set each time.
- [Cleanup and uninstall](https://docs.corfedo.ai/operate/single-host/cleanup-and-uninstall/) removes old sets.
