Created
December 18, 2019 10:10
-
-
Save gordonmurray/ae165d7e4cbc3fe591d60bc4afa83032 to your computer and use it in GitHub Desktop.
Set random maintenance windows on all RDS instances within limits
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
#!/usr/bin/env bash | |
set -xe | |
REGION="eu-west-1" | |
# list RDS instances to a file | |
aws rds --region ${REGION} describe-db-instances | jq -r '.DBInstances[].DBInstanceIdentifier' > rds.log | |
# loop over the rds instances in the file | |
while read rds; do | |
# Random hour | |
HOUR=`shuf -i 2-5 -n 1` | |
HOUREND=$((HOUR+1)) | |
# Random day | |
DAYS[0]="Sat" | |
DAYS[1]="Sun" | |
size=${#DAYS[@]} | |
index=$(($RANDOM % $size)) | |
DAY=${DAYS[$index]} | |
aws rds modify-db-instance --region ${REGION} --db-instance-identifier ${rds} --preferred-maintenance-window ${DAY}:0${HOUR}:00-${DAY}:0${HOUREND}:00 | |
sleep 3 | |
echo ${RDS} set to ${DAY} from ${HOUR} to ${HOUREND} | |
done <rds.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment