Expand description
Shared helpers for interacting with the kopia CLI.
Used by bestool-tamanu (for the kopia_backup doctor check) and by
bestool (for the bestool kopia subcommand suite). Has nothing
tamanu-specific in it.
Highlights:
find_kopia_binary/find_windows_kopia_binary/find_windows_kopia_config: locate kopia and (on Windows) the per-user repository config from KopiaUI’s standard install locations.linux_elevation: decide whether/how to elevate to thekopiasystem user on Linux. ReturnsElevation::Sudowhen we’re not the kopia user and the system kopia install is present,Elevation::Directwhen we already have access,Elevation::Skipotherwise.Snapshotandfetch_snapshots: deserialisekopia snapshot list --jsonoutput into a typed shape.SnapshotFilter/build_filter: in-process filtering of a snapshot list by host, tag, path substring, and time window.- With the
clifeature: [SnapshotSelectorArgs] (aclap::Args-derived struct that consumer commands flatten into their own args) and [select_snapshot] (adialoguer-backed interactive picker).
Structs§
- DirSummary
- Root
Entry - Snapshot
- A single kopia snapshot, as emitted by
kopia snapshot list --json. - Snapshot
Filter - Filter criteria used by listing/restore/mount.
- Snapshot
Source
Enums§
- Elevation
- What to do about elevation on Linux when we want to run kopia.
Constants§
- LINUX_
KOPIA_ CONFIG - Standard location of the system kopia repository config on Linux. Owned
by the
LINUX_KOPIA_USER. - LINUX_
KOPIA_ USER - System user that owns the Linux kopia install.
Functions§
- build_
filter - Build a
SnapshotFilterfrom CLI-shaped inputs.all = truedrops any source-host filter. - build_
kopia_ command - Build a
Commandthat runs the kopia binary, elevated to the kopia user if the current platform/user requires it (Linux only). - current_
username - Current process’s username (via
whoami).Noneifwhoamican’t determine it (rare). - fetch_
snapshots - Run
kopia snapshot list --json --alland parse the result. - find_
kopia_ binary - Locate the kopia binary.
- find_
windows_ kopia_ binary - Look for the kopia binary bundled with KopiaUI on Windows.
- find_
windows_ kopia_ config - Standard per-user kopia repository config on Windows, used by KopiaUI.
- format_
snapshot_ line - One-line summary of a snapshot, suitable for an interactive picker.
- format_
tags - Render a snapshot’s tag map as a
k=v, k2=v2string (sorted by key). - format_
taken - Format a snapshot timestamp for human display.
- human_
bytes - Human-readable size formatter.
- linux_
elevation - Decide how to invoke kopia on Linux given the current user and whether the system kopia install is present (and accessible).
- parse_
tag_ kv - Parse a
key:valuetag spec from a--tagflag. - short_
id - Kopia’s manifest IDs are long hex. The short prefix is enough to identify a snapshot in a list; kopia restore/mount accept short prefixes too.