Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
filename_instance_info="instance_info.txt"
profile_list="profile_list"
for profile_name in $(cat $profile_list)
do
export AWS_DEFAULT_PROFILE=$profile_name
# Get running instances
aws ec2 describe-instances --filters Name=instance-state-name,Values=running > $filename_instance_info
# Get EBS volumes of running instances
volumes_list=$(cat $filename_instance_info | grep "EBS" | awk '{print $5}')
tag_name_list=$(cat $filename_instance_info | grep "TAGS" | awk '{print $3}')
TAG_NAME_ARRAY={'tmp'}
i="0"
for tag_name in $tag_name_list
do
TAG_NAME_ARRAY=("${TAG_NAME_ARRAY[@]}" $tag_name)
done
# Create snapshots for $volumes_list
for volume in $volumes_list
do
i=$(($i + 1))
description="${volume}_${TAG_NAME_ARRAY[i]}_backup-`date +%Y-%m-%d`"
aws ec2 create-snapshot --volume-id $volume --description $description
echo $description
done
rm $filename_instance_info
unset TAG_NAME_ARRAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.