LibrePortal/scripts/backup/engine/borg_forget.sh
librelad 0b27ed1072 refactor(desudo): funnel backup-engine privilege drop through runBackupOp
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>
2026-05-24 18:01:51 +01:00

41 lines
1.3 KiB
Bash

#!/bin/bash
borgForgetApp()
{
local idx="$1"
local app_name="$2"
if resticLocationAppendOnly "$idx"; then
isNotice "$(resticLocationName "$idx") is append-only — skipping forget for $app_name"
return 0
fi
local keep_last keep_daily keep_weekly keep_monthly keep_yearly
keep_last=$(resticRetentionFor "$idx" KEEP_LAST)
keep_daily=$(resticRetentionFor "$idx" KEEP_DAILY)
keep_weekly=$(resticRetentionFor "$idx" KEEP_WEEKLY)
keep_monthly=$(resticRetentionFor "$idx" KEEP_MONTHLY)
keep_yearly=$(resticRetentionFor "$idx" KEEP_YEARLY)
borgEnvExport "$idx" || return 1
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
local args=(prune --glob-archives "${app_name}-${host_tag}-*")
[[ -n "$keep_last" ]] && args+=(--keep-last "$keep_last")
[[ -n "$keep_daily" ]] && args+=(--keep-daily "$keep_daily")
[[ -n "$keep_weekly" ]] && args+=(--keep-weekly "$keep_weekly")
[[ -n "$keep_monthly" ]] && args+=(--keep-monthly "$keep_monthly")
[[ -n "$keep_yearly" ]] && args+=(--keep-yearly "$keep_yearly")
isNotice "Applying retention for $app_name on $(resticLocationName "$idx")"
runBackupOp borg "${args[@]}"
local rc=$?
if [[ "$CFG_BACKUP_PRUNE_AFTER_FORGET" == "true" && $rc -eq 0 ]]; then
runBackupOp borg compact
fi
borgEnvUnset
return $rc
}