- restic_install, crowdsec_update/verify_firewall/fix_priority: pure host ops (apt/cscli/nft/systemctl, /etc/crowdsec) -> runSystem. - kopia_backup/borg_restore: ignore-file/target tee+chown+mkdir -> runFileOp/ runFileWrite; kept the 'sudo -E -u dockerinstall' engine calls as-is — those already run as the unprivileged backup user (least-privilege; the scoped sudoers will permit (dockerinstall)). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
50 lines
1.3 KiB
Bash
50 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
borgRestoreSnapshot()
|
|
{
|
|
local idx="$1"
|
|
local snapshot_id="$2"
|
|
local target_dir="$3"
|
|
local include_path="$4"
|
|
|
|
if [[ -z "$snapshot_id" || -z "$target_dir" ]]; then
|
|
isError "borgRestoreSnapshot requires snapshot_id and target_dir"
|
|
return 1
|
|
fi
|
|
|
|
borgEnvExport "$idx" || return 1
|
|
runFileOp mkdir -p "$target_dir"
|
|
|
|
isNotice "Restoring $snapshot_id from $(resticLocationName "$idx") → $target_dir"
|
|
local rc
|
|
if [[ -n "$include_path" ]]; then
|
|
local stripped="${include_path#/}"
|
|
( cd "$target_dir" && sudo -E -u "$docker_install_user" borg extract "::$snapshot_id" "$stripped" )
|
|
rc=$?
|
|
else
|
|
( cd "$target_dir" && sudo -E -u "$docker_install_user" borg extract "::$snapshot_id" )
|
|
rc=$?
|
|
fi
|
|
borgEnvUnset
|
|
return $rc
|
|
}
|
|
|
|
borgDumpFile()
|
|
{
|
|
local idx="$1"
|
|
local snapshot_id="$2"
|
|
local file_path="$3"
|
|
local target_file="$4"
|
|
|
|
borgEnvExport "$idx" || return 1
|
|
local stripped="${file_path#/}"
|
|
if [[ -n "$target_file" ]]; then
|
|
sudo -E -u "$docker_install_user" borg extract --stdout "::$snapshot_id" "$stripped" | runFileWrite "$target_file"
|
|
else
|
|
sudo -E -u "$docker_install_user" borg extract --stdout "::$snapshot_id" "$stripped"
|
|
fi
|
|
local rc=$?
|
|
borgEnvUnset
|
|
return $rc
|
|
}
|