Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Scheduled Backups
Backups that leave the box, taken on a schedule by the daemon, with an automatic restore test that proves each one restores.
Restore points (before every package install) and python -m object_backup already existed, but both write to the data directory's own disk: a dead disk or a deleted VM takes them with it. This is the other half. It is off until you name a destination.
Setup
- Give the box a destination outside the data directory: a mounted
disk, an NFS share, or a folder another tool syncs away (rclone, restic, Syncthing, a provider's volume snapshots). Encrypt it (see Encryption).
- Set it in the server's environment file and restart the daemon:
DBBASIC_BACKUP_DESTINATION=/mnt/backup/dbbasic
- Read the daemon's boot banner; it says
Backups: every 86400s, keep 7
(or why the destination is refused). The first backup runs on the daemon's first poll; check /backups (the system dashboard's page) or GET /admin/backups/scheduled a few minutes later.
The destination must already exist. It is never created, because the classic way this fails is an unmounted disk: the mount point is an empty directory on the root disk, and a backup that "succeeds" into it never left the box. A destination on the same filesystem as the data directory is allowed (a synced folder is a legitimate setup) but is reported as a warning everywhere the status is shown.
Settings
| Variable | Default | Meaning |
|---|---|---|
DBBASIC_BACKUP_DESTINATION | unset (off) | Absolute path to write snapshots to. Refused if it overlaps the data or objects directory, does not exist, or is not writable. |
DBBASIC_BACKUP_INTERVAL_SECONDS | 86400 | Time between scheduled backups (minimum 60). A failed run is retried after an hour, or the interval if shorter. |
DBBASIC_BACKUP_KEEP | 7 | How many snapshots to keep (minimum 2). |
DBBASIC_BACKUP_RESTORE_TEST_DIR | system temp dir | Where the restore test makes its throwaway copy. Needs room for one full copy. Refused if it is inside live data. |
DBBASIC_BACKUP_AFTER_COMMAND | unset | A command run after each backup whose restore test passed, with the snapshot's path appended (no shell; split like a shell would). The hook for encrypting or shipping. |
DBBASIC_BACKUP_SCHEDULE (an external timer calling object_backup.py create, described in backup-restore.md) is unrelated and still works.
What a backup contains
Exactly what a runtime backup archive (object_backup) contains, chosen by the same lists and the same skip rules:
- Included:
objects/(object source); from the data directory,
collections/ (every collection's records), schemas/, permissions/ (the policy), state/, logs/, versions/, source_changes/, schema_versions/, record_changes/ (every collection's change log), package_changes/, package_baselines/, reconciles/, file_changes/, files/, user_files/ (the bytes behind every files record), and from identity/ only users.tsv and accounts.tsv (who the users and accounts are, their status and roles).
- Not included:
identity/credentials.tsv(password hashes),
identity/sessions.tsv, identity/api_keys.tsv (token hashes), identity/service_keys.tsv (third-party provider secrets), the exchange private keys (exchange/private/), restore-point archives (backups/), rate-limit state, the environment file, systemd units, virtualenvs, caches, dot-files, lock and temp files. Each snapshot's manifest.json lists the top-level data-directory entries it left out (excluded), so you can see exactly what stayed behind on your box.
The cost of keeping secrets out: a box restored from a snapshot knows its users and roles, but nobody can sign in until credentials are re-issued (a password reset, new API keys, service keys re-entered, exchange keys restored or rotated). That is deliberate. A destination is by definition somewhere else, and the less it holds the less a stolen copy is worth. Back up the environment file and the exchange private keys through your own secret-aware process.
How a snapshot is written
Each run writes a directory dbbasic-snapshot-<UTC timestamp>/ holding objects/, data/ and manifest.json (every file's SHA-256, size and mode; every collection's record count and content hash; the objects tree's hash). It is staged as .partial-dbbasic-snapshot-... and renamed only when complete, so an interrupted run leaves something that is visibly not a backup, and the next run sweeps it away.
Unchanged files are hard links to the previous snapshot, the rsync --link-dest / Time Machine design, using only the standard library. A box with 40GB of uploads writes only what changed each night, every snapshot is still a complete plain tree you can copy back with cp -a, and deleting an old snapshot frees only what no newer one shares. A file counts as unchanged when the live file's inode, size and modification time match what the previous manifest recorded. Links are taken only from a previous snapshot whose restore test passed; after a failed test the next run is a full copy, so a file that rotted at the destination is never linked forward. Where the destination cannot hold hard links (some SMB mounts, FAT disks) every file is copied: slower and bigger, never wrong. Snapshot files are written mode 0600 inside a snapshot directory that is 0700; the original modes are in the manifest and come back on restore.
Consistency
A collection's records.tsv and its change log are captured as a pair under that collection's write lock, the lock every record writer holds while it writes both. The table and its audit trail in a snapshot agree to the row, even while writers are busy. The lock is held only to open the two files; the copy reads from the open files afterwards, which is exact for both storage modes (a classic rewrite replaces the file, and the open copy keeps the old one; an append only adds bytes past the size noted).
What a snapshot is not is one instant across the whole box. Collections are captured one after another, so a write to two collections during the run may appear in only the later one. User file bytes are copied after the files records, so a file deleted during the run can leave a record whose bytes are missing; the restore test names any such record as a warning.
The restore test
After every backup the daemon restores the new snapshot into a throwaway directory and checks it. You can also run it on demand. It:
- reads the manifest and checks its format;
- checks the snapshot holds exactly the manifest's files: none missing,
none of another size, nothing extra under objects/ or data/;
- restores every file with the **same function you would use for a real
restore**, hashing every byte against the manifest;
- checks the restored object source hashes to the manifest's;
- starts a fresh process whose data and objects directories point at the
restored copy, and loads it with the server's own loaders: every collection must load to the record count and content hash recorded when the snapshot was taken, every schema must load, the permission policy must load with the same number of rules, and the users and accounts registries must read the same counts.
It never touches live data: the scratch directory is refused if it lies inside the data or objects directory, the loader process sees only the copy, and the scratch directory is deleted afterwards whether the test passed or failed. The result is written into the snapshot (restore-test.json) and into the status.
What it proves: the bytes at the destination are the bytes that were captured; the restore procedure works; and the server, booting cold on the restored directories, sees the same records, schemas, policy and users it saw at capture time.
What it does not prove: that the destination survives a disaster (a synced folder that never syncs passes every test); that secrets the backup deliberately leaves out can be recovered (they cannot, from here); that every object runs correctly on the restored box (it checks source bytes, not behaviour); that the snapshot is one instant across collections (see Consistency); or anything about a snapshot after it was tested. A full recovery drill on a second machine (below) is still worth doing a few times a year.
Seeing it
/admin/statushasscheduled_backups(last backup and last good
backup with time, size, file counts, duration; last restore test and last passing one; their ages; problems; healthy) and puts any problem in alerts, the list an operator reads first.
- The system dashboard: a Backups tile, a
/backupspage with the
detail and two buttons, and an urgent attention count, backup_problems, shown to admins only.
- The daemon log: a boot line with the settings, and one line per run,
e.g. Backup: dbbasic-snapshot-... -- 1204 file(s), 412.0MB (1198 linked, 6 copied, 3.1MB written) in 9.2s; restore test ok. A failed backup, a failed restore test or a failed after-command is an ERROR line.
healthy is true only when backups are on and nothing is wrong. Each of these is a problem: the last backup failed; no backup has completed yet; the last good backup is older than two intervals plus an hour; the last restore test failed; no restore test has passed yet, or the last passing one is older than two intervals plus an hour; the destination is refused; the after-command failed. A failure is never hidden by an older success. With backups off nothing is raised as an alarm (it is your decision), but every surface says "off" in words.
Back up or test now
# Over HTTP (admin token or an admin session); both answer 202 at once.
curl -X POST -H "Authorization: Token $DBBASIC_ADMIN_TOKEN" https://your-box/admin/backups/scheduled/run
curl -X POST -H "Authorization: Token $DBBASIC_ADMIN_TOKEN" https://your-box/admin/backups/scheduled/test
curl -H "Authorization: Token $DBBASIC_ADMIN_TOKEN" https://your-box/admin/backups/scheduled
# On the box, as the service user, with the service's environment loaded.
python -m object_backup_schedule run # back up now, then restore-test it
python -m object_backup_schedule test # restore-test the newest snapshot
python -m object_backup_schedule status
python -m object_backup_schedule list
Only one run at a time per destination (a lock file at the destination, .dbbasic-backup.lock), so the daemon, the API and the CLI cannot collide.
Restoring for real
- Pick a snapshot whose
restore-test.jsonsays"ok": true(`python -m
object_backup_schedule list` shows which).
- Stop the server and the daemon.
- Move the old directories aside (do not delete them yet), and restore
into empty ones:
sudo systemctl stop dbbasic-object-server dbbasic-object-daemon
sudo mv /var/lib/dbbasic-object-server/data /var/lib/dbbasic-object-server/data.old
sudo mv /var/lib/dbbasic-object-server/objects /var/lib/dbbasic-object-server/objects.old
sudo -u dbbasic /opt/dbbasic-object-server/.venv/bin/python -m object_backup_schedule \
restore /mnt/backup/dbbasic/dbbasic-snapshot-YYYYMMDDTHHMMSSffffffZ \
--objects-dir /var/lib/dbbasic-object-server/objects \
--data-dir /var/lib/dbbasic-object-server/data
The restore hashes every byte against the manifest and stops at the first mismatch. It refuses to replace an existing file unless you pass --overwrite.
- Put back what a snapshot never holds: copy
identity/credentials.tsv,
sessions.tsv, api_keys.tsv, service_keys.tsv and exchange/private/ from data.old if you still have it; otherwise reset passwords, issue new keys and rotate the exchange key.
- Start the services, check
/healthand/admin/status, and look at
representative records before deleting the .old directories.
On a new machine the steps are the same, with the snapshot copied (or mounted) from wherever it was shipped.
Encryption
The Python standard library has no AES, and this server does not invent cryptography. Encrypt at the destination: an encrypted disk or filesystem (LUKS, FileVault, an encrypted cloud volume), or a sync tool that encrypts (restic, borg, rclone crypt). DBBASIC_BACKUP_AFTER_COMMAND is the clean hook for the second: it runs only after the snapshot passed its restore test, receives the snapshot's path as its last argument, and a non-zero exit (or a timeout after an hour) is recorded as a problem like any other. For example:
DBBASIC_BACKUP_AFTER_COMMAND="/usr/local/bin/restic backup --tag dbbasic"
Retention
The newest DBBASIC_BACKUP_KEEP snapshots are kept; older ones are deleted after each run. Retention deletes only its own snapshots: directories named dbbasic-snapshot-<timestamp> whose manifest.json says it was written by this server. Anything else at the destination is invisible to it. It never deletes the newest snapshot whose restore test passed, even beyond the count, so a run of failing tests cannot age out the last good backup. The status file in the data directory keeps the last 30 events.