# Export

> Take your app anywhere, or keep a backup: its code, its database as SQL, and a guide to the variables it runs with.

Your app is yours. **Export** packs a project into downloads you can take anywhere: the source code exactly as it was uploaded, the database as plain SQL that `psql` restores into any Postgres, and a guide to every variable the app uses. Use it to move, or just to keep a backup.

```bash
vibiz export                      # code + guide + database, saved here
vibiz export --code -o shop.zip   # just the code (with the guide)
vibiz export --db --csv           # the database as SQL and each table as CSV
vibiz export --secrets            # also the env's values, in their own file (owner key; asks first)
```

In the console: the project's **Export** page (`/projects/<id>/export?env=production`), with what to include, the environment, progress, and the downloads.

## What you get

| File | What it is |
| --- | --- |
| `<slug>-<env>-code.zip` | The source of the live deployment (or the one you pick), as you uploaded it: not the build output. Inside, `VIBIZ-EXPORT.md` and `.env.example`. |
| `VIBIZ-EXPORT.md` | What the app uses on Vibiz (hosting, database, sign-in, payments, email, AI, files, analytics…), how to run it on your computer, and two ways on: host it anywhere and keep Vibiz with one key, or move everything. |
| `.env.example` | Every variable the app has in that environment, with what it is for. **Names only, never values.** |
| `<slug>-<env>-database.sql.gz` | The whole database in one consistent snapshot: schemas, tables, every row, keys, indexes, views, functions, triggers, sequence positions. No owners or grants, so any Postgres user that can create tables restores it. |
| `<slug>-<env>-database-csv.zip` | Optional: each table as a CSV file with a header row. |

Restore the database into an empty Postgres (15 or newer), on any host:

```bash
gunzip -c shop-production-database.sql.gz | psql "$NEW_DATABASE_URL"
```

## Secret values

The values of the variables (database passwords, keys) are never inside an export, so the zip is safe to share with whoever works on the code. The account owner downloads them separately, as a `.env` file for that environment: the **Download .env** button on the Export page (it asks first), `vibiz export --secrets`, or `GET /v1/projects/:id/exports/:exportId/env?confirm=1` with an owner key. Never commit that file.

## Who can export what

| | Agent key | Owner |
| --- | --- | --- |
| Code and the guide (names only) | yes, either environment | yes |
| Development database | yes | yes |
| Production database | no (`owner_only`) | yes |
| Secret values (`.env`) | no | yes, on purpose |

An agent's export defaults to the development environment. An owner's production database export shows up in an agent's list, but without its link.

## Links

Downloads are signed links that work without a key, so they can be opened in any browser or `curl`ed, for **a day**. Then the files are deleted and the export says `expired`: export again for fresh ones. One export runs at a time per project, ten a day. The code is at most 1 GB compressed, the database 2 GB; for a larger database the owner copies it with `pg_dump` and the `DATABASE_URL` from the `.env`.

## Over HTTP

```bash
curl -X POST https://app.vibiz.app/v1/projects/$ID/exports \
  -H "Authorization: Bearer $VIBIZ_API_KEY" -H 'content-type: application/json' \
  -d '{"include":["code","database","env_guide"],"env":"production"}'
# → 202 { "object": "project_export", "id": "exp_…", "status": "queued", … }

curl https://app.vibiz.app/v1/projects/$ID/exports/exp_… -H "Authorization: Bearer $VIBIZ_API_KEY"
```

```json
{
  "object": "project_export",
  "id": "exp_01k…",
  "environment": "production",
  "include": ["code", "database", "env_guide"],
  "status": "ready",
  "files": [
    { "kind": "database", "name": "shop-production-database.sql.gz", "size": 48211, "url": "https://app.vibiz.app/x/exp_01k…/shop-production-database.sql.gz?expires=…&signature=…" },
    { "kind": "code", "name": "shop-production-code.zip", "size": 120533, "url": "https://app.vibiz.app/x/exp_01k…/shop-production-code.zip?expires=…&signature=…" }
  ],
  "url_expires_at": "2026-10-29T10:00:00.000Z",
  "warnings": [],
  "console_url": "https://app.vibiz.app/projects/prj_…/export?env=production&export=exp_01k…"
}
```

`include` takes `code`, `database`, `database_csv` and `env_guide` (default: all there is but CSV). `env` defaults to production for owners and development for agents; `deployment_id` exports another deployment's code. While it runs, `step` and `progress` say where it is. Agents with the MCP server use `vibiz_export` (`start`, then `status`); the SDK has `vibiz.exports.create`, `get`, `waitUntilDone`, `download` and `envFile`.

## Errors

| Code | Status | When |
| --- | --- | --- |
| `forbidden` + `owner_only` | 403 | an agent asked for production data or the `.env` |
| `dependency_not_ready` | 409 | no deployment yet (leave the code out), no database, or no development copy yet (`vibiz dev`) |
| `conflict` | 409 | an export of this project is already running (`details.export_id`) |
| `rate_limited` | 429 | ten exports in a day |
