Last active
December 27, 2015 03:39
-
-
Save dwchiang/7261458 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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