Expand description
Backup subsystem: scheduled policy jobs, on-demand archive export, and the shared transfer plumbing.
The scheduler (spawned from main when HELDAR_BACKUP_ENABLED) ticks every
HELDAR_BACKUP_SCHEDULER_INTERVAL_S, creates a backup_job for each due enabled policy, and runs
it under a process-wide concurrency Semaphore (also shared by manual triggers) with a
per-job timeout. A job resolves its segment files (camera selection + time window, optionally only
evidence-locked footage) and ships them:
localdestinations copy via std fs into{dest path}/{camera_id}/(NAS mounts, no rclone).sftp/ftp/s3destinations shell out to rclone (HELDAR_RCLONE_BIN). When rclone is not installed the job is markederrorwith a clear message โ the build/tests never require it.
On-demand archive export (create_archive) builds a .zip of the selected segments via
/usr/bin/zip into HELDAR_ARCHIVE_DIR/{job_id}.zip (served at /media/archives), enforcing
HELDAR_ARCHIVE_MAX_BYTES. It reuses backup_jobs with kind='on_demand_archive' + output_url.
Functionsยง
- create_
archive - Build a
.zipof the selected segments and record it as anon_demand_archivejob. Enforces the archive size cap on the source footprint; runs inline (bounded by the job timeout) so the returned job already carriesoutput_url. - run
- Background scheduler loop. Returns immediately (no respawn churn) when backups are disabled โ but
mainalready guards the spawn, mirroring the notifier. - test_
destination - Probe a destination: writability for
local, a short rclone connectivity check for remotes. - trigger_
policy - Manually trigger a policy: create its job and dispatch it (returns the job id immediately).