Expand description
Backup, restore and export.
§A backup
One .tar.gz holding, under a manifest.json that comes first:
plm.sqlite— a snapshot of the metadata and the audit log: SQLite’s backup of one read transaction, which the server’s writes do not wait for (WAL);models/<part>/<revision>.json— the document of every revision the snapshot records a hash for;blobs/…— every attachment the snapshot references, and every version of every workspace file;scripts/…— the administrator’s scripts directory (without.git).
The manifest lists every file with its size and SHA-256, and the snapshot’s row counts.
§Consistent while the server runs
The snapshot is one transaction, but documents and blobs are files that a
running server keeps changing: a draft’s document is rewritten, a blob is
removed with its last reference. So a backup is taken OPTIMISTICALLY and
then proven: every document copied must hash to what the snapshot recorded,
and every blob to its name. A mismatch or a missing file means a write
landed in between, and the whole backup is taken again (up to
ATTEMPTS times). A released revision’s document never changes and a
blob is never rewritten, so only drafts written during the copy can cause a
retry. This needs no lock on the server, which is why brep-plm backup
works from another process while serve owns the directory.
A draft saved faster than a backup can be taken (an autosave loop) would
make that retry forever, so after ADJUST_AFTER tries a draft’s
document is taken as copied and the snapshot’s record of its hash and size
set to match: a draft in work at the snapshot, with the document it had a
moment later — a state the store passes through anyway between a CAD save
and its next. The manifest lists each such file under adjusted.
The server’s own backups (the Backups page, --backup-dir) open that
transaction, read what it references and copy the drafts’ documents under
the store’s read lock instead: writes wait for that (not for the copy of
the store, which follows from the same transaction), and nothing is
adjusted.
§A restore
Into an empty (or absent) directory only. Every entry’s path is checked
(no absolute paths, no ..), every file must be in the manifest with the
size and hash it lists, and every file the manifest lists must be present.
Anything wrong removes what was written and refuses.
§An export
Metadata only, for moving to another system: see export_json and the
operator guide’s “Export format” (GUIDE.md).
Structs§
- File
Entry - Last
Backup - One backup this process took (or failed to).
- Manifest
- Saved
Backup - Status
Enums§
- Attempt
- One attempt: snapshot, copy, prove.
Retrywhen a write landed.
Constants§
- ADJUST_
AFTER - After this many tries a draft’s moving document is taken as copied
(
Manifest::adjusted) instead of retrying again. - ATTEMPTS
- How many times a backup is retaken when a write lands during the copy.
- DEFAULT_
KEEP - How many saved backups are kept when
--backup-keepis not given. - EXPORT_
FORMAT - The export format’s
formatfield. - EXPORT_
VERSION - FORMAT
- The manifest’s
formatfield. - PREFIX
- Saved backups are named
brep-plm-<UTC time>.tar.gz. - SUFFIX
- VERSION
- Bumped when the archive’s layout changes.
Functions§
- backup
- Take a backup of
data(with its scripts directory) intoout, a.tar.gz, from outside the server: works while a server is running ondata, retrying when a draft’s document is rewritten during the copy. - backup_
held backup, with the snapshot and the draft documents copied underhold.- export_
json - Every piece of metadata a migration to another system needs, as one JSON
value. Secrets and live state are left out: password verifiers, sessions,
API tokens, sign-in throttles, locks. Documents and attachment bytes are
not included (they are in a backup); each revision names its
document_keyandcontent_hash, and each attachment itssha256. - hash_
file - The lower-case hex SHA-256 of a file, read in pieces.
- is_
backup_ name - Whether
nameis a saved backup’s name — the only names ever joined to the backup directory from a request. - load_
snapshot - Load a data directory’s metadata from a snapshot, without opening the
store — what
brep-plm exportuses, so it works while a server runs. - parts_
csv - One row per part: its identity, catalog, current state and preferred MPN.
- read_
manifest - Read a backup’s manifest without restoring it.
- restore
- Restore
archiveintodata, which must be empty or absent. Returns the manifest. On any refusal, what was written is removed again. - saved
- The saved backups in
dir, newest first. - stamp
YYYYMMDD-HHMMSSin UTC, from Unix seconds.- structure_
csv - One row per uses-list line in the store: the whole assembly structure, flat.
- unheld
- For a caller that cannot hold writes off: just run it.