Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2722

バッチ処理で EBS ボリュームタイプを gp2 から gp3 に変更する

$
0
0
はじめに(要件) 今回の実施内容は、バッチ処理で EBS ボリュームタイプを gp2 から gp3 に変更します。 Case1: (変更前)gp2のIOPS < 3000の場合: (変更後)gp3のIOPSを3000、Throughputを125に設定します。 Case2: (変更前)gp2のIOPS > 3000の場合: (変更後)gp3のIOPSは変更前のgp2のIOPSと同じで、Throughputは125に設定します。 事前準備 ①input.txt(EBSボリュームIDを格納する) ②gp.sh(EBSボリュームタイプをgp2からgp3に変更の実行ファイル) ⇒バッチファイルの中身は以下の通りです。 #!/bin/bash # To get the exit IOPS of gp2, need to create a json file at first. echo '[' >> gp2.json cat input.txt | while read VOLUME_ID || [ -n "${VOLUME_ID}" ]; do aws ec2 describe-volumes --volume-ids $VOLUME_ID --output json >> gp2.json echo ',' >> gp2.json done < input.txt head -n -1 gp2.json > temp.json ; mv temp.json gp2.json sed '$ s/.$//' gp2.json echo ']' >> gp2.json # Get Volume length VOLUME_ID_LENGTH=$(jq length gp2.json) echo $VOLUME_ID_LENGTH for ((i=0; i < $VOLUME_ID_LENGTH; i++)); do IOPS=$(jq ".[$i].Volumes[0].Iops" gp2.json | tr -d '"') # echo $IOPS VOLUME_ID=$(jq ".[$i].Volumes[0].VolumeId" gp2.json | tr -d '"') # echo $VOLUME_ID # Change gp2 to gp3. if [ $IOPS -lt 3000 ] ; then echo "****************************************************************************" echo "IOPS is: $IOPS, VOLUMEID is: $VOLUME_ID. IOPS is less then 3000" echo "****************************************************************************" echo "Start to change gp2 to gp3(IPOS < 3000)" echo -n "問題がなければ、'Y'を入力してください: " read Key #---- if [ $Key = "Yes" ] || [ $Key = "yes" ] || [ $Key = "Y" ] || [ $Key = "y" ] || [ $Key = "YES" ] then VOLUME_ID=$(jq ".[$i].Volumes[0].VolumeId" gp2.json | tr -d '"') aws ec2 modify-volume --volume-id $VOLUME_ID --volume-type gp3 fi else echo "****************************************************************************" echo "IOPS is: $IOPS,VOLUME_ID is $VOLUME_ID. IOPS is over 3000" echo "****************************************************************************" echo "Start to change gp2 to gp3(IPOS > 3000)" echo -n "問題がなければ、'Y'を入力してください: " read Key if [ $Key = "Yes" ] || [ $Key = "yes" ] || [ $Key = "Y" ] || [ $Key = "y" ] || [ $Key = "YES" ] then VOLUME_ID=$(jq ".[$i].Volumes[0].VolumeId" gp2.json | tr -d '"') aws ec2 modify-volume --volume-id $VOLUME_ID --volume-type gp3 --iops $IOPS fi fi done rm gp2.json *2つのファイルは同一ディレクトリに格納する必要があります。 EBS ボリュームタイプをgp2からgp3に変更 STEP1 EBSのボリュームIDを「input.txt」に記入します。 STEP2 バッチ実行します。 Jenny:/Desktop/gp3$ ./gp.sh STEP3 コマンドを実行します。 出力内容を確認する。 問題がなければ、'Y'を入力してください: Y STEP4 結果を確認します。 無事に変更しましたね~

Viewing all articles
Browse latest Browse all 2722

Trending Articles