The backup engine already drops to the backup user (sudo -E -u $docker_install_user) and backupLocationOwner == $docker_install_user, which is exactly what runFileOp/runFileWrite resolve to in both modes. So convert the raw-sudo data ops (mkdir/chmod/rm/find/cat/grep/mv/chown/tee on backup repos, location configs, keys, manifests) to runFileOp/runFileWrite — creating files as the owner directly, no root chown. backup_verify creates its scratch as the backup user (runFileOp mktemp) instead of chown-after. Binary installs (kopia tar/install, borg dnf) -> runSystem. The 44 sudo -u engine drops stay (already least-privilege; the scoped sudoers will grant them). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
45 lines
1.6 KiB
Bash
45 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
backupVerifySnapshot()
|
|
{
|
|
local idx="$1"
|
|
local snapshot_id="$2"
|
|
local app_name="$3"
|
|
|
|
if [[ -z "$snapshot_id" ]]; then
|
|
isNotice "No snapshot id provided — verification skipped"
|
|
return 0
|
|
fi
|
|
|
|
local scratch
|
|
# Create the scratch dir AS the backup/install user so the engine (which runs
|
|
# as that user) can restore into it and we can read it back — no root chown.
|
|
scratch=$(runFileOp mktemp -d -t libreportal-verify-XXXXXX)
|
|
|
|
isNotice "Verifying ${snapshot_id:0:8} via scratch restore at $scratch"
|
|
|
|
if ! engineRestoreSnapshot "$idx" "$snapshot_id" "$scratch" "$containers_dir$app_name"; then
|
|
isError "Verify restore FAILED for $app_name on $(resticLocationName "$idx")"
|
|
runFileOp rm -rf "$scratch"
|
|
return 1
|
|
fi
|
|
|
|
# The scratch restore above succeeding is the real proof the snapshot is
|
|
# restorable (restic verifies each blob's hash as it restores). We can't
|
|
# compare against the live app dir any more — the live path deliberately
|
|
# differs from the snapshot (raw DB dirs and private file trees are excluded
|
|
# and replaced by dumps/captures under .lp-backup) — so just sanity-check the
|
|
# restore produced a non-empty tree.
|
|
local restored_count
|
|
restored_count=$(runFileOp find "$scratch$containers_dir$app_name" -type f 2>/dev/null | wc -l)
|
|
|
|
runFileOp rm -rf "$scratch"
|
|
|
|
if [[ "$restored_count" -lt 1 ]]; then
|
|
isError "Verify FAILED for $app_name — restored snapshot is empty"
|
|
return 1
|
|
fi
|
|
|
|
isSuccessful "Snapshot ${snapshot_id:0:8} verified — restored $restored_count files"
|
|
}
|