Skip to content

Instantly share code, notes, and snippets.

@mungi
Last active March 31, 2016 15:37
Show Gist options
  • Save mungi/7ddb3eafaecbf5fee404fc21c623e67c to your computer and use it in GitHub Desktop.
Save mungi/7ddb3eafaecbf5fee404fc21c623e67c to your computer and use it in GitHub Desktop.
#!/bin/bash
EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
export AWS_DEFAULT_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
if [ $# -eq 0 ]
then
echo "Need Filter Value eg. $0 web"
else
ec2list | grep $1 | awk '{print $3,$1}' | while read param;do
arr=($param)
aws ec2 create-image --no-reboot --instance-id ${arr[0]} --name Backup_$(date +%y%m%d-%H%M)_${arr[1]}_${arr[0]}
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment