LibrePortal/scripts/cli/commands/backup/cli_backup_commands.sh
librelad 19c76f0a3f feat(backup): CLI + data plumbing for per-location SSH keys
Expose the existing location_ssh.sh key store through the backup CLI:
'backup location ssh-key-set|ssh-key-generate|ssh-key-public|ssh-key-delete <idx>'
(the WebUI runs these as tasks). The locations generator now emits
ssh_key_exists + ssh_public_key (public key only — the private key never
leaves the per-location ssh.key file), so the editor can show the key state.
Also fix the stale SSH_AUTH label (~/.ssh/id_rsa -> managed per-location key).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-23 16:11:31 +01:00

116 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
cliHandleBackupCommands()
{
local backup_type="$initial_command2"
local action="$initial_command3"
local name="$initial_command4"
local extra="$initial_command5"
local extra2="$initial_command6"
if [[ -z "$backup_type" ]]; then
cliShowBackupHelp
return
fi
case "$backup_type" in
app)
case "$action" in
""|help) cliShowBackupHelp ;;
create)
[[ -z "$name" ]] && { isNotice "No app name provided."; cliShowBackupHelp; return; }
backupAppStart "$name"
;;
schedule)
[[ -z "$name" ]] && { isNotice "No app name provided."; cliShowBackupHelp; return; }
backupAppSchedule "$name"
;;
delete)
[[ -z "$name" ]] && { isNotice "No app name provided."; cliShowBackupHelp; return; }
[[ -z "$extra" ]] && { isNotice "No <location_idx>:<snapshot_id> provided (e.g. 1:abc123)."; cliShowBackupHelp; return; }
local idx="${extra%%:*}"
local snap="${extra##*:}"
backupAppDeleteSnapshot "$idx" "$snap"
;;
delete_all)
[[ -z "$name" ]] && { isNotice "No app name provided."; cliShowBackupHelp; return; }
backupAppDeleteAll "$name"
;;
list)
[[ -z "$name" ]] && { isNotice "No app name provided."; cliShowBackupHelp; return; }
local idx
while IFS= read -r idx; do
[[ -z "$idx" ]] && continue
echo "--- $(resticLocationName "$idx") (loc $idx) ---"
engineSnapshotsJson "$idx" "$name"
done < <(resticEnabledLocations)
;;
*)
isNotice "Invalid app backup action: $action"
cliShowBackupHelp
;;
esac
;;
all)
backupAllApps
;;
scheduled)
backupScheduleEnabledApps
;;
location)
case "$action" in
add)
[[ -z "$name" ]] && { isNotice "Usage: backup location add <name> [type]"; cliShowBackupHelp; return; }
locationAdd "$name" "$extra"
;;
remove)
[[ -z "$name" ]] && { isNotice "Usage: backup location remove <idx>"; cliShowBackupHelp; return; }
locationRemove "$name" "$extra"
;;
list)
local idx
while IFS= read -r idx; do
[[ -z "$idx" ]] && continue
local enabled="no"; resticLocationEnabled "$idx" && enabled="yes"
echo "[$idx] $(resticLocationName "$idx") — type=$(resticLocationType "$idx"), enabled=$enabled"
done < <(resticAllLocationIndices)
;;
init)
engineInitAllLocations
;;
check)
engineCheckAllLocations "${name:-5}"
;;
stats)
[[ -z "$name" ]] && name="1"
engineLocationStats "$name"
;;
ssh-key-set)
[[ -z "$name" || -z "$extra" ]] && { isNotice "Usage: backup location ssh-key-set <idx> <base64-key>"; return; }
backupSshKeySet "$name" "$extra"
;;
ssh-key-generate)
[[ -z "$name" ]] && { isNotice "Usage: backup location ssh-key-generate <idx>"; return; }
backupSshKeyGenerate "$name"
;;
ssh-key-public)
[[ -z "$name" ]] && { isNotice "Usage: backup location ssh-key-public <idx>"; return; }
backupSshKeyPublic "$name"
;;
ssh-key-delete)
[[ -z "$name" ]] && { isNotice "Usage: backup location ssh-key-delete <idx>"; return; }
backupSshKeyDelete "$name"
;;
*) isNotice "Invalid location action: $action"; cliShowBackupHelp ;;
esac
;;
verify)
engineCheckAllLocations "${action:-5}"
;;
*)
isNotice "Invalid backup type: $backup_type"
cliShowBackupHelp
;;
esac
}