Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Backup And Restore
DBBASIC runtime backups protect the object loop by keeping source, state, logs, files, versions, schemas, and collection records recoverable together.
The public backup helper is:
python -m object_backup
It creates a tar/gzip archive with a JSON manifest and a narrow runtime backup set.
Included
Runtime backups include:
objects/
data/state/
data/logs/
data/versions/
data/source_changes/
data/schema_versions/
data/record_changes/
data/package_changes/
data/file_changes/
data/files/
data/schemas/
data/collections/
That covers object source, object state, current logs, rotated compressed logs, source versions, source change history, schema change history, record change history, package change history, object file change history, object-owned files, schema metadata, and TSV-backed collection records.
Excluded
Runtime backups deliberately exclude:
- deployment secrets
- environment files
- systemd service files
- git history
- virtualenvs
- caches
- lock files
- temp files
- ephemeral rate-limit files
The environment file and service unit still need operator-managed backups, but they should be stored through a secret-aware server backup process, not inside the portable runtime archive.
Create
mkdir -p /var/backups/dbbasic-object-server
python -m object_backup create \
/var/backups/dbbasic-object-server/runtime-YYYYMMDD-HHMMSS.tar.gz \
--objects-dir /var/lib/dbbasic-object-server/objects \
--data-dir /var/lib/dbbasic-object-server/data
The command writes dbbasic-backup-manifest.json inside the archive. The manifest records the format version, timestamp, included roots, file count, byte count, and warnings.
Restore Points
Server-side mutations that can rewrite multiple runtime files should create a restore point before writing. Package installs use:
object_backup.create_runtime_restore_point("package-hello-world")
By default, restore points are written under:
data/backups/
Set DBBASIC_BACKUPS_DIR to move those archives to a mounted backup volume or another operator-managed path. Runtime backup archives do not include data/backups/, so restore points do not recursively back up other archives.
Every install writes a full archive by default, which on a large data directory adds up quickly when reinstalling many packages. To share one archive, create it once with POST /admin/backups and name it in each install body: {"allow_replace": true, "restore_point": "<backup id>"}. No new archive is written, and the install's change-log entry records the named one, so POST /packages/{id}/restore still works. An unknown or malformed id is refused (409 / 400) before anything changes. See "Upgrade" in single-vm-deployment.md for the batch recipe.
Package restore uses the recorded restore point from a package install change, not an arbitrary package path. That package-scoped HTTP route (POST /packages/{id}/restore, gated by DBBASIC_ENABLE_PACKAGE_RESTORE) is separate from full-runtime restore, which stays CLI-only. It calls restore_runtime_backup(..., overwrite=True, prune_extra=True) so files created by the package are removed if they were not present in the snapshot. Pruning is limited to the runtime roots; data/backups/ is left alone.
A package restore rolls back the runtime, not the record of what happened. What it does to each runtime root:
| Root | Package restore |
|---|---|
objects/ | rolled back to the snapshot (files added since are removed) |
data/state/, data/files/, data/user_files/ | rolled back |
data/collections/, data/schemas/ | rolled back |
data/package_baselines/, data/reconciles/ | rolled back (they describe the installed packages) |
data/permissions/policy.json | rolled back, only after the policy difference is shown and confirmed (below) |
data/permissions/audit.jsonl and its rotated segments | kept as on disk |
data/identity/users.tsv, accounts.tsv | kept as on disk: a user disabled, or a role removed, since the snapshot stays that way |
data/versions/ (object source versions) | kept; the restore adds a version |
data/source_changes/ | kept; the restore adds a source_rollback, source_create or source_destroy entry |
data/schema_versions/ | kept; the restore adds a version |
data/record_changes/ (and archive/) | kept; the restore adds a create/update/delete entry per row it changed |
data/file_changes/ | kept; the restore adds a file_create/file_update/file_delete entry |
data/package_changes/ | kept; the restore adds restore_requested and rolled_back |
data/logs/ (object logs, rotated logs) | kept |
Every entry the restore adds names who ran it (the actor), when, and the snapshot (package_restore: {package_id, from_change_id, restore_point} in a source or file change's details, and the message Package restore: <id> rolled back to before change <change_id> on versions and record changes). An object source the restore replaces or removes is saved as a version first when no version already holds it, so nothing the rollback overwrote is lost: it can be brought back with the usual source rollback. The response's history gives the counts of entries added and any that could not be written (failed, errors); the runtime is restored either way.
The policy difference comes first
Rolling back can put back an older, looser permission policy: a deny rule added since the snapshot to close a hole would silently disappear. So a package restore is two steps whenever it changes who may do what:
POST /packages/{id}/restorewith{"change_id": "...", "preview": true}
writes nothing and returns policy_diff (every rule added, removed or changed, reordered rules, access mode, admin roles, user roles, role metadata, and the field permissions in data/schemas/), a readable policy_diff_text, and policy_diff_hash.
- The apply, `{"change_id": "...", "confirm": "restore-runtime",
"policy_diff_hash": "<from the preview>"}, recomputes the difference and is refused with 409` if the hash is missing (and the policy changes) or is not the hash of the difference now -- the policy or the snapshot changed since the preview. The 409 carries the current difference and hash; look at it again before sending it back.
Each change is marked loosens (someone may do something they may not do now), tightens, or neutral (labels, reasons), and policy_diff.loosens says whether any change loosens; the error and the text call a loosening restore out in capitals. A change that cannot be proven to tighten counts as loosening: a changed row filter or validity window, rules reordered (the first matching allow wins), any access-mode change other than to role_based. A snapshot without policy.json is compared as the server's default policy, since the restore prunes the live one.
Fail closed: if either policy, or any schema in data/schemas/, cannot be read or parsed, the difference cannot be computed and the restore (and the preview) is refused with 409. Fix or move the unreadable file first.
A restore that does not change the policy needs no hash. The difference and its hash are recorded in the rolled_back package change.
Verify
python -m object_backup verify \
/var/backups/dbbasic-object-server/runtime-YYYYMMDD-HHMMSS.tar.gz \
--json
Verification checks that:
- the archive can be read
- the manifest is present
- the manifest count matches the archive contents
- archive paths stay under
objects/or supporteddata/roots - symlinks, hard links, device files, and other unsafe member types are rejected
Restore
Restore is a deliberate CLI operation, not an HTTP verb. It is destructive and whole-instance, so it is intentionally not exposed on the admin surface (/admin/status reports capabilities.backups.can_restore: false); a "restore" button one misclick from wiping live data is a footgun. The pairing is: download a backup from Scroll or GET /admin/backups/{id}/download to get it, and this CLI to apply it.
Runtime backups live under data/backups/ (or DBBASIC_BACKUPS_DIR) and are named YYYYMMDDTHHMMSSffffffZ-<label>.tar.gz (label manual for on-demand, package-<id> for install restore points). Always verify first (see above).
Dry-run into clean directories first
mkdir -p /tmp/dbbasic-restore/objects /tmp/dbbasic-restore/data
python -m object_backup restore \
/var/lib/dbbasic-object-server/data/backups/20260708T145041382734Z-manual.tar.gz \
--objects-dir /tmp/dbbasic-restore/objects \
--data-dir /tmp/dbbasic-restore/data \
--json
By default restore refuses to overwrite existing files, so this dry run never touches a live runtime. Start the server against the restored directories and check it before trusting the archive:
DBBASIC_OBJECTS_DIR=/tmp/dbbasic-restore/objects \
DBBASIC_DATA_DIR=/tmp/dbbasic-restore/data \
uvicorn object_server:app --host 127.0.0.1 --port 8001
Then verify /health and representative object routes. A real recovery drill should do this on a second clean VM.
Recovering the live runtime
Stop the service first so nothing writes during the restore. Use --overwrite to replace existing files, and --prune-extra (which requires --overwrite) only when you want an exact match to the archive, removing files added since — a powerful, opt-in flag:
sudo systemctl stop dbbasic-object-server
sudo -u dbbasic /opt/dbbasic-object-server/.venv/bin/python \
-m object_backup restore \
/var/lib/dbbasic-object-server/data/backups/<id>.tar.gz \
--objects-dir /var/lib/dbbasic-object-server/objects \
--data-dir /var/lib/dbbasic-object-server/data \
--overwrite --prune-extra --json
sudo systemctl start dbbasic-object-server
curl http://127.0.0.1:8001/health
When --overwrite would change the permission policy (policy.json, or the field permissions in data/schemas/), the CLI prints the difference first -- loosening changes marked, the same classification as the package restore -- and asks for yes on a terminal. Anything else, or no terminal, refuses and restores nothing; pass --yes to apply non-interactively (the difference is still printed, or returned as policy_diff with --json). To see the difference without restoring:
python -m object_backup restore <backup>.tar.gz \
--objects-dir /var/lib/dbbasic-object-server/objects \
--data-dir /var/lib/dbbasic-object-server/data \
--preview # add --json for the structured difference
If either side's policy or a schema cannot be read, the overwrite is refused. Restores without --overwrite cannot replace a live policy and ask nothing. The full CLI restore is disaster recovery: unlike the package restore it does write back the histories, the audit log and the identity registry from the archive.
Pruning is limited to known runtime roots (objects/, data/state/, data/logs/, data/collections/, data/schemas/, data/source_changes/, data/package_changes/, data/file_changes/); data/backups/ is left alone, so restoring never destroys your other archives.
HTTP Surface
On-demand backup and download are exposed on the admin API (and used by Scroll's Backup screen) — see the HTTP contract:
GET /admin/backups— inventory (id,created_at,size,kind,scope).POST /admin/backups— create a full-runtime backup now.GET /admin/backups/{id}/download— stream the archive.
All admin-gated (a backup holds every record, file and user on the box, so never public; password hashes, sessions, API keys and service keys are left out, see the HTTP contract). Restore is deliberately absent from this surface — use the CLI above.
Scheduling
For backups that leave the box, use scheduled backups: set DBBASIC_BACKUP_DESTINATION and the daemon writes a hard-linked snapshot there on an interval, keeps a bounded number, and restore-tests every one, with failures reported in /admin/status, the dashboard's attention band and the daemon log.
The older recipe below still works. The run itself is an external timer (systemd or cron) invoking object_backup.py create on a cadence with retention; DBBASIC_BACKUP_SCHEDULE records the operator's intent so /admin/status and Scroll can display it. A sample daily systemd timer:
# /etc/systemd/system/dbbasic-backup.service
[Service]
Type=oneshot
User=dbbasic
EnvironmentFile=/etc/dbbasic-object-server.env
WorkingDirectory=/opt/dbbasic-object-server
ExecStart=/opt/dbbasic-object-server/.venv/bin/python -m object_backup create \
/var/lib/dbbasic-object-server/data/backups/scheduled-%%i.tar.gz
# /etc/systemd/system/dbbasic-backup.timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
Note that on-box backups do not survive losing the VM — pair them with provider-level disk backups (or copy archives to a bucket) for disaster recovery. On-demand create and download always work regardless of any schedule.