Azure Blob Storage Lifecycle Management
Lifecycle management policies for Azure Blob Storage help you manage your data throughout its lifecycle. You can use these policies to transition blobs to cooler access tiers or to expire blobs at the end of their lifecycles. This policy is defined and applied using a JSON structure.
JSON Policy Structure
A lifecycle management policy is an array of rules. Each rule consists of a filter that selects which blobs the rule applies to, and an action that defines what to do with those blobs.
Example Policy (JSON)
{
"rules": [
{
"name": "ArchiveOldBlobs",
"enabled": true,
"type": "Lifecycle",
"definition": {
"actions": {
"version": [
{
"name": "archive",
"daysAfterCreationGreaterThan": 365,
"actionType": "MoveToArchive"
},
{
"name": "delete",
"daysAfterCreationGreaterThan": 730,
"actionType": "Delete"
}
],
"snapshot": [
{
"name": "archive",
"daysAfterCreationGreaterThan": 365,
"actionType": "MoveToArchive"
},
{
"name": "delete",
"daysAfterCreationGreaterThan": 730,
"actionType": "Delete"
}
],
"object": [
{
"name": "archive",
"daysAfterModificationGreaterThan": 30,
"actionType": "MoveToCool"
},
{
"name": "archive",
"daysAfterModificationGreaterThan": 365,
"actionType": "MoveToArchive"
},
{
"name": "delete",
"daysAfterModificationGreaterThan": 730,
"actionType": "Delete"
}
]
},
"filters": {
"blobTypes": [
"block"
],
"prefixMatch": [
"container1/logs/",
"container2/archive/"
]
}
}
},
{
"name": "DeleteTempFiles",
"enabled": true,
"type": "Lifecycle",
"definition": {
"actions": {
"object": [
{
"name": "delete",
"daysAfterModificationGreaterThan": 7,
"actionType": "Delete"
}
]
},
"filters": {
"blobTypes": [
"append",
"block"
],
"prefixMatch": [
"temp/"
]
}
}
}
]
}
Policy Definition Details
rules
- An array containing one or more lifecycle rules.
name
- A unique name for the rule (e.g., "ArchiveOldBlobs").
enabled
- Boolean value indicating whether the rule is active (
true
) or inactive (false
). type
- Must be
"Lifecycle"
. definition
- Contains the actions and filters for the rule.
definition.actions
-
Specifies the actions to be taken on blobs. Supports actions for
object
,version
, andsnapshot
. -
Within each action type (e.g.,
object
), you can define multiple actions, each with aname
, a condition (e.g.,daysAfterModificationGreaterThan
), and anactionType
. actions[*].actionType
-
Possible values include:
MoveToCool
MoveToArchive
Delete
actions[*].daysAfterCreationGreaterThan
- Applies to blob versions and snapshots. Triggers action when blob version/snapshot is older than specified days from creation.
actions[*].daysAfterModificationGreaterThan
- Applies to current blob objects. Triggers action when the blob's last modified time is older than specified days.
actions[*].daysAfterLastAccessTimeGreaterThan
- Applies to current blob objects. Triggers action when the blob's last access time is older than specified days (requires Last-Access-Time-Tracking to be enabled).
definition.filters
- Specifies criteria to select which blobs the rule applies to.
filters.blobTypes
-
An array of blob types to filter (e.g.,
["block"]
,["append"]
,["block", "append"]
). If omitted, applies to all blob types. filters.prefixMatch
-
An array of strings representing blob prefixes. Blobs starting with any of these prefixes will be matched.
(e.g.,
["logs/", "archive/"]
). filters.includeBlobIndexes
-
An array of blob index tag conditions. Blobs with matching tags will be selected.
(e.g.,
[{"name": "Environment", "op": "equals", "value": "Production"}]
).
Key Considerations
- Order of Operations: Actions within a rule are evaluated in the order they appear. The first matching condition triggers the action.
- Rehydration Costs: Moving blobs from Archive tier to Hot or Cool incurs rehydration costs and takes time. Plan accordingly.
- Last Access Time Tracking: Enabling
daysAfterLastAccessTimeGreaterThan
requires the Last-Access-Time-Tracking feature to be enabled at the storage account level. - Versioning and Snapshots: Lifecycle management can be applied to blob versions and snapshots independently of the current blob.
Applying the Policy
Lifecycle policies can be applied at the storage account level through the Azure portal, Azure CLI, Azure PowerShell, or REST API. The JSON structure shown above is used when interacting programmatically.