> ## Documentation Index
> Fetch the complete documentation index at: https://docs.varios-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backup and Restore

> Which data of an on-premise installation must be backed up and how to restore it

All data of an on-premise installation resides in the installation directory, the directory containing `docker-compose.yml` and `.env`. Docker images do not need to be backed up; they are downloaded again during installation.

## What must be backed up

| Directory or file            | Content                                                             |
| ---------------------------- | ------------------------------------------------------------------- |
| `.env`, `docker-compose.yml` | Configuration, credentials, version                                 |
| `Data/Data/Persistent`       | Uploaded files, images, encrypted content, and the installation key |
| `PostgresBackups`            | Daily database backups                                              |
| `traefik`                    | TLS certificates and proxy configuration                            |
| `Web/_Resources`             | Published files                                                     |
| `Data/Logs`                  | Audit, login, and DLP logs for compliance evidence                  |

The directories `Postgres` and `Redis` do not need to be backed up. The running database in `Postgres` is only consistent when stopped; back up `PostgresBackups` instead.

<Warning>
  The database and `Data/Data/Persistent` belong together. The database references files in this directory, and the key stored there is required to decrypt stored content. Always back up both together and close in time.
</Warning>

## Disaster recovery

For recovery after an outage, we recommend **daily snapshots of the entire virtual machine** on your virtualization platform. A snapshot captures the database, files, and configuration in one consistent state and can be restored within minutes. Keep the snapshots on a different storage system than the running machine. Also take a snapshot before every update of VARIOS AI so that you can return to the previous state if problems occur.

The database backup described in the next section complements the snapshots: it allows you to restore individual days or to move an installation to another system.

## Database backup

VARIOS AI creates a full database backup every day at 3:00 a.m. in the `PostgresBackups` directory and keeps the backups of the last seven days. The time is set by `BACKUP_TIME` on the `postgres-backup` service in `docker-compose.yml`.

To start a backup manually:

```bash theme={null}
docker compose exec postgres-backup /usr/local/bin/backup.sh
```

<Tip>
  Copy the installation directory without `Postgres` and `Redis` to another system after each database backup, for example with rsync or your backup software.
</Tip>

## Restore

<Steps>
  <Step title="Install VARIOS AI">
    Install VARIOS AI on the target system in the same version as at the time of the backup. The version is stored in the backed-up `.env` under `VERSION`. Do not start the services yet.
  </Step>

  <Step title="Restore files">
    Copy `.env`, `docker-compose.yml`, `traefik`, `Data/Data/Persistent`, and `Web/_Resources` from the backup into the installation directory. The `Postgres` directory must be empty or absent.
  </Step>

  <Step title="Restore the database">
    Start only the database and import the desired backup:

    ```bash theme={null}
    docker compose up -d postgres
    sleep 15
    gunzip -c PostgresBackups/backup_YYYYMMDD_HHMMSS.sql.gz | docker compose exec -T postgres psql -U <database-user> -d postgres
    ```

    Replace `<database-user>` with the value of `POSTGRES_USER` from your `.env`. Two messages stating that the role and the database already exist are expected and can be ignored.
  </Step>

  <Step title="Start all services and verify">
    ```bash theme={null}
    docker compose up -d
    ```

    <Check>
      Log in, open an older chat with an uploaded file, and check that the file is displayed.
    </Check>
  </Step>
</Steps>

<Note>
  Test the restore regularly on a separate system. Only a successfully restored backup is a backup.
</Note>
