Harden restore-volumes.sh against silent restore truncation and incomplete-download skips

- BUG 1: Add error checking after tar extraction for both LOCAL and REMOTE-CACHE branches
  - Check exit status of tar -I zstd -xf commands
  - Print error to stderr and exit non-zero on failure
  - Prevents silent truncation where corrupt/incomplete backup extracts partial data
  - Mirrors existing remote-STREAM branch error handling
- BUG 2: Fix REMOTE branch to resume incomplete aria2c downloads
  - Check for presence of <file>.aria2 control file as incomplete signal
  - aria2c -c continues/resumes download when .aria2 file exists
  - Only skip download when file exists AND no .aria2 control file remains
  - aria2 deletes .aria2 sidecar on successful completion, making it a reliable signal
- Maintain all existing flags: aria2c -c -Z -x8 -j8 -s8 -d
- Preserve reth guard logic and static-file offload behavior unchanged

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
rob
2026-06-17 16:22:50 +00:00
parent 6ddb18dbc5
commit 6bb0b19f45

View File

@@ -117,17 +117,26 @@ while IFS= read -r key; do
echo "No /backup cache: streaming + extracting $newest_file directly" echo "No /backup cache: streaming + extracting $newest_file directly"
curl --ipv4 -# "${remote_source}${newest_file}" | zstd -d | tar -xf - --keep-directory-symlink -C / curl --ipv4 -# "${remote_source}${newest_file}" | zstd -d | tar -xf - --keep-directory-symlink -C /
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error processing $newest_file" echo "Error processing $newest_file" >&2
exit 1 exit 1
fi fi
else else
if [ ! -e "$backup_dir/$(basename "$newest_file")" ]; then backup_file="$backup_dir/$(basename "$newest_file")"
if [ ! -e "$backup_file" ] || [ -e "${backup_file}.aria2" ]; then
aria2c -c -Z -x8 -j8 -s8 -d "$backup_dir" "${remote_source}${newest_file}" aria2c -c -Z -x8 -j8 -s8 -d "$backup_dir" "${remote_source}${newest_file}"
fi fi
tar -I zstd -xf "$backup_dir/$(basename "$newest_file")" --keep-directory-symlink -C / tar -I zstd -xf "$backup_file" --keep-directory-symlink -C /
if [ $? -ne 0 ]; then
echo "Error processing $newest_file" >&2
exit 1
fi
fi fi
else else
tar -I zstd -xf "$newest_file" --keep-directory-symlink -C / tar -I zstd -xf "$newest_file" --keep-directory-symlink -C /
if [ $? -ne 0 ]; then
echo "Error processing $newest_file" >&2
exit 1
fi
fi fi
echo "Backup '$newest_file' restored" echo "Backup '$newest_file' restored"
done <<< "$keys" done <<< "$keys"