# Backups

A production installation needs regular backups. Two things must be saved: the
**PostgreSQL database** and the **file storage** (uploaded documents).

## Backing up the database

Create a dump with `pg_dump` — in the container installation, directly in the DB container:

```bash
docker compose exec db pg_dump -U lalabase lalabase_production > backup.sql
```

For regular backups, a cron job on the host that creates and versions the dump (e.g. to a
separate storage) works well.

## Backing up file storage

Uploaded files live in the `storage` volume. Save it as an archive:

```bash
docker compose cp web:/rails/storage ./storage-backup
```

<div class="docs-callout docs-callout--warning">
  <div class="docs-callout__title">Consistency</div>
  <p>Back up the database and storage in the same time window — otherwise references to files may point nowhere.</p>
</div>

## Restoring

Load a dump into an empty database:

```bash
cat backup.sql | docker compose exec -T db psql -U lalabase lalabase_production
```

<div class="docs-callout docs-callout--danger">
  <div class="docs-callout__title">Warning</div>
  <p>Test your backups regularly with a trial restore. An untested backup is not a backup.</p>
</div>
