Skip to content

Instantly share code, notes, and snippets.

@slav123
Created March 31, 2023 08:38
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 slav123/4b6d09a36f29376f08e532c0990b6073 to your computer and use it in GitHub Desktop.
Save slav123/4b6d09a36f29376f08e532c0990b6073 to your computer and use it in GitHub Desktop.
Restore Files from Glacier on Amazon S3 Storage using Bash Script
#!/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