一种方法是使用gcloud 的键和标志:projections、--format、--filters。要直接从终端阅读更多内容,请使用gcloud topic,例如:
gcloud topic projections
要查看可用的字段/属性,请使用--format=flattened,例如:
gcloud app services list --format=flattened
为了简单起见,除了gcloud,我将把所有东西都放在外面。
for SERVICE in $(gcloud app services list --format='table[no-heading](id)'); do
echo "for service $SERVICE :"
RECENT=$(gcloud app versions list --format='table[no-heading](id)' --filter="service=$SERVICE" | tail -n1)
echo 'y' | gcloud app versions start $RECENT
VERSIONS=$(gcloud app versions list --format='table[no-heading](id)' --filter="service=$SERVICE AND version.servingStatus=SERVING AND NOT id=$RECENT" | tr '\n' ' ')
echo 'y' | gcloud app versions stop $VERSIONS
done
'table[no-heading](service)' 输出一个没有标题的表格,它被设置在括号中,以及一个带有服务 ID 的列,它被设置在括号中。
--filter="service=$SERVICE AND version.servingStatus=SERVING AND NOT id=$RECENT" 将仅显示来自指定服务的正在服务的版本,RECENT 指定的版本除外。
此外,如果您想使用日期进行过滤:
gcloud app versions list --format='table(id, version.servingStatus, version.createTime.date(format="%s"))' --filter="service=default" --sort-by="~version.createTime"
version.createTime.date(format="%s") 是一个function date 将version.createTime.date 转换为自纪元以来的秒数。
%s 来自strftime(3) 并以更易于理解和比较的 Epoch 格式返回日期。
--sort-by="~version.createTime"按创建日期排序,因为~按降序排列。