Created
January 30, 2024 00:58
-
-
Save BeniaminK/3ebf0288d7015ef2dff7bd9f82fbe8d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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