Azure Blob Storage lifecycle management offers a cost-effective way to manage blobs throughout their lifetime. You can define rules to automatically transition blobs between different access tiers (Hot, Cool, Archive) or delete them based on rules that you define.
Key Concepts
- Rules: Define criteria for applying lifecycle management actions to blobs.
- Actions: Operations that can be performed on blobs, such as transitioning to a different tier or deleting them.
- Filters: Specify which blobs a rule should apply to, based on blob prefixes, tags, or the last modified date.
- Access Tiers: Hot, Cool, and Archive tiers offer different price points and access speeds.
How Lifecycle Management Works
Lifecycle management policies are applied at the storage account level. A policy is a collection of rules. Each rule consists of:
- Scope: All blobs or a subset of blobs defined by a filter.
- Filters: Criteria to select blobs. Common filters include:
- Blob prefix: Matches blobs with a specific path.
- Blob tags: Matches blobs with specific key-value tags.
- Last modified date: Filters blobs based on when they were last modified.
- Actions: The operations to perform on the filtered blobs. These can include:
- Transition to Cool: Move blobs to the Cool tier after a specified number of days.
- Transition to Archive: Move blobs to the Archive tier after a specified number of days.
- Delete: Permanently delete blobs after a specified number of days.
Important Considerations
The cool tier is optimized for storing data that is accessed less frequently but requires rapid access when needed. The archive tier is optimized for storing data that is rarely accessed and allows for the lowest storage costs but the longest retrieval times. Ensure your access patterns align with the tier characteristics.
Creating a Lifecycle Management Policy
You can create lifecycle management policies using the Azure portal, Azure CLI, PowerShell, or the Storage Management REST API.
Using Azure Portal
- Navigate to your storage account in the Azure portal.
- Under "Data management," select "Lifecycle management."
- Click "Add a rule."
- Configure the rule name, scope, filters, and actions as needed.
- Save the rule.
Using Azure CLI
Here's an example of how to create a rule to move blobs with a prefix of logs/ to the Cool tier after 30 days and to the Archive tier after 90 days:
az storage lifecycle-management policy create \
--account-name <your-storage-account-name> \
--policy '{
"rules": [
{
"name": "transition-to-cool-and-archive-logs",
"enabled": true,
"type": "Management",
"definition": {
"actions": {
"version": {
"tierToCool": {"daysAfterModificationGreaterThan": 30},
"tierToArchive": {"daysAfterModificationGreaterThan": 90}
},
"baseBlob": {
"tierToCool": {"daysAfterModificationGreaterThan": 30},
"tierToArchive": {"daysAfterModificationGreaterThan": 90}
}
},
"filters": {
"prefix": ["logs/"]
}
}
}
]
}'
Understanding DaysAfterModificationGreaterThan
This parameter defines the number of days after a blob's last modification date to trigger the action. For versioning, it applies to the base blob's last modification date.
Monitoring Lifecycle Management
You can monitor the execution of your lifecycle management rules using Azure Monitor. This includes viewing metrics related to rule execution and troubleshooting any issues.
Best Practices
- Start with a small set of rules and test thoroughly.
- Use descriptive names for your rules.
- Regularly review your lifecycle management policies to ensure they still meet your business needs and cost optimization goals.
- Consider using blob tags for more granular control over which blobs are managed.
Tip
Combine lifecycle management with Blob Versioning and Soft Delete for comprehensive data protection and cost management.
By effectively using Azure Blob Storage lifecycle management, you can significantly reduce your storage costs while ensuring your data is accessible when you need it.