Skip to content

Instantly share code, notes, and snippets.

@sumit-sampang-rai
Created July 25, 2018 07:12
Show Gist options
  • Save sumit-sampang-rai/487e3b947b1e896e216c73abc7edd1b3 to your computer and use it in GitHub Desktop.
Save sumit-sampang-rai/487e3b947b1e896e216c73abc7edd1b3 to your computer and use it in GitHub Desktop.
Take snapshots of AWS instances
PROFILE=srekcahrai;REGION=us-east-1;aws --profile=$PROFILE --region=$REGION ec2 describe-instances --filter Name='instance-state-name',Values='running' --output json | jq -r '.Reservations[].Instances[] | .InstanceId + "\t" + .BlockDeviceMappings[].Ebs.VolumeId' | while read instance_id volume_id;do aws --profile=$PROFILE --region=$REGION ec2 create-snapshot --volume-id="$volume_id" --description="$instance_id $volume_id $(date +"%F %T")";done;
PROFILE=srekcahrai;REGION=us-east-1;NAMETAG=srekcahrai;aws --profile=$PROFILE --region=$REGION ec2 describe-instances --filter Name='tag:Name',Values=$NAMETAG --output json| jq -r '.Reservations[].Instances[] | .InstanceId + "\t" + .BlockDeviceMappings[].Ebs.VolumeId' | while read instance_id volume_id;do aws --profile=$PROFILE --region=$REGION ec2 create-snapshot --volume-id="$volume_id" --description="$instance_id $volume_id $(date +"%F %T")";done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment