Skip to content

Instantly share code, notes, and snippets.

@BeniaminK
Created January 30, 2024 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeniaminK/3ebf0288d7015ef2dff7bd9f82fbe8d8 to your computer and use it in GitHub Desktop.
Save BeniaminK/3ebf0288d7015ef2dff7bd9f82fbe8d8 to your computer and use it in GitHub Desktop.
#!/bin/bash -
set -o nounset # Treat unset variables as an error
BUCKET="beniamink-permission-testing-source"
# List all objects in the bucket
objects=$(aws s3api list-objects --bucket "$BUCKET" --query "Contents[?StorageClass=='GLACIER']" --output json | jq -r '.[].Key')
# Iterate over each object and initiate restore
for object_key in $objects
do
echo "Restoring: $object_key"
aws s3api restore-object --bucket $BUCKET --key "$object_key" --restore-request '{"Days": 2, "GlacierJobParameters": {"Tier": "Standard"}}'
done
echo
for object_key in $objects
do
STATUS=
echo -n Checking "${object_key}"
while true
do
echo -n .
STATUS=$(aws s3api head-object --bucket "${BUCKET}" --key "${object_key}" --no-cli-pager | jq -r -e '.Restore | if . == null then "NotPresent" elif . == "ongoing-request=\"true\"" then "Ongoing" elif startswith("ongoing-request=\"false\"") then "Completed" else "Unknown" end')
if [ "${STATUS}" = Completed ]
then
break
elif [ "${STATUS}" != Ongoing ]
then
echo "Error - STATUS: ${STATUS}"
fi
sleep 10
done
echo
done
# aws s3 sync s3://${BUCKET}/configuration.tf s3://${BUCKET}/configuration2.tf --storage-class STANDARD
# Cleanup
# aws s3 rm s3://${BUCKET}/configuration.tf --recursive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment