问题描述
需要计算 ADLS Gen2 中特定容器和文件夹的大小。
从命令 az storage fs file list
开始。但是不明白如何获取 next_marker ?它作为警告出现在标准输出中,但不在命令输出中:
WARNING: Next Marker:
WARNING: VBbYvMrBhcCCqheySAAAA=
那么如何获得这个 next_marker:
$files=$(az storage fs file list --file-system <container name>\
--auth-mode login --account-name <account name> \
--query "[*].[contentLength]" --num-results 1000 -o tsv)
$files.next_marker 为空。
UPDATE1:创建问题 https://github.com/Azure/azure-cli/issues/16893
解决方法
如果您使用这个 azure cli 命令:az storage fs file list,next_marker
不会返回到变量 $files
,它总是在控制台中打印出来。您需要复制并粘贴它。
作为一种解决方法,您可以使用此 azure cli 命令:az storage blob list(大多数 azure blob storage
cli 命令也可在 ADLS Gen2
中使用)。这个命令有一个参数--show-next-marker
,你可以用它把next_marker
返回给一个变量。
我编写了一个 azure cli 脚本,它可以很好地用于 ADLS Gen2
:
$next_token = ""
$blobs=""
$response = & az storage blob list --container-name your_file_system_in_ADLS_Gen2 --account-name your_ADLS_Gen2_account --account-key your_ADLS_Gen2_key --num-results 5 --show-next-marker | ConvertFrom-Json
$blobs += $response.properties.contentLength
$next_token = $response.nextMarker
while ($next_token -ne $null){
$response = & az storage blob list --container-name your_file_system_in_ADLS_Gen2 --account-name your_ADLS_Gen2_account --account-key your_ADLS_Gen2_key --num-results 5 --marker $next_token --show-next-marker | ConvertFrom-Json
$blobs = $blobs + " " + $response.properties.contentLength
$next_token = $response.nextMarker
}
$blobs
测试结果:
请注意将您的 azure cli 升级到最新版本,根据 this issue,--show-next-marker
参数在旧版本中可能不起作用。