diff --git a/source/agent-remote/datacommands_v2.sh b/source/agent-remote/datacommands_v2.sh index 271090e..76e8412 100644 --- a/source/agent-remote/datacommands_v2.sh +++ b/source/agent-remote/datacommands_v2.sh @@ -73,13 +73,13 @@ backup_file() { # Store metadata about the file echo "${filepath}" > "${target_dir}/original_path.txt" - # Copy the file + # Copy the file - save as the label name, not original filename docker run --rm \ -v "${file_parent}":/source \ -v "${target_dir}":/backup \ - debian bash -c "cp /source/${file_name} /backup/${file_name} && chown -R $MYID:$MYGRP /backup" + debian bash -c "cp /source/${file_name} /backup/${label}.data && chown -R $MYID:$MYGRP /backup" - echo "File ${filepath} backed up successfully" + echo "File ${filepath} backed up successfully as ${label}.data" else echo "File ${filepath} does not exist - nothing to backup" fi @@ -99,10 +99,8 @@ restore_file() { return 1 fi - local file_name - file_name=$(basename "${filepath}") - - if [ -f "${source_dir}/${file_name}" ]; then + # File is backed up as ${label}.data, not original filename + if [ -f "${source_dir}/${label}.data" ]; then # Ensure parent directory exists local file_parent file_parent=$(dirname "${filepath}") @@ -111,11 +109,11 @@ restore_file() { # Remove existing file if present rm -f "${filepath}" - # Copy from backup - cp "${source_dir}/${file_name}" "${filepath}" - echo "File ${filepath} restored successfully" + # Copy from backup - restore from label.data to target filepath + cp "${source_dir}/${label}.data" "${filepath}" + echo "File ${filepath} restored successfully from ${label}.data" else - echo "Backup file ${source_dir}/${file_name} not found" + echo "Backup file ${source_dir}/${label}.data not found" return 1 fi }