Last active
September 25, 2023 11:32
-
-
Save VTRyo/ddb3f6ffdc0da7337a31f94f70d4ee29 to your computer and use it in GitHub Desktop.
s3 versioning, lifecycle
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/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