Configure a lifecycle management policy

Azure Storage lifecycle management offers a rule-based policy that you can use to transition blob data to the appropriate access tiers or to expire data at the end of the data lifecycle. A lifecycle policy acts on a base blob, and optionally on the blob's versions or snapshots. For more information about lifecycle management policies, see Optimize costs by automatically managing the data lifecycle.

A lifecycle management policy is comprised of one or more rules that define a set of actions to take based on a condition being met. For a base blob, you can choose to check one of two conditions:

  • The number of days since the blob was last modified.
  • The number of days since the blob was last accessed. To use this condition in an action, you must first optionally enable access time tracking.

When the selected condition is true, then the management policy performs the specified action. For example, if you have defined an action to move a blob from the hot tier to the cool tier if it has not been modified for 30 days, then the lifecycle management policy will move the blob 30 days after the last write operation to that blob.

For a blob snapshot or version, the condition that is checked is the number of days since the snapshot or version was created.

Optionally enable access time tracking

Before you configure a lifecycle management policy, you can choose to enable blob access time tracking. When access time tracking is enabled, a lifecycle management policy can include an action based on the time that the blob was last accessed with a read or write operation.

To enable last access time tracking with the Azure portal, follow these steps:

  1. Navigate to your storage account in the Azure portal.

  2. In the Data management section, select Enable access tracking.

    Screenshot showing how to enable last access tracking in Azure portal

Use the daysAfterLastAccessTimeGreaterThan property to specify the number of days from last access after which an action should be taken on a blob.

Create or manage a policy

You can add, edit, or remove a lifecycle management policy with the Azure portal, PowerShell, Azure CLI, or an Azure Resource Manager template.

There are two ways to add a policy through the Azure portal.

List view

  1. In the Azure portal, navigate to your storage account.

  2. Under Data management, select Lifecycle Management to view or change lifecycle management policies.

  3. Select the List View tab.

  4. Select Add a rule and name your rule on the Details form. You can also set the Rule scope, Blob type, and Blob subtype values. The following example sets the scope to filter blobs. This causes the Filter set tab to be added.

    Lifecycle management add a rule details page in Azure portal

  5. Select Base blobs to set the conditions for your rule. In the following example, blobs are moved to cool storage if they haven't been modified for 30 days.

    Lifecycle management base blobs page in Azure portal

    The Last accessed option is available only if you have enabled access time tracking. To learn how to enable access tracking, see Optionally enable access time tracking.

  6. If you selected Limit blobs with filters on the Details page, select Filter set to add an optional filter. The following example filters on blobs whose name begins with log in a container called sample-container.

    Lifecycle management filter set page in Azure portal

  7. Select Add to add the new policy.

Code view

  1. In the Azure portal, navigate to your storage account.
  2. Under Data management, select Lifecycle Management to view or change lifecycle management policies.
  3. Select the Code View tab. On this tab, you can define a lifecycle management policy in JSON.

The following sample JSON defines a lifecycle policy that moves a block blob whose name begins with log to the cool tier if it has been more than 30 days since the blob was modified.

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

A lifecycle management policy must be read or written in full. Partial updates are not supported.

Note

If you enable firewall rules for your storage account, lifecycle management requests may be blocked. You can unblock these requests by providing exceptions for trusted Microsoft services. For more information, see the Exceptions section in Configure firewalls and virtual networks.

See also