Last active
December 17, 2020 15:17
-
-
Save sgnn7/d27fb0ab6e2cb29d466198ced9ea93df to your computer and use it in GitHub Desktop.
Wait for AWS EC2 snapshot or volume for longer than 20 mins
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
#!/bin/bash -e | |
EC2_REGION="us-west-1" | |
DEFAULT_PROGRESS_WAIT=5 | |
# ========== SNAPSHOT WAIT ============== | |
snapshot_id="snap-testtesttest" | |
while [ "$snapshot_progress" != "100%" ]; do | |
sleep "$DEFAULT_PROGRESS_WAIT" | |
snapshot_progress=$(aws ec2 describe-snapshots --region $EC2_REGION \ | |
--snapshot-ids "$snapshot_id" \ | |
--no-paginate \ | |
--query "Snapshots[*].Progress" \ | |
--output text) | |
echo "Snapshot progress: $snapshot_id $snapshot_progress" | |
done | |
aws ec2 wait snapshot-completed --region $EC2_REGION \ | |
--snapshot-ids "$snapshot_id" | |
echo "- Snapshot done: $snapshot_id" | |
# ========== VOLUME WAIT ============== | |
new_volume_id="vol-testtesttest" | |
while [ "$volume_status" != "available" ]; do | |
sleep "$DEFAULT_PROGRESS_WAIT" | |
volume_status=$(aws ec2 describe-volumes --region $EC2_REGION \ | |
--volume-ids "$new_volume_id" \ | |
--no-paginate \ | |
--query "Volumes[*].State" \ | |
--output text) | |
echo "Volume progress: $new_volume_id $volume_status" | |
done | |
aws ec2 wait volume-available --region $EC2_REGION \ | |
--no-paginate \ | |
--volume-ids $new_volume_id | |
echo "- Volume ready: $new_volume_id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment