This document provides an overview of Azure Blob Storage lifecycle management, enabling you to manage your blobs efficiently across different access tiers.
What is Lifecycle Management?
Azure Blob Storage lifecycle management provides a powerful way to manage your blobs across different tiers (Hot, Cool, Archive) and delete them at the end of their lifecycle. This helps you to:
- Optimize Storage Costs: Automatically move data to cooler tiers when it's accessed less frequently, reducing costs.
- Ensure Compliance: Retain data for a specified period and then delete it to meet regulatory requirements.
- Automate Operations: Reduce manual effort and the risk of errors by automating tiering and deletion policies.
Key Concepts
Access Tiers
Azure Blob Storage offers three tiers for different data access patterns:
- Hot Tier: For data that is accessed frequently. Offers the lowest access latency but the highest storage cost.
- Cool Tier: For data that is accessed infrequently. Offers higher access latency than the hot tier but lower storage costs.
- Archive Tier: For data that is rarely accessed and requires the longest retrieval time. Offers the lowest storage cost but the highest access latency (hours).
Lifecycle Rules
Lifecycle rules define the actions to be performed on blobs based on specific criteria. A rule consists of:
- Scope: The set of blobs the rule applies to (e.g., all blobs in a container, or blobs matching a prefix).
- Filters: Criteria for selecting blobs, such as creation date, last modification date, or blob type.
- Actions: Operations to perform on selected blobs, such as changing the access tier or deleting the blob.
Creating and Managing Lifecycle Rules
You can manage lifecycle rules using the Azure portal, Azure CLI, Azure PowerShell, or the Storage Management API.
Using the Azure Portal
- Navigate to your storage account in the Azure portal.
- Under "Data management", select "Lifecycle management".
- Choose to create a "Rule for blobs" or "Rule for blocks".
- Define the rule name, scope, filters, and actions.
- Save the rule.
Example Rule Configuration
Consider a rule to move infrequently accessed blobs older than 30 days to the Cool tier and delete blobs older than 365 days:
Rule 1: Move to Cool Tier
- Name: MoveToCool
- Scope: All blobs
- Filters: Last modified on or after 30 days
- Actions: Move blob to Cool tier
Rule 2: Delete Old Blobs
- Name: DeleteOldBlobs
- Scope: All blobs
- Filters: Last modified on or after 365 days
- Actions: Delete blob
Code Example (Azure CLI)
Here's how you might configure a rule using the Azure CLI:
az storage lifecycle-management policy create \
--account-name <storage-account-name> \
--policy '{
"rules": [
{
"name": "MoveToCool",
"enabled": true,
"type": "Lifecycle",
"definition": {
"actions": {
"version": {
"tierToCool": { "daysAfterCreationGreaterThan": 30 }
},
"baseBlob": {
"tierToCool": { "daysAfterModificationGreaterThan": 30 }
}
},
"filters": {
"blobTypes": [ "blockBlob" ]
}
}
},
{
"name": "DeleteOldBlobs",
"enabled": true,
"type": "Lifecycle",
"definition": {
"actions": {
"version": {
"delete": { "daysAfterCreationGreaterThan": 365 }
},
"baseBlob": {
"delete": { "daysAfterModificationGreaterThan": 365 }
}
},
"filters": {
"blobTypes": [ "blockBlob" ]
}
}
}
]
}'
Best Practices
- Start Simple: Begin with basic rules and expand as needed.
- Test Thoroughly: Before applying rules to production data, test them on a small subset of data.
- Monitor Performance: Regularly review your lifecycle management policies and their impact on costs and performance.
- Consider Blob Versioning: If enabled, ensure your rules account for blob versions as well.