On this page
Data safety
Ozone must never lose an app's data. This page is the contract and the reasons behind the code
that keeps it. Read it before changing apps/server/src/ozone/runtime, apps/server/src/ozone/data
or apps/server/src/ozone/deploy.
The contract
-
Data lives in named volumes. A template's stateful service keeps its data in a named Docker volume labelled
ozone.data. Nothing stateful lives in a container layer or an anonymous volume, so removing and recreating containers loses nothing. -
Two code paths remove a volume, and a person starts each. Every Docker command goes through
DockerCli, which refusesvolume rm,volume prune,system prune --volumesandcompose down|rmwith-v, on this machine or a server. A refusal is a defect, not an error to handle: reaching it means new code asked for something Ozone must not do. Start, stop, restart, rebuild and deploy therefore keep the data by construction. The two exceptions each take a snapshot, remove the containers, and only then ask the guard to let go of the volumes that snapshot holds:- Delete app:
AppData.remove, for development's volumes on this machine. - Delete deployment:
AppDeploy.removeDeployment, for one production place, on this machine or a server.
A test scans the server for the flag and finds exactly those two. Each Compose project is named from the app's slug (
<slug>,<slug>-prod), never read from a compose file: agents can edit that file, and neither path may reach another project, such as Delete app reaching the app's production one. - Delete app:
-
Snapshots live outside the app.
AppDatawrites them under the server's state directory, inozone/backups/<app slug>/<snapshot id>/. They survive the app's containers, its volume, its checkout and the app's own deletion. -
Restoring and deleting are a person's decisions. They are offered on the app's page and in its menus, and a deployment's delete also in Settings, Servers. No MCP tool restores or deletes data. A restore first snapshots the data it is about to replace, so it can be undone. A deleted app leaves its last snapshot, its folder and a record beside the snapshot, and Home brings it back from those: a project for the folder, the same slug, and the snapshot loaded before the app first starts. Volumes still in Docker are newer than any snapshot and are left as they are. Once confirmed, a restore or a deletion runs to its end in the server's own fiber: a window closed halfway must not leave a database dropped and empty. While one runs, every start and stop of the app waits for it, so an agent's restart cannot run the app on a database just dropped.
-
A migration that can lose data runs only when a person applies it. The check lives in each app's own migrate command (
src/db/migration-guard.ts), because every path runs that command: the container's start, and so every restart, rebuild, settings change and restore; an agent's./dev npm run db:migrate; a build's check; and production'smigratestep. It holds back a pending migration with a statement thatfindDestructiveStatementsflags, applies nothing, and writes.ozone/migrations.json. The app's banner shows it, and Apply after a snapshot takes a snapshot and runs it with a token naming the exact SQL the person saw, once. No MCP tool can apply it, and a build's lead cannot accept such a task until the person has. A test keeps the app's copy of the rules and Ozone's the same.
Why a restore drops the database
pg_restore --clean only replaces objects that are in the dump. A table created after the snapshot
would survive, while the migration journal went back in time, and the next start would fail trying
to create that table again. Restoring into a freshly created database gives exactly the state the
snapshot recorded. The app's service is stopped for the duration so nothing writes in between.
Going back in History
AppHistory takes an app back to an earlier
commit with the data of that time: the newest snapshot taken at that commit. It never rewrites
history. Uncommitted changes are committed first. The app is stopped, the data is restored (its
safety snapshot is filed under the commit being left, which is the data that belongs with it), the
old tree is committed as a new commit, and only then does the app start: started on the newer
code, it would migrate the restored data forward. Going back is therefore undone by going back to
the commit before it.
Build tasks whose commits the restored point lacks go back into their plans, and come back as done
when a later restore brings their commits back. A restore is refused while a build is working.
Production
AppDeploy treats production's data as another
target of the same snapshot code. Every deploy after the first to a place saves it before its
migrations run, and the app's Data page takes and restores snapshots of it. A restore runs the deployed
version's migrations afterwards, because that version expects its own schema whatever the snapshot
had. A first deploy to a new place can start from the data of the place before: that data is
saved, loaded into the new database before the app starts, and the old deploy is stopped with its
volume left in place. Each command runs against an export of the commit that is deployed, never the
working tree. An app whose production is running cannot be deleted until a person stops it or
deletes that deployment.
Settings, Servers lists every deployment on record (ozone/apps/<slug>/deploy.json): where each
app runs and where it ran before, deleted apps included, with what each machine holds now. Servers
are only asked about those projects, never searched. Delete deployment works where Ozone runs
the containers. It asks the machine what is there, refuses with nothing removed when the machine
does not answer, saves the data to backups/<slug>/production/ (a before-delete snapshot, never
pruned), runs compose down --remove-orphans --rmi local, and only then removes the database
volumes that snapshot holds. A deleted app's deployment is reached through the folder its
app.json names, so a folder deleted by hand makes it undeletable from Ozone. The record forgets
the place only after all of that succeeded, so a restore from Home does not bring the deployment
back, and a delete cut short is finished by asking again.
A rollback deploys an earlier commit and keeps today's data unless asked for the data from then. That data is the snapshot the next successful deploy on the same host took just before replacing the version, so it is the data as that version left it. It is loaded after a snapshot of today's data, so the rollback can be undone the same way.
Why the dump is copied, not streamed
Ozone reads command output as bounded text. A database dump is binary and can be large, so
pg_dump writes inside the container and docker compose cp moves the file to the host.
Agents
An agent has a shell and could run docker compose down -v itself, or edit the migrate command
to get past its check. The instructions Ozone writes into every app forbid both, and no Ozone tool
offers either. If it happens anyway, the newest snapshot is the recovery, which is why a snapshot
is taken after every task that passes its checks.
Not covered yet
- Apps made before the migrate command held migrations back still apply them silently. A build
stops on a new one, possibly after a worker applied it. Copying
src/db/migration-guard.ts,src/db/migrate.ts,docker/dev-entrypoint.shand the.gitignoreline from the template upgrades an app. - Only
postgresdata services are snapshotted. A manifest may declare a service of kindvolume, and Ozone runs it, but does not archive it. - Deleting an app's project from the project menu, instead of Delete app, leaves its containers and volumes in Docker until someone removes them by hand.
- A deleted app comes back without its threads: they are deleted with the project.
- A deployed app's data lives in a volume of its own (
<slug>-prod_pgdata) that only Delete deployment removes. Its snapshots are kept apart, inbackups/<slug>/production/, on this machine even when the app runs on a server. A volume no snapshot holds, such as avolumeservice's, stays when a deployment is deleted, and the person is told which. - Deployments Ozone has no record of, such as ones made from another computer, are not listed. A server that no longer answers keeps its rows until it does. Checking a server and starting its proxy were tried over real SSH; a deploy to a server, and moving to one, with scripted Docker only.
- An app deployed through Dokploy keeps its data in volumes Dokploy owns, out of Ozone's reach: Ozone takes no snapshot there, never deletes the Dokploy service, and does not run a migration that can lose data. Backups are Dokploy's.
- An app on a hosting platform (Railway, Render, Koyeb, Vercel) is in the same position: the host keeps the database, Ozone takes no snapshot of it, never deletes the service, the database or the project, and does not run a migration that can lose data. Stopping the app suspends it and keeps everything. Some free plans delete data on their own: Render removes a free database after about a month, and Railway removes a trial's volumes after its credit runs out.
- Routine snapshots, the one after each task and the one before a rebuild, are pruned to the newest 20 per app. A person's own snapshots and the undo points of a restore or a delete are kept until removed by hand.
- Delete app leaves the volumes its snapshot does not hold, such as a
volumeservice's data or a dependency cache, in Docker. They lose nothing and take disk space until removed by hand.