# Data and secrets

> Where an app keeps data, SQLite on the volume, the optional private database, backups and secrets.

An app keeps data in one of two places: a SQLite file on its volume, or one private database.

## Filesystem

Every file the app writes is kept: a SQLite file next to the code, an `uploads/` folder, a text file. It survives a restart, a sleep and a new deploy, and it is backed up. The app needs no volume path and no change.

| Location | Kept |
|---|---|
| Anywhere the app writes | Yes. Backed up |
| `/tmp` and `/run` | No. Discarded on restart |

- A new deploy replaces the code, not the files the app wrote.
- If the app changed a file at run time that the new deploy also contains, the app's copy wins. `smallrun deploy` lists those paths as `shadowed_paths`.

## SQLite

SQLite is the default choice for a small app. Put the file wherever the app expects it; it needs no manifest field.

## A private database

```yaml
database: postgres
```

- The value is `postgres` or `mysql`. Not both.
- The database is the app's own instance. It runs inside the app's microVM and is shared with no other app.
- The platform creates the database, the user and the password.
- The connection string is injected as `DATABASE_URL`. It points at localhost. Write no credentials.
- An app that expects other names, such as `DB_HOST` and `DB_PASSWORD`, maps them in the manifest: `DB_PASSWORD: ${database.password}`.
- The database is reachable only from the app.
- It is small by design: sized for 5–10 users a day, not for load.

## Backups

- Volumes are snapshotted on a schedule and before every deploy.
- PostgreSQL and MySQL are also dumped.
- One restore command covers all of them.
- A rollback does not restore data. Restore is a separate step.

## Secrets

```sh
smallrun secrets
```

- A `.env` file deployed with the source works as it always did: the app reads it. Whether to deploy it is the agent's choice.
- `smallrun secrets` is optional, for values that should not be in the source. Secrets are encrypted at rest, and the app reads them as environment variables.
- The manifest can refer to a secret as `${secrets.<NAME>}` in `env:`. Never write a password in the manifest as a literal.

---
Source: https://www.smallrun.app/docs/data/ · Index of all pages: https://www.smallrun.app/llms.txt
