A cleanup script deleted every object under `s3://acme-invoices/2025/`. Versioning is enabled.
BeginnerTroubleshootingData loss and corruption
Answer
Likely causes → With versioning on, a plain delete doesn't remove data; it adds a delete marker on top of each object. The previous versions are still there.
Diagnose →
aws s3api list-object-versions --bucket acme-invoices --prefix 2025/ \
--query 'DeleteMarkers[?IsLatest==`true`].[Key,VersionId]' --output text | head
Fix → Remove the delete markers so the previous versions become current again:
aws s3api list-object-versions --bucket acme-invoices --prefix 2025/ \
--query 'DeleteMarkers[?IsLatest==`true`].[Key,VersionId]' --output text |
while read -r key ver; do
aws s3api delete-object --bucket acme-invoices --key "$key" --version-id "$ver"
done
For millions of objects, use S3 Batch Operations with an inventory report.
Prevent → Keep versioning on with a lifecycle rule for noncurrent versions (for example 30 days), enable MFA delete or Object Lock for critical buckets, and scope cleanup scripts' IAM to the prefixes they really own.
More on Data loss and corruption
An engineer ran `DELETE FROM orders;` on the production Postgres (forgot the `WHERE`) at 14:32.BeginnerYou need to restore last night's MySQL backup and discover the dump files for the past three months are 20 KB each.IntermediateUsers update their profile, the page reloads, and they see the old values; a minute later the new values show up.IntermediateA network partition between data centres lasted 4 minutes; afterwards you find both sites accepted writes as primary, and the same order IDs exist with different contents.AdvancedA deploy ran a migration that dropped the `phone` column; old pods still running during the rolling update threw 500s, and a background job wrote nulls into a new table.IntermediateSomeone ran `helm uninstall` on the production Postgres release; the PVC was deleted and the StorageClass has `reclaimPolicy: Delete`.Beginner