0
0
Azurecloud~5 mins

Storage tier optimization in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Storage tier optimization helps you save money by moving your data to different storage types based on how often you use it. It automatically moves data to cheaper storage when you don't need it often and brings it back when you do.
When you have files that are rarely accessed but must be kept for a long time, like backups or archives.
When you want to reduce storage costs by moving old data to cheaper storage automatically.
When you want to keep frequently used data quickly accessible while saving money on less used data.
When you want to manage storage costs without manually moving files between storage types.
When you want to set rules that automatically move data between hot, cool, and archive storage tiers.
Config File - storage-lifecycle-policy.json
storage-lifecycle-policy.json
{
  "rules": [
    {
      "name": "move-to-cool-after-30-days",
      "enabled": true,
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": ["blockBlob"]
        },
        "actions": {
          "baseBlob": {
            "tierToCool": {
              "daysAfterModificationGreaterThan": 30
            }
          }
        }
      }
    },
    {
      "name": "move-to-archive-after-90-days",
      "enabled": true,
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": ["blockBlob"]
        },
        "actions": {
          "baseBlob": {
            "tierToArchive": {
              "daysAfterModificationGreaterThan": 90
            }
          }
        }
      }
    }
  ]
}

This JSON file defines lifecycle rules for Azure Blob Storage.

  • rules: A list of rules to manage data movement.
  • move-to-cool-after-30-days: Moves blobs to the cool tier if they haven't changed for 30 days.
  • move-to-archive-after-90-days: Moves blobs to the archive tier if they haven't changed for 90 days.
  • filters: Applies only to block blobs.
  • actions: Defines the tier change actions based on days since last modification.
Commands
This command applies the lifecycle policy to the storage account named 'mystorageaccount' in the resource group 'myresourcegroup'. It tells Azure to start moving blobs between tiers based on the rules in the JSON file.
Terminal
az storage account management-policy create --account-name mystorageaccount --resource-group myresourcegroup --policy @storage-lifecycle-policy.json
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount/managementPolicies/default", "name": "default", "type": "Microsoft.Storage/storageAccounts/managementPolicies", "policy": { "rules": [ { "name": "move-to-cool-after-30-days", "enabled": true, "type": "Lifecycle", "definition": { "filters": { "blobTypes": ["blockBlob"] }, "actions": { "baseBlob": { "tierToCool": { "daysAfterModificationGreaterThan": 30 } } } } }, { "name": "move-to-archive-after-90-days", "enabled": true, "type": "Lifecycle", "definition": { "filters": { "blobTypes": ["blockBlob"] }, "actions": { "baseBlob": { "tierToArchive": { "daysAfterModificationGreaterThan": 90 } } } } } ] } }
--account-name - Specifies the storage account to apply the policy
--resource-group - Specifies the resource group of the storage account
--policy - Points to the lifecycle policy JSON file
This command shows the current lifecycle management policy applied to the storage account. It helps verify that the policy was set correctly.
Terminal
az storage account management-policy show --account-name mystorageaccount --resource-group myresourcegroup
Expected OutputExpected
{ "policy": { "rules": [ { "name": "move-to-cool-after-30-days", "enabled": true, "type": "Lifecycle", "definition": { "filters": { "blobTypes": ["blockBlob"] }, "actions": { "baseBlob": { "tierToCool": { "daysAfterModificationGreaterThan": 30 } } } } }, { "name": "move-to-archive-after-90-days", "enabled": true, "type": "Lifecycle", "definition": { "filters": { "blobTypes": ["blockBlob"] }, "actions": { "baseBlob": { "tierToArchive": { "daysAfterModificationGreaterThan": 90 } } } } } ] } }
--account-name - Specifies the storage account to check
--resource-group - Specifies the resource group of the storage account
Key Concept

If you remember nothing else from this pattern, remember: lifecycle policies automatically move data to cheaper storage tiers based on how long data is unused, saving money without manual effort.

Common Mistakes
Not enabling the lifecycle rules in the policy JSON.
If rules are not enabled, Azure will ignore them and no data movement happens.
Always set "enabled": true for each rule you want active.
Applying the policy to the wrong storage account or resource group.
The policy won't apply if the account or group names are incorrect, causing confusion and no cost savings.
Double-check the storage account and resource group names before running the command.
Using incorrect blob types in filters, like missing 'blockBlob'.
The rules won't apply to the blobs you want to manage, so data stays in the expensive tier.
Specify the correct blob types in the filters section, usually "blockBlob" for most blobs.
Summary
Create a lifecycle policy JSON file defining rules to move blobs to cool and archive tiers after set days.
Apply the lifecycle policy to your Azure storage account using the Azure CLI.
Verify the policy is active by showing the current management policy on the storage account.