Update source/agent-remote/datacommands_v2.sh
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 30s
Build-Test-Publish / build (linux/arm64) (push) Successful in 56s

This commit is contained in:
Your Name
2025-08-31 11:30:00 +12:00
parent dfe50b7fa9
commit fc20c62671

View File

@@ -73,13 +73,13 @@ backup_file() {
# Store metadata about the file # Store metadata about the file
echo "${filepath}" > "${target_dir}/original_path.txt" echo "${filepath}" > "${target_dir}/original_path.txt"
# Copy the file # Copy the file - save as the label name, not original filename
docker run --rm \ docker run --rm \
-v "${file_parent}":/source \ -v "${file_parent}":/source \
-v "${target_dir}":/backup \ -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 else
echo "File ${filepath} does not exist - nothing to backup" echo "File ${filepath} does not exist - nothing to backup"
fi fi
@@ -99,10 +99,8 @@ restore_file() {
return 1 return 1
fi fi
local file_name # File is backed up as ${label}.data, not original filename
file_name=$(basename "${filepath}") if [ -f "${source_dir}/${label}.data" ]; then
if [ -f "${source_dir}/${file_name}" ]; then
# Ensure parent directory exists # Ensure parent directory exists
local file_parent local file_parent
file_parent=$(dirname "${filepath}") file_parent=$(dirname "${filepath}")
@@ -111,11 +109,11 @@ restore_file() {
# Remove existing file if present # Remove existing file if present
rm -f "${filepath}" rm -f "${filepath}"
# Copy from backup # Copy from backup - restore from label.data to target filepath
cp "${source_dir}/${file_name}" "${filepath}" cp "${source_dir}/${label}.data" "${filepath}"
echo "File ${filepath} restored successfully" echo "File ${filepath} restored successfully from ${label}.data"
else else
echo "Backup file ${source_dir}/${file_name} not found" echo "Backup file ${source_dir}/${label}.data not found"
return 1 return 1
fi fi
} }