Skip to content

Commit e08e129

Browse files
authored
improved specific file restore
1 parent ecec8ed commit e08e129

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

backup_script.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,27 +355,18 @@ run_restore_mode() {
355355
if [[ -n "$dir_choice" ]]; then break;
356356
else echo "Invalid selection. Please try again."; fi
357357
done
358-
PS3="#? "
358+
PS3="#? "
359359
local full_remote_source=""
360360
local default_local_dest=""
361361
local item_for_display=""
362362
local restore_path=""
363363
local is_full_directory_restore=false
364364
if [[ "$dir_choice" == "$RECYCLE_OPTION" ]]; then
365365
print_header "Browse Recycle Bin"
366+
local date_folders=()
366367
local remote_recycle_path="${BOX_DIR%/}/${RECYCLE_BIN_DIR%/}"
367-
local date_folders; date_folders=$(ssh "${SSH_OPTS_ARRAY[@]}" "${SSH_DIRECT_OPTS[@]}" "$BOX_ADDR" "ls -1 \"$remote_recycle_path\"" 2>/dev/null) || true
368-
local valid_folders=()
369-
for f in $date_folders; do
370-
case "$f" in
371-
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9])
372-
valid_folders+=( "$f" )
373-
;;
374-
esac
375-
done
376-
date_folders=("${valid_folders[@]}")
368+
mapfile -t date_folders < <(ssh "${SSH_OPTS_ARRAY[@]}" "${SSH_DIRECT_OPTS[@]}" "$BOX_ADDR" "ls -1 \"$remote_recycle_path\"" 2>/dev/null | grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{6}$')
377369
if [[ ${#date_folders[@]} -eq 0 ]]; then
378-
echo "❌ No validly-named backup folders found in the recycle bin." >&2; return 1
379370
fi
380371
printf "${C_YELLOW}Select a backup run (date_time) to browse:${C_RESET}\n"
381372
PS3="Your choice: "
@@ -410,6 +401,11 @@ run_restore_mode() {
410401
case "$choice" in
411402
entire) is_full_directory_restore=true; break ;;
412403
specific)
404+
local relative_path_browse="${dir_choice#*./}"
405+
local remote_browse_source="${REMOTE_TARGET}${relative_path_browse}"
406+
print_header "Files available in ${dir_choice} (showing first 20)"
407+
rsync -r -n --out-format='%n' -e "$SSH_CMD" "$remote_browse_source" . 2>/dev/null | head -n 20 || echo "No files found for this backup set."
408+
printf "%b--------------------------------------------------------%b\n" "${C_BOLD}" "${C_RESET}"
413409
printf -v specific_path_prompt "Enter the path relative to '%s' to restore (e.g., subfolder/file.txt): " "$dir_choice"; printf "${C_YELLOW}%s${C_RESET}" "$specific_path_prompt"; read -er specific_path
414410
if [[ "$specific_path" == /* || "$specific_path" =~ (^|/)\.\.(/|$) ]]; then
415411
echo "❌ Invalid restore path: must be relative and contain no '..'" >&2; return 1

0 commit comments

Comments
 (0)