Azure Storage Blob Lifecycle Management

Blob Lifecycle Management

Blob lifecycle management provides a cost-effective way to manage the data in your Azure Blob Storage account. You can use it to automatically move blobs between different access tiers (Hot, Cool, and Archive) or to delete blobs at the end of their lifecycle. This can help you optimize costs by moving less frequently accessed data to cheaper tiers, or by deleting data that is no longer needed.

Key Features

Scenarios

Lifecycle management is ideal for a variety of scenarios, including:

How it Works

You define lifecycle management rules within your Azure Storage account. Each rule consists of:

  1. Scope: The rule can apply to a specific container or all containers in the storage account. You can further refine this scope using a blob prefix.
  2. Rules: Within each rule, you can define one or more actions that apply to blobs matching certain conditions.
  3. Conditions: These specify when an action should be taken. Common conditions include:
    • Days after creation: The number of days since the blob was created.
    • Days after last modification: The number of days since the blob was last modified.
    • Days after last access: The number of days since the blob was last accessed. (Requires setting last-access-time tracking)
  4. Actions: These are the operations performed when conditions are met. Common actions include:
    • Transition action: Move the blob to a different access tier (e.g., Hot to Cool, Cool to Archive).
    • Delete action: Permanently delete the blob.

Example Policy Configuration

Here's an example of a lifecycle management policy that manages data based on access frequency and retention period:


{
  "actions": {
    "baseBlob": {
      "type": "Lifecycle",
      "rules": [
        {
          "name": "archive_old_data",
          "enabled": true,
          "type": "object",
          "definition": {
            "filters": {
              "blobTypes": ["blockBlob"],
              "prefixMatch": ["logs/"]
            },
            "actions": {
              "version": [
                {
                  "name": "delete",
                  "daysAfterCreationGreaterThan": 365
                }
              ],
              "base": [
                {
                  "name": "move",
                  "daysAfterLastAccessGreaterThan": 90,
                  "tier": "Archive"
                },
                {
                  "name": "move",
                  "daysAfterModificationGreaterThan": 180,
                  "tier": "Cool"
                }
              ]
            }
          }
        },
        {
          "name": "delete_temp_files",
          "enabled": true,
          "type": "object",
          "definition": {
            "filters": {
              "blobTypes": ["blockBlob"],
              "prefixMatch": ["temp/"]
            },
            "actions": {
              "base": [
                {
                  "name": "delete",
                  "daysAfterCreationGreaterThan": 30
                }
              ]
            }
          }
        }
      ]
    }
  }
}
            

Best Practices

By effectively implementing Blob lifecycle management, you can significantly reduce your Azure Storage costs and streamline your data management operations.