The borg/restic/kopia engines all dropped to the dedicated backup user via scattered 'sudo -E -u $docker_install_user'. Centralize that into a single runBackupOp helper so the backup subsystem has one audit point and the scoped sudoers needs only the (dockerinstall) drop rule. Also: - owncloud config heredoc tees -> runSystem (container-UID file) - webui_display_logins: fix the broken 'command -v sudo sqlite3' guard to 'command -v sqlite3' (body already runs sqlite3 via runInstallOp) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
70 lines
1.7 KiB
Bash
70 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Reshape `kopia snapshot list --json` to match the restic-style {short_id,
|
|
# time, hostname, tags, paths} schema the frontend consumes.
|
|
|
|
kopiaSnapshotsJson()
|
|
{
|
|
local idx="$1"
|
|
local app_filter="$2"
|
|
local host_filter="$3"
|
|
|
|
kopiaEnvExport "$idx" || return 1
|
|
|
|
local args=(snapshot list --all --json)
|
|
|
|
local raw
|
|
raw=$(runBackupOp kopia "${args[@]}" 2>/dev/null)
|
|
local rc=$?
|
|
kopiaEnvUnset
|
|
[[ $rc -ne 0 || -z "$raw" ]] && { echo "[]"; return $rc; }
|
|
|
|
local jq_filter='[.[] | {
|
|
id: .id,
|
|
short_id: (.id[0:8]),
|
|
time: .startTime,
|
|
hostname: .source.host,
|
|
tags: ((.tags // []) | map(sub(":"; "="))),
|
|
paths: [.source.path]
|
|
}]'
|
|
|
|
if [[ -n "$app_filter" ]]; then
|
|
jq_filter='[.[] | select(any(.tags[]?; . == "app:'"$app_filter"'"))] | '"$jq_filter"
|
|
fi
|
|
if [[ -n "$host_filter" ]]; then
|
|
jq_filter='[.[] | select(.source.host == "'"$host_filter"'")] | '"$jq_filter"
|
|
fi
|
|
|
|
if command -v jq >/dev/null 2>&1; then
|
|
echo "$raw" | jq -c "$jq_filter"
|
|
else
|
|
echo "$raw"
|
|
fi
|
|
}
|
|
|
|
kopiaSnapshotLatestId()
|
|
{
|
|
local idx="$1"
|
|
local app_name="$2"
|
|
local host="${3:-$CFG_INSTALL_NAME}"
|
|
|
|
local json
|
|
json=$(kopiaSnapshotsJson "$idx" "$app_name" "$host")
|
|
if command -v jq >/dev/null 2>&1; then
|
|
echo "$json" | jq -r 'sort_by(.time) | last | .id // empty'
|
|
else
|
|
echo "$json" | grep -oE '"id":\s*"[^"]+"' | tail -1 | cut -d'"' -f4
|
|
fi
|
|
}
|
|
|
|
kopiaSnapshotListFiles()
|
|
{
|
|
local idx="$1"
|
|
local snapshot_id="$2"
|
|
kopiaEnvExport "$idx" || return 1
|
|
runBackupOp kopia snapshot list "$snapshot_id" --json 2>/dev/null
|
|
local rc=$?
|
|
kopiaEnvUnset
|
|
return $rc
|
|
}
|