From d04beefb42de4351791b4cb4fdd9cd20a1c1ca2a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 30 Aug 2025 18:04:20 +1200 Subject: [PATCH] Update source/agent-remote/datacommands_v2.sh --- source/agent-remote/datacommands_v2.sh | 152 ++++++++++++------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/source/agent-remote/datacommands_v2.sh b/source/agent-remote/datacommands_v2.sh index 1c2db64..9b68287 100644 --- a/source/agent-remote/datacommands_v2.sh +++ b/source/agent-remote/datacommands_v2.sh @@ -281,7 +281,7 @@ backup_volume() { restore_volume() { local label="$1" local volume_name="$2" - local backup_folder="$3" + local backup_folder="$TEMP_DIR/backup" echo "[restore_volume] label=$label volume=$volume_name backup_folder=$backup_folder" @@ -315,98 +315,98 @@ restore_volume() { fi } -# # ============================================================================ -# # MAIN BACKUP/RESTORE ORCHESTRATION -# # ============================================================================ +# ============================================================================ +# MAIN BACKUP/RESTORE ORCHESTRATION +# ============================================================================ -# # Process multiple items for backup -# # Usage: backup_items type1:label1:location1 type2:label2:location2 ... -# backup_items() { -# local backup_file="$1" -# local temp_dir="$2" -# shift 2 +# Process multiple items for backup +# Usage: backup_items type1:label1:location1 type2:label2:location2 ... +backup_items() { + _check_required_env_vars "BACKUP_FILE" "TEMP_DIR" + local backup_file="${BACKUP_FILE}" + local temp_dir="${TEMP_DIR}" -# local backup_temp_path="${temp_dir}/backup" -# mkdir -p "$backup_temp_path" + local backup_temp_path="${temp_dir}/backup" + mkdir -p "$backup_temp_path" -# echo "Starting backup to ${backup_file}" + echo "Starting backup to ${backup_file}" -# # Process each item -# for item in "$@"; do -# IFS=':' read -r type label location <<< "$item" + # Process each item + for item in "$@"; do + IFS=':' read -r type label location <<< "$item" -# case "$type" in -# file) -# backup_file "$label" "$location" "$backup_temp_path" -# ;; -# path) -# backup_path "$label" "$location" "$backup_temp_path" -# ;; -# volume) -# backup_volume "$label" "$location" "$backup_temp_path" -# ;; -# *) -# echo "Unknown type: $type (must be file, path, or volume)" -# ;; -# esac -# done + case "$type" in + file) + backup_file "$label" "$location" "$backup_temp_path" + ;; + path) + backup_path "$label" "$location" "$backup_temp_path" + ;; + volume) + backup_volume "$label" "$location" "$backup_temp_path" + ;; + *) + echo "Unknown type: $type (must be file, path, or volume)" + ;; + esac + done -# # Create final backup archive -# echo "Creating backup archive ${backup_file}" -# tar -czf "$backup_file" -C "$backup_temp_path" . + # Create final backup archive + echo "Creating backup archive ${backup_file}" + tar -czf "$backup_file" -C "$backup_temp_path" . -# # Clean up temp directory -# rm -rf "$backup_temp_path" + # Clean up temp directory + rm -rf "$backup_temp_path" -# echo "Backup completed successfully" -# } + echo "Backup completed successfully" +} -# # Process multiple items for restore -# # Usage: restore_items type1:label1:location1 type2:label2:location2 ... -# restore_items() { -# local backup_file="$1" -# local temp_dir="$2" -# shift 2 +# Process multiple items for restore +# Usage: restore_items type1:label1:location1 type2:label2:location2 ... +restore_items() { + _check_required_env_vars "BACKUP_FILE" "TEMP_DIR" + local backup_file="${BACKUP_FILE}" + local temp_dir="${TEMP_DIR}" -# if [ ! -f "$backup_file" ]; then -# echo "Backup file $backup_file not found" -# return 1 -# fi + if [ ! -f "$backup_file" ]; then + echo "Backup file $backup_file not found" + return 1 + fi -# local restore_temp_path="${temp_dir}/restore" -# mkdir -p "$restore_temp_path" + local restore_temp_path="${temp_dir}/restore" + mkdir -p "$restore_temp_path" -# echo "Starting restore from ${backup_file}" + echo "Starting restore from ${backup_file}" -# # Extract backup archive -# echo "Extracting backup archive" -# tar -xzf "$backup_file" -C "$restore_temp_path" + # Extract backup archive + echo "Extracting backup archive" + tar -xzf "$backup_file" -C "$restore_temp_path" -# # Process each item -# for item in "$@"; do -# IFS=':' read -r type label location <<< "$item" + # Process each item + for item in "$@"; do + IFS=':' read -r type label location <<< "$item" -# case "$type" in -# file) -# restore_file "$label" "$location" "$restore_temp_path" -# ;; -# path) -# restore_path "$label" "$location" "$restore_temp_path" -# ;; -# volume) -# restore_volume "$label" "$location" "$restore_temp_path" -# ;; -# *) -# echo "Unknown type: $type (must be file, path, or volume)" -# ;; -# esac -# done + case "$type" in + file) + restore_file "$label" "$location" "$restore_temp_path" + ;; + path) + restore_path "$label" "$location" "$restore_temp_path" + ;; + volume) + restore_volume "$label" "$location" "$restore_temp_path" + ;; + *) + echo "Unknown type: $type (must be file, path, or volume)" + ;; + esac + done -# # Clean up temp directory -# rm -rf "$restore_temp_path" + # Clean up temp directory + rm -rf "$restore_temp_path" -# echo "Restore completed successfully" -# } + echo "Restore completed successfully" +} # # ============================================================================ # # LEGACY COMPATIBILITY WRAPPER (can be removed once migration is complete)