如何使用AWS将现有卷从gp2修改为gp3?
我想试试剧本,
#! /bin/bash
region='us-east-1'
# Find all gp2 volumes within the given region
volume_ids=$(/usr/bin/aws ec2 describe-volumes --region "${region}" --filters Name=volume-type,Values=gp2 | jq -r '.Volumes[].VolumeId')
# Iterate all gp2 volumes and change its type to gp3
for volume_id in ${volume_ids};do
result=$(/usr/bin/aws ec2 modify-volume --region "${region}" --volume-type=gp3 --volume-id "${volume_id}" | jq '.VolumeModification.ModificationState' | sed 's/"//g')
if [ $? -eq 0 ] && [ "${result}" == "modifying" ];then
echo "OK: volume ${volume_id} changed to state 'modifying'"
else
echo "ERROR: couldn't change volume ${volume_id} type to gp3!"
fi
done要验证脚本是否像我们所期望的那样工作,但是只有一台机器,而不是所有使用gp2的机器?我需要对脚本做哪些更改?
发布于 2022-01-20 16:18:53
如果要在速度模式下进行测试,可以在包含第一个元素的条件之后在循环中添加一个中断:)
比如:
# Iterate all gp2 volumes and change its type to gp3
for volume_id in ${volume_ids};do
result=$(/usr/bin/aws ec2 modify-volume --region "${region}" --volume-type=gp3 --volume-id "${volume_id}" | jq '.VolumeModification.ModificationState' | sed 's/"//g')
if [ $? -eq 0 ] && [ "${result}" == "modifying" ];then
echo "OK: volume ${volume_id} changed to state 'modifying'"
break <====
else
echo "ERROR: couldn't change volume ${volume_id} type to gp3!"
fi
done但我建议您在第一次请求时更加具体,通过addind标记筛选器(Name)获取特定卷,以便只获得一个用于测试的卷EBS
发布于 2022-09-06 07:51:00
https://stackoverflow.com/questions/70789643
复制相似问题