如何将 Azure 存储帐户中所有文件的访问层更改为“存档”?
答案1
您需要单独更改每个文件的访问层。以下是使用以下命令执行此操作的 powershell 脚本:Azure CLI:
https://gist.github.com/MattRuwe/f1a4e09a55fed89a7857ec00ec772028
$connectionString = "<ConnectionString>"
$containerName = "<ContainerName>"
$hotAccessTierFiles = az storage blob list --connection-string $connectionString --container-name $containerName --query "[?properties.blobTier=='Hot'].name" --num-results *
$hotAccessTierFilesObject = $hotAccessTierFiles | ConvertFrom-Json
$hotAccessTierFilesObject | % { az storage blob set-tier --connection-string $connectionString --container-name $containerName --name $_ --tier "Archive" }
答案2
我想出了自己的解决方案,我可以将页面存储在源代码控制中,而不需要连接字符串。
$resourceGroup = "<resourceGroup>"
$storageAccount = "<storageAccount>"
$containerName = "<containerName>"
$connectionString = az storage account show-connection-string --name $storageAccount --out tsv
$response =(az storage blob list --container-name $containerName --connection-string $connectionString --num-results 10 --show-next-marker) | ConvertFrom-Json
$next_token = $response.nextMarker
while ($next_token -ne $null)
{
foreach ($file in $response)
{
if ($file.properties.contentLength -gt 0 -and $file.properties.blobTier -eq 'Hot')
{
Write-Host "$($file.name):$($file.properties.contentLength)"
az storage blob set-tier --connection-string $connectionString --container-name $containerName --name $file.name --tier "Archive"
}
}
$response =(az storage blob list --container-name $containerName --connection-string $connectionString --num-results 10 --marker $next_token --show-next-marker) | ConvertFrom-Json
$next_token = $response.nextMarker
}