Lifecycles

+
~

Azure Blob Storage offers the ability to manage data lifecycles so that blobs are moved down through colder tiers and eventually expired as it gets older. With lifecycle management, you can:

Policies

A policy is a collection of rules, which in turn is a collection of filters and actions to apply to blobs in your storage.

Rules

{
  "rules": [
    {
      "name": "rule1",
      "enabled": true,
      "type": "Lifecycle",
      "definition": {...}
    },
    {
      "name": "rule2",
      "type": "Lifecycle",
      "definition": {...}
    }
  ]
}
Parameter name Parameter type Notes Required
name String A rule name can include up to 256 alphanumeric characters. Rule name is case-sensitive. It must be unique within a policy. True
enabled Boolean An optional boolean to allow a rule to be temporarily disabled. Default value is true. False
type An enum value The current valid type is Lifecycle. True
definition An object that defines the lifecycle rule Each definition is made up of a filter set and an action set. True

Actions and filters

Each rule definition contains a list of actions and a list of filters.

{
  "rules": [
	// rule
	{
      "enabled": true,
      "name": "sample-rule",
      "type": "Lifecycle",
      "definition": {
	    // actions
        "actions": {
          "baseBlob": {
            "tierToCool": {
              "daysAfterModificationGreaterThan": 30
            },
            "tierToArchive": {
              "daysAfterModificationGreaterThan": 90,
              "daysAfterLastTierChangeGreaterThan": 7
            },
            "delete": {
              "daysAfterModificationGreaterThan": 2555
            }
          },
          "snapshot": {
            "delete": {
              "daysAfterCreationGreaterThan": 90
            }
          }
        },
        // filters
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "sample-container/blob1"
          ]
        }
      }
    }
  ]
}

Filters

Filter name Type Is Required
blobTypes An array of predefined enum values. Yes
prefixMatch An array of strings for prefixes to be match. Each rule can define up to 10 prefixes. A prefix string must start with a container name. No
blobIndexMatch An array of dictionary values consisting of blob index tag key and value conditions to be matched. Each rule can define up to 10 blob index tag condition. No

Actions

Action Current Version Snapshot Previous Versions
tierToCool Supported for blockBlob Supported Supported
tierToCold Supported for blockBlob Supported Supported
enableAutoTierToHotFromCool Supported for blockBlob Not supported Not supported
tierToArchive Supported for blockBlob Supported Supported
delete Supported for blockBlob and appendBlob Supported Supported

With conditions:

Action run condition Condition value Description
daysAfterModificationGreaterThan Integer value indicating the age in days The condition for base blob actions
daysAfterCreationGreaterThan Integer value indicating the age in days The condition for blob snapshot actions
daysAfterLastAccessTimeGreaterThan Integer value indicating the age in days The condition for a current version of a blob when access tracking is enabled
daysAfterLastTierChangeGreaterThan Integer value indicating the age in days after last blob tier change time The minimum duration in days that a rehydrated blob is kept in hot, cool, or cold tiers before being returned to the archive tier. This condition applies only to tierToArchive actions.

Adding policies

Lifecycle policies can be added in Azure portal either through "list view" or "code view".

Storage Account > Data management > Lifecycle management > Code view (tab)

{
  "rules": [
    {
      "enabled": true,
      "name": "move-to-cool",
      "type": "Lifecycle",
      "definition": {
        "actions": {
          "baseBlob": {
            "tierToCool": {
              "daysAfterModificationGreaterThan": 30
            }
          }
        },
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "sample-container/log"
          ]
        }
      }
    }
  ]
}

You can also add policies via the Azure CLI. The CLI accepts a full JSON document of rules to replace to current rules. Partial updates are not supported.

az storage account management-policy create \
   --account-name <storage-account> \
   --policy @policy.json \
   --resource-group <resource-group>