# Back up and restore

Back up your .env secrets, Postgres database, and SeaweedFS uploads, and restore dimmi onto a fresh server.

A complete dimmi backup has three pieces: `/opt/dimmi/.env`, a Postgres dump, and the uploaded files volume. Store all three off the server.

## What to back up

| Asset | Source | Suggested schedule |
| --- | --- | --- |
| **Config and secrets** | `/opt/dimmi/.env` | Once, and after every `dimmictl set` |
| **Database** | `pg_dump` of `dimmi` | Daily, and before every upgrade |
| **Uploaded files** | Docker volume `dimmi_seaweedfs` | Daily |

Keep `/opt/dimmi/.env` safe: it holds `DIMMI_APP__KEY` (required to decrypt database secrets) plus your database and storage passwords. Valkey stores only cache, rate limits, and realtime messages, so it does not need backups.

Create a database dump:

```bash
docker compose -f /opt/dimmi/compose.yaml exec -T postgres \
  pg_dump -U postgres -Fc dimmi > dimmi-$(date +%F).dump
```

Archive uploaded files:

```bash
tar -czf dimmi-files-$(date +%F).tar.gz \
  -C /var/lib/docker/volumes/dimmi_seaweedfs/_data .
```

## Restore onto a fresh server

1. Copy your backed-up `.env` to `/opt/dimmi/.env` on the new server.

2. Run the [installer](/self-hosting/install/) pinned to the exact release from your old `/opt/dimmi/VERSION` (prefixed with `v`, like `v1.2.3`). It preserves your `.env` so Postgres and SeaweedFS initialize with your existing passwords and `DIMMI_APP__KEY`:

   ```bash
   curl -fsSL https://github.com/dimmihq/dimmi/releases/download/<version>/install.sh \
     | bash -s -- --version <version> --domain support.example.com --email ops@example.com
   ```

3. Stop the stack and restore the file archive:

   ```bash
   docker compose -f /opt/dimmi/compose.yaml stop
   tar -xzf dimmi-files-<date>.tar.gz -C /var/lib/docker/volumes/dimmi_seaweedfs/_data
   ```

4. Start Postgres alone and restore the database dump:

   ```bash
   docker compose -f /opt/dimmi/compose.yaml start postgres
   docker compose -f /opt/dimmi/compose.yaml exec -T postgres \
     pg_restore -U postgres -d dimmi --clean < dimmi-<date>.dump
   ```

5. Bring the full stack back online:

   ```bash
   dimmictl start
   ```

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
