Interview Prep/Shell Scripting/Scenarios: backups, log rotation and housekeeping

How do you verify that a file uploaded to S3 is intact?

IntermediateScenarioScenarios: backups, log rotation and housekeeping
Answer

Situation read → Network errors and partial uploads must be detected before you delete the local copy.

What I'd do →

  1. Compare the size after upload:
    local_size=$(stat -c %s "$f")
    remote_size=$(aws s3api head-object --bucket "$B" --key "$K" --query ContentLength --output text)
    [[ $local_size == "$remote_size" ]] || die "size mismatch"
    
  2. Upload a SHA-256 checksum alongside, or use S3's checksum support: aws s3api put-object --checksum-algorithm SHA256 ... and read it back with head-object --checksum-mode ENABLED.
  3. During restore tests, download and run sha256sum -c.

Why → The CLI already retries and validates parts, but an explicit check gives evidence in logs and catches logic errors such as uploading the wrong file.

Interview tip → Mention that the ETag equals the MD5 only for single-part, non-KMS uploads, so do not rely on it as a checksum.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: backups, log rotation and housekeeping