Getting Container Properties:
- az storage container show --name $containerName --account-name $storageAccountName --account-key NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==
Setting and Getting Container Metadata, the attention that the update command overwrites the existing container metadata
- az storage container metadata update --account-name $storageAccountName --name $containerName --metadata creationType=AzureCli --auth-mode key --account-key "P3o/5qMhTrI8rJgt34SPSaeLuv7ED6Szft5kAf7hixh2UiSwltBW52CG4FejDs3nhV4t2lAE/2XEAIAsUvKorA=="
- az storage container metadata show --account-name $storageAccountName --name $containerName --auth-mode key --account-key "P3o/5qMhTrI8rJgt34SPSaeLuv7ED6Szft5kAf7hixh2UiSwltBW52CG4FejDs3nhV4t2lAE/2XEAIAsUvKorA=="
Setting and Getting Blob Metadata, attention that the update command overwrites the existing blob metadata
- az storage blob metadata update --name "frequent.jpg" --account-name $storageAccountName --container-name $containerName --metadata creationType=azurecli --auth-mode key --account-key "P3o/5qMhTrI8rJgt34SPSaeLuv7ED6Szft5kAf7hixh2UiSwltBW52CG4FejDs3nhV4t2lAE/2XEAIAsUvKorA=="
- az storage blob metadata show --name "frequent.jpg" --account-name $storageAccountName --container-name $containerName --auth-mode key --account-key "P3o/5qMhTrI8rJgt34SPSaeLuv7ED6Szft5kAf7hixh2UiSwltBW52CG4FejDs3nhV4t2lAE/2XEAIAsUvKorA=="
Using .NET
Getting Container Properties
- private static readonly string connectionString = "DefaultEndpointsProtocol=https;AccountName=samplestorageaccountblob;AccountKey=NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==;EndpointSuffix=core.windows.net";
- private static readonly string containerName = "sampleblobcontainer";
- static async Task Main(string[] args)
- {
-
- Console.WriteLine("Program started. Connecting to Blob Client");
- BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
- BlobContainerClient containerClient = null;
-
- if (blobServiceClient.GetBlobContainers().Where(x => x.Name == containerName).Any())
- {
- Console.WriteLine("Blob Container Client found.");
- containerClient = blobServiceClient.GetBlobContainerClient(containerName);
- }
- else
- {
- Console.WriteLine("Blob Container Client not found, creating a new one.");
- containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
- Console.WriteLine("Blob Container Client created.");
- }
- var properties = containerClient.GetProperties();
- }
Setting and Getting Container Metadata, pay attention that the SetMetada method overwrites the existing metadata.
- private static readonly string connectionString = "DefaultEndpointsProtocol=https;AccountName=samplestorageaccountblob;AccountKey=P3o/5qMhTrI8rJgt34SPSaeLuv7ED6Szft5kAf7hixh2UiSwltBW52CG4FejDs3nhV4t2lAE/2XEAIAsUvKorA==;EndpointSuffix=core.windows.net";
- private static readonly string containerName = "sampleblobcontainer";
-
- static async Task Main(string[] args)
- {
-
- Console.WriteLine("Program started. Connecting to Blob Client");
- BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
- BlobContainerClient containerClient = null;
-
- if (blobServiceClient.GetBlobContainers().Where(x => x.Name == containerName).Any())
- {
- Console.WriteLine("Blob Container Client found.");
- containerClient = blobServiceClient.GetBlobContainerClient(containerName);
- }
- else
- {
- Console.WriteLine("Blob Container Client not found, creating a new one.");
- containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
- Console.WriteLine("Blob Container Client created.");
- }
- Dictionary<string, string> containerMetadata = new Dictionary<string, string>();
- containerMetadata.Add("creationType", ".Net SDK");
- containerMetadata.Add("seccondMetadata", ".Net SDK");
- containerClient.SetMetadata(containerMetadata);
- var containerProperties = containerClient.GetProperties();
- }
![]()
Setting and Getting Blob Metadata, pay attention that the SetMetada method overwrites the existing metadata.
- private static readonly string connectionString = "DefaultEndpointsProtocol=https;AccountName=samplestorageaccountblob;AccountKey=P3o/5qMhTrI8rJgt34SPSaeLuv7ED6Szft5kAf7hixh2UiSwltBW52CG4FejDs3nhV4t2lAE/2XEAIAsUvKorA==;EndpointSuffix=core.windows.net";
- private static readonly string containerName = "sampleblobcontainer";
- static async Task Main(string[] args)
- {
-
- Console.WriteLine("Program started. Connecting to Blob Client");
- BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
- BlobContainerClient containerClient = null;
-
- if (blobServiceClient.GetBlobContainers().Where(x => x.Name == containerName).Any())
- {
- Console.WriteLine("Blob Container Client found.");
- containerClient = blobServiceClient.GetBlobContainerClient(containerName);
- }
- else
- {
- Console.WriteLine("Blob Container Client not found, creating a new one.");
- containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
- Console.WriteLine("Blob Container Client created.");
- }
-
-
- Dictionary<string, string> blobMetadata = new Dictionary<string, string>();
- blobMetadata.Add("creationType", ".Net SDK");
- blobMetadata.Add("seccondMetadata", ".Net SDK");
- BlobClient client = containerClient.GetBlobClient("frequent.jpg");
- client.SetMetadata(blobMetadata);
- var blobMetadataValues = client.GetProperties().Value.Metadata;
- }
![]()
Result from Azure Portal
Moving items between Blob Storage and Containers
You can copy a single Blob or a Batch of Blobs, here we will be moving a batch of Blobs from one container to another inside the same Blob Storage Account.
The error here is due to the Rare.jpg being rehydrated.
- az storage blob copy start-batch --account-name $storageAccountName --destination-container "anothercontainer" --source-container $containerName --account-key NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==
Moving from one container to another inside another storage account.
- az storage blob copy start-batch --account-name "cloudshell325844558" --source-account-name $storageAccountName --source-container "anothercontainer" --destination-container "containeranotheraccount" --account-key Oc3mEd/80DqJ65+nxMUJb/C9nq/hre+YLdVEfXeZ7M3gvcwJ7zqB7SAzNaiRtPyOrEtYXBub9Wn4xVUgTv5BTw== --source-account-key NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==
Hot, Cool, and Archiving Storage
By default, when you create a Blob its access tier is set automatically to the one configured when creating Azure Storage. And by default, Blob Storages are created with the Hot Access Tier, in order to change the default access tier of the Storage Account, check the configuration tab under the settings sector.
To change the access tier of a blob you have to individually set its new access tier. We are going to organize the blobs according to their necessities: frequent image stays in the hot tier, not so frequent image stays in the cool tier and the rare image is going to be placed in the archiving tier.
- az storage blob set-tier --account-name $storageAccountName --container-name $containerName --name "not so frequent.png" --tier Cool --account-key NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==
- az storage blob set-tier --account-name $storageAccountName --container-name $containerName --name "rare.jpg" --tier Archive --account-key NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==
Result in Azure Portal
To move one item from Archive Access Tier to another Access Tier you can also set the rehydrate priority to high. This feature is still in preview mode.
- az storage blob set-tier --account-name $storageAccountName --container-name $containerName --name "rare.jpg" --tier Cool --rehydrate-priority high --account-key NSs2H9xg8DIpKH8y3EeYMiIpM1zYl/K9oAlBvDnPJaOpwUuS1GIwnbllIBuWngVpUYkpzmiRHdJiybgmGR3tag==
Implementing Archiving and Retention - Lifecycle Management