Skip to content

Instantly share code, notes, and snippets.

@VTRyo
Last active September 25, 2023 11:32
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 VTRyo/ddb3f6ffdc0da7337a31f94f70d4ee29 to your computer and use it in GitHub Desktop.
Save VTRyo/ddb3f6ffdc0da7337a31f94f70d4ee29 to your computer and use it in GitHub Desktop.
s3 versioning, lifecycle
#/bin/sh
################# Usage ########################
# ./check_s3_backup_policy.sh AWS_PROFILE_NAME
################################################
PROFILE=$1
if [ -z "$PROFILE" ]; then
echo "Usage: $0 <aws-profile>"
exit 1
fi
for bucket in $(aws --profile $PROFILE s3api list-buckets --query 'Buckets[*].Name' --output text)
do
versioning=$(aws --profile $PROFILE s3api get-bucket-versioning --bucket $bucket --query 'Status' --output text)
if [ "$versioning" == "Enabled" ]; then
echo "$bucket: versioning is enabled"
else
echo "$bucket: versioning is disabled"
fi
lifecycle=$(aws s3api get-bucket-lifecycle-configuration --bucket $bucket --profile $PROFILE --output json 2>/dev/null)
if [ "$?" -ne 0 ] || [ -z "$lifecycle" ]; then
echo "lifecyle rule: nothing"
else
echo "lifecycle rule: exist"
echo "rule details:"
echo "$lifecycle" | jq '.Rules[] | .'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment