---
title: luna export
description: Write an environment's lunas, as they are now or as they were at an earlier moment, to an archive of SQLite files and file contents.
related:
  - /develop/export-and-import
  - /cli/import
---

`luna export` writes the lunas of an environment to an archive on this machine. Each luna is a plain SQLite database, readable without Luna.

```bash
luna export --out backup.tar.zst
```

## Reference

```bash
luna export [OPTIONS] --out <OUT>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--out <OUT>` | path | Required | The archive to write, a `.tar.zst` file. |
| `--type <LUNA_TYPE>` | text | Every type | Exports only the lunas of this type. |
| `--at <AT>` | moment | Now | Exports the lunas as they were at this [moment](/cli#moments). |
| `--dir <DIR>` | path | `.` | The app's folder. Its env file names the project and environment. |
| `--env <ENV>` | text | `LUNA_ENV`, then `production` | The environment to export. |
| `--project <PROJECT>` | text | `LUNA_PROJECT` | The project, by name or as `organisation/project`. |
| `--tenant <TENANT>` | text | The environment's own | A tenant added to the environment, by name. |
| `--token <TOKEN>` | text | `LUNA_TOKEN`, then your login | An API token or account key to act with. |

## Good to know

The archive is a tar file compressed with Zstandard. It starts with `luna-export.json`, and then holds a folder for each luna.

| Path | Holds |
| --- | --- |
| `luna-export.json` | The archive's format, the environment it came from and the moment it shows |
| `<TYPE>/<HASH>/key.json` | The luna's key, as JSON |
| `<TYPE>/<HASH>/db.sqlite` | The luna's SQLite database |
| `<TYPE>/<HASH>/parts/<ID>` | The contents of the luna's files |

- `<HASH>` is made from the luna's key, so the folder name is safe whatever the key holds. Read the key from `key.json`.
- Exporting needs `data:read` on the environment.
- [`luna import`](/cli/import) creates lunas from the archive.

## Examples

### Export an environment

```bash
luna export --env production --out production.tar.zst
```

### Export one luna type as it was yesterday

```bash
luna export --type List --at "24h ago" --out lists.tar.zst
```

### Read a luna's database with SQLite

```bash
tar --zstd -xf production.tar.zst
sqlite3 List/<HASH>/db.sqlite .tables
```
