Export and import
Write an environment's lunas to an archive of SQLite files and objects with luna export, and load them into another environment with luna import.
Luna keeps each luna’s history for a limited time, and only inside Luna. Sometimes you need a copy that you hold yourself, or that you can open with other tools.
An export writes the lunas of an environment to one archive file on your machine. An import makes lunas from that archive in an environment of your choice.
Export an environment
luna export writes every luna of the folder’s environment to the file you name.
luna export --out backup.tar.zst
It covers each luna type that the environment’s code defines. Pass --env to export another environment, and --tenant <NAME> to export a tenant added to it.
Exporting reads every luna, so it needs the data:read permission on that environment.
Export one type or an earlier moment
Pass --type to export the lunas of one type only.
luna export --out lists.tar.zst --type List
Pass --at to export the lunas as they were at a moment in the past. It takes the same forms as luna restore --to, such as "2h ago" or 2026-11-30T09:00:00Z.
luna export --out before-deploy.tar.zst --at "2h ago"
A luna that did not exist yet at that moment is left out of the archive.
What the archive holds
The archive is a tar file compressed with zstd. It holds plain files, so you can read it without Luna.
| Path | Holds |
|---|---|
luna-export.json |
The archive’s format and the moment it was taken |
<TYPE>/<HASH>/key.json |
One luna’s key, as JSON |
<TYPE>/<HASH>/db.sqlite |
That luna’s tables, as a SQLite database |
<TYPE>/<HASH>/parts/<ID> |
The stored bytes of that luna’s files |
Each luna gets a folder named after a hash of its key, so any key makes a safe path. Read its key.json to see which luna it is.
tar --zstd -xf backup.tar.zst
Any SQLite tool then opens a luna’s db.sqlite. Beside your own tables, it holds tables Luna uses for itself, whose names start with _luna.
Import an archive
luna import makes a luna in the folder’s environment for each luna in the archive.
luna import backup.tar.zst --env staging
The environment must run code that defines each luna type in the archive. Deploy to it first, or make it with luna env create --from.
Every key in the archive must be free in that environment. Importing onto a luna that exists is refused, and the command stops there.
Importing writes lunas, so it needs the data:write permission on that environment.
What an imported luna starts with
An imported luna starts with the tables and files from the archive. It starts with no messages, connections or subscriptions, as a fork does.
Schedules do not carry on unless you pass --schedules. With it, they carry on without catching up on runs they missed.
luna import backup.tar.zst --env staging --schedules
Uses for an export
- A backup you keep. History inside Luna reaches back a limited time, and a deleted environment takes its history with it.
- Another project. Pass
--projecttoluna importto load the lunas into a project of your own choosing. - A look with other tools. Open a luna’s
db.sqlitewith any SQLite tool to read or check its data.
Next steps
- Fork a luna copies one luna, sandboxes included, without a file in between.
- Restore to an earlier moment rewinds lunas in place instead.
- Manage environments copies a whole environment’s code and data with
luna env create --data.