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 →
- 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" - Upload a SHA-256 checksum alongside, or use S3's checksum support:
aws s3api put-object --checksum-algorithm SHA256 ...and read it back withhead-object --checksum-mode ENABLED. - 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.
More on Scenarios: backups, log rotation and housekeeping
Design a nightly backup of `/etc` and application data to S3 with retention.IntermediateWrite the core of a Postgres backup that streams `pg_dump` through gzip to S3 and never uploads an empty dump.IntermediateBackups have "succeeded" every night for a year, but the first real restore failed. How do you make backups trustworthy?Advanced`/var` is 100% full because an app's logs were never rotated, and the app now fails to start. What do you do now, and what do you set up after?BeginnerShould you use `copytruncate` or a `postrotate` signal for an application's logs? How do you decide?Intermediate`/srv/app/releases` has 300 old release directories. Write a cleanup that keeps the newest 5 and never deletes the current release.Beginner