Created
September 28, 2015 07:40
-
-
Save onagatani/f245266fa4d52c21cf4d to your computer and use it in GitHub Desktop.
EBSのスナップショットが本日日付で取得されているかチェックする
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 | |
export PATH=$PATH:/usr/local/bin/:/usr/bin | |
while getopts r: OPT | |
do | |
case $OPT in | |
"r" ) | |
REGION=$OPTARG | |
;; | |
esac | |
done | |
export AWS_DEFAULT_REGION=${REGION:-ap-northeast-1} | |
INSTANCES=$( aws ec2 describe-tags\ | |
--filters "Name=resource-type,Values=instance" "Name=key,Values=backup"\ | |
--query "Tags[?Value=='ON'].ResourceId"\ | |
--output text ) | |
DATE=$(date --date "9 hours ago" -u "+%Y-%m-%d") | |
if [ -z "$INSTANCES" ]; then | |
exit 1 | |
fi | |
for INSTANCE_ID in $INSTANCES | |
do | |
VOLUMES=$( aws ec2 describe-volumes\ | |
--filters "Name=attachment.instance-id,Values=${INSTANCE_ID}"\ | |
--query "Volumes[].VolumeId"\ | |
--output text ) | |
if [ "$VOLUMES" ]; then | |
for VOLUME_ID in $VOLUMES | |
do | |
SNAPSHOT=$( aws ec2 describe-snapshots\ | |
--filters "Name=volume-id,Values=${VOLUME_ID}" "Name=progress,Values=100%"\ | |
--query "reverse(sort_by(Snapshots,&StartTime))[].[StartTime][0]"\ | |
--output text | grep "${DATE}" ) | |
if [ -z "$SNAPSHOT" ]; then | |
logger -is -p user.info -t "EBS-SNAPSHOT" "ERROR ${VOLUMES}" | |
fi | |
done | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment