Layman
Layman

Reputation: 1056

Change tier in bulk for Azure blob storage

I have some thousands of blobs with a given suffix I want to assign to a new tier (hot to archive) in bulk. I know it is possible to manually change the tier on portal or through a REST request pointing to a specific blob. Is there a way to set tiers in bulk with a wildcard or something similar?

Upvotes: 6

Views: 3252

Answers (1)

Hannel
Hannel

Reputation: 1716

It's really as simple as 3 lines.

#Get stroage account 
$straccount = Get-AzureRmStorageAccount -Name xxxxxx -ResourceGroupName xxxxxxxxxxxxx

#Get all the blobs in container
$blobs = Get-AzureStorageBlob -Container test -Context $straccount.Context

#Set tier of all the blobs to Archive
$blobs.icloudblob.setstandardblobtier("Archive") 

Just make sure the container only have block blob or you will get error. Last i checked Archive tier is only support by block blob.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.blob.cloudblockblob?view=azure-dotnet

Hope this helps.

Upvotes: 10

Related Questions