Created
March 31, 2023 08:38
-
-
Save slav123/4b6d09a36f29376f08e532c0990b6073 to your computer and use it in GitHub Desktop.
Restore Files from Glacier on Amazon S3 Storage using Bash Script
This file contains 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 your AWS region and S3 bucket name | |
REGION=eu-central-1 | |
BUCKET=bucket-name | |
# List all objects in the bucket and change the storage class to Standard | |
aws s3api list-objects --region "$REGION" --bucket "$BUCKET" --query "Contents[?StorageClass=='GLACIER'].[Key]" --output text | while read -r line; do | |
# Skip directories | |
if [[ "$line" == */ ]]; then | |
continue | |
fi | |
echo "Restoring \"$line\" to Standard storage class" | |
# Use double quotes around the key variable to handle spaces | |
aws s3api restore-object --bucket "$BUCKET" --key "$line" --restore-request '{"Days":25,"GlacierJobParameters":{"Tier":"Standard"}}' --no-cli-pager 2>&1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment