Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- _INSTANCE_ID="${YOUR_INSTANCE_ID}"
- _ROOT_DEVICE="/dev/sda1"
- _CHECK_INTERVAL=60
- echo "処理を続行しますか? [Y/n]"
- read ANSWER
- case ${ANSWER} in
- [yY]) echo "処理を続行します..."
- ;;
- [nN]) echo "$(date '+%Y-%m-%d %H:%M:%S') 処理を終了します..."
- exit 0 ;;
- *) echo "$(date '+%Y-%m-%d %H:%M:%S') 処理を終了します..."
- exit 0 ;;
- esac
- if [ -f tmp/snapshot_ids ];then
- rm tmp/snapshot_ids
- fi
- for ebs in $(aws ec2 describe-instances --filters Name=instance-id,Values=${_INSTANCE_ID} --query 'Reservations[].Instances[].BlockDeviceMappings[].Ebs.VolumeId' --output text);
- do
- _SNAPSHOT_ID=$(aws ec2 create-snapshot --volume-id ${ebs} | jq -r .SnapshotId)
- echo ${_SNAPSHOT_ID} >> tmp/snapshot_ids
- _DEVICE=$(aws ec2 describe-volumes --volume-ids ${ebs} --query Volumes[].Attachments[].Device --output text)
- if [ "${_DEVICE}" == "${_ROOT_DEVICE}" ];then
- aws ec2 create-tags --resources ${_SNAPSHOT_ID} --tags Key=device,Value=${_DEVICE} Key=Name,Value="OS"
- else
- aws ec2 create-tags --resources ${_SNAPSHOT_ID} --tags Key=device,Value=${_DEVICE} Key=Name,Value="DATA"
- fi
- done
- if [ -f tmp/snapshot_ids -a $(wc -l tmp/snapshot_ids | awk '{print $1}') == 2 ];then
- echo ${_SLACK_CHANNEL} "スナップショットの作成を開始しました..."
- else
- echo ${_SLACK_CHANNEL} "スナップショットの作成に失敗しました.処理を中断します."
- exit 1
- fi
- aws ec2 wait snapshot-completed --snapshot-ids $(cat tmp/snapshot_ids)
- if [ $? == 0 ]; then
- echo "スナップショットの作成が完了しました."
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement