Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 666
Layman Avatar asked Dec 16 '18 07:12

Layman


People also ask

Does blob storage support storage tiers?

Azure offers three storage tiers to store data in blob storage: Hot Access tier, Cool Access tier, and Archive tier. These tiers target data at different stages of its lifecycle and offer cost-effective storage options for different use cases.

What blob tiers can be set at the account level?

GPv2 Storage account and Blob Storage Account type has 3 access tiers (hot,cool and archive). These account types are also called as Standard Performance Tiers. You can move data in between Hot, cold and archive.

What is blob access tier in Azure?

Azure Cool Blob storage tier is intended for data that you expect to access less often than once a month, but more often than once every six months or so. The cost per gigabyte to store data in the Cool tier is significantly lower than in the Hot tier.

When a blob is in the Archive access tier What must you do first before accessing it?

While a blob is in the Archive tier, it can't be read or modified. To read or download a blob in the Archive tier, you must first rehydrate it to an online tier, either Hot or Cool. Data in the Archive tier can take up to 15 hours to rehydrate, depending on the priority you specify for the rehydration operation.


1 Answers

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://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.blob.cloudblockblob?view=azure-dotnet

Hope this helps.

like image 188
Hannel Avatar answered Sep 27 '22 19:09

Hannel