You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure存储账户大小在CLI与Azure门户中显示不一致

Azure CLI脚本计算存储容器容量与门户差异巨大的排查方案

核心问题

Azure门户显示存储账户总容量约100GB,但通过PowerShell+Azure CLI脚本仅算出目标容器容量600MB,实际下载单个文件夹已超1GB,且已排除版本、快照、其他存储服务(文件共享/队列/表)的影响,小容器测试脚本结果正常。

排查与解决方向

1. 遗漏非块Blob类型

默认az storage blob list仅返回块Blob,若存储中存在大量追加Blob或页Blob,脚本会直接漏掉这部分容量。

  • 修复命令:添加--include all参数覆盖所有Blob类型
$blobSizes = az storage blob list --container-name $container --account-name $account --include all --query "[].properties.contentLength" --output json | ConvertFrom-Json

2. 未统计归档层Blob

门户会统计归档存储层的Blob容量,但默认CLI命令不会返回离线的归档Blob,导致容量计算缺失。

  • 修复命令:添加--include archived参数(需配合--include all)
$blobSizes = az storage blob list --container-name $container --account-name $account --include all,archived --query "[].properties.contentLength" --output json | ConvertFrom-Json

3. 权限不足导致部分Blob无法读取

若当前CLI身份未拥有容器的Storage Blob Data Reader权限,可能无法读取全部Blob(尤其是深层目录或特殊权限的Blob)。

  • 验证方法:使用存储账户密钥直接调用命令,排除RBAC权限问题
# 获取存储账户密钥
$accountKey = (az storage account keys list --account-name $account --query "[0].value" --output tsv)
# 用密钥执行Blob列表查询
$blobSizes = az storage blob list --container-name $container --account-name $account --account-key $accountKey --include all,archived --query "[].properties.contentLength" --output json | ConvertFrom-Json

4. Blob数量与门户不匹配

先验证CLI返回的Blob总数是否和门户一致,确认是否存在未被遍历的Blob:

# 统计CLI返回的Blob数量
$cliBlobCount = (az storage blob list --container-name $container --account-name $account --include all,archived --output json | ConvertFrom-Json).Count
# 对比门户中该容器的Blob总数
Write-Output "CLI返回Blob数量:$cliBlobCount"

5. 优化contentLength过滤逻辑

原脚本用字符串匹配^\d+$过滤有效容量,可能误判数字类型的contentLength(如int64类型),调整为类型检查:

$validSizes = $blobSizes | Where-Object { $_ -is [int64] -or $_ -is [double] -and $_ -ge 0 }

内容的提问来源于stack exchange,提问作者Manuel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 12:55:02