feat: add non-destructive file-restore mode to restore.sh

This commit is contained in:
kbe
2026-07-25 19:01:33 +02:00
parent 769eeea2b9
commit ea361904ba
2 changed files with 55 additions and 0 deletions
+21
View File
@@ -65,6 +65,27 @@ list_archives() {
borg list --lock-wait 60
}
extract_path() {
local rel_path="$1" dest_dir="$2" archive="$3"
mkdir -p "$dest_dir"
( cd "$dest_dir" && run_cmd borg extract --lock-wait 600 "${REPO}::${archive}" "${ARCHIVE_TARGET_PATH}/${rel_path}" )
echo "${dest_dir%/}/${ARCHIVE_TARGET_PATH}/${rel_path}"
}
cmd_file() {
local rel_path="$1" dest
resolve_archive
dest="${DEST:-/tmp/restore-file-$$}"
step "Restoring '$rel_path' from archive $RESOLVED_ARCHIVE into $dest"
if [[ "$DRY_RUN" == true ]]; then
log "[DRY-RUN] would extract ${ARCHIVE_TARGET_PATH}/${rel_path} from ${REPO}::${RESOLVED_ARCHIVE} into $dest"
return 0
fi
local final
final="$(extract_path "$rel_path" "$dest" "$RESOLVED_ARCHIVE" | tail -n1)"
log "Restored file available at: $final"
}
usage() {
cat <<'EOF'
Usage: