Restore to an earlier moment
Rewind one luna, every luna of a type or a whole environment to how it was at an earlier moment with luna restore.
A bad deploy or a wrong edit can write bad data into many lunas before anyone notices. Luna keeps each luna’s history, so you can put its data back as it was at a moment before the mistake.
Restore one luna
luna restore takes a luna type, a key as JSON, and the moment to go back to.
luna restore List --key '{"id":"groceries"}' --to "1h ago"
It asks before it changes anything. Pass --yes to answer in advance, as a script must.
Restore a luna type or an environment
Leave out --key to restore every luna of a type. Leave out the type as well to restore every luna in the environment.
luna restore List --to "2026-11-30T09:00:00Z"
luna restore --to "2h ago"
The restore acts on the environment the folder uses. Pass --env production to make sure it reaches the one you mean.
Luna restores the lunas a page at a time, and --limit sets how many go in each page. A luna that fails to restore is named with its error, and the command exits with an error. Run it again for those.
Write the moment
--to takes a moment in the past, in any of these forms.
| Form | Example |
|---|---|
| A time ago | "30m ago", "2h ago", "7d ago" |
| A date and time | 2026-11-30T09:00:00Z |
| Milliseconds since 1970 | 1796029200000 |
The units are s, m, h and d. The word ago is optional, so 24h means 24 hours ago.
How far back you can go
Luna keeps 30 days of each luna’s history. A moment older than that is out of reach. Limits lists what your plan keeps.
What happens to data written since
The luna’s tables and files go back to how they were. The restore is itself kept in the luna’s history, so you can undo it by restoring to a moment shortly before you ran it.
The restore waits for the handlers already running in the luna to finish. Calls that arrive meanwhile wait for it, then run on the restored data.
| Since that moment | After the restore |
|---|---|
| Messages the luna already handled | Stay handled, and do not run again |
| Messages still waiting for the luna | Are kept and delivered |
| Messages the luna had queued to send | Are sent only if they had not gone already |
| Schedules that came due | Do not run again to catch up |
| A durable run that was unfinished at that moment | Carries on from there |
| Its connections | Are kept as they are now |
Lunas that listen to its table changes are sent its rows again, so they match the restored data.
Lunas made after that moment
A luna that did not exist yet at that moment is left as it is, not deleted. The command counts those as lunas it left alone.
To remove such lunas, have a handler call ctx.destroy() in each, as The life of a luna shows.
Next steps
- Fork a luna copies a luna as of a moment, without changing it.
- Export and import keeps a copy of an environment outside Luna.
- Browse a luna’s data fixes a single value instead of rewinding.