79805959

Date: 2025-10-31 15:45:42
Score: 1
Natty:
Report link

I found this script which does the trick

#!/bin/bash

# Get the time one hour ago in ISO 8601 format
one_hour_ago=$(date -u -d '1 hour ago' +'%Y-%m-%dT%H:%M:%SZ')

# List all the latest delete markers
delete_markers=$(aws s3api list-object-versions --bucket my-bucket --prefix my-folder/ --query 'DeleteMarkers[?IsLatest==`true`].[Key, VersionId, LastModified]' --output text)

# Delete only the delete markers set within the last hour
while IFS=$'\t' read -r key version_id last_modified; do
  if [[ "$last_modified" > "$one_hour_ago" ]]; then
    echo "Deleting delete marker for $key with version ID $version_id, set at $last_modified"
    aws s3api delete-object --bucket my-bucket --key "$key" --version-id "$version_id"
  fi
done <<< "$delete_markers"

source: https://dev.to/siddhantkcode/how-to-recover-an-entire-folder-in-s3-after-accidental-deletion-173f

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Aram