Skip to main content

Module backup

Module backup 

Source
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:

  • local destinations copy via std fs into {dest path}/{camera_id}/ (NAS mounts, no rclone).
  • sftp / ftp / s3 destinations shell out to rclone (HELDAR_RCLONE_BIN). When rclone is not installed the job is marked error with 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 .zip of the selected segments and record it as an on_demand_archive job. Enforces the archive size cap on the source footprint; runs inline (bounded by the job timeout) so the returned job already carries output_url.
run
Background scheduler loop. Returns immediately (no respawn churn) when backups are disabled โ€” but main already 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).