Lesson 5 of 5 Azure Blob Storage Data Management

Automating Tiering and Deletion with Lifecycle Management

Lifecycle management applies rules that tier and delete blobs as they age. This lesson explains policy structure, conditions and timing.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the filters, actions and conditions of a lifecycle rule.
  • Explain the requirements for last access time conditions.
  • Design a lifecycle rule for a retention requirement.

Policy structure

A storage account has one lifecycle management policy, a JSON document with up to 100 rules. Each rule has a name, an enabled flag, a filter and actions. Filters select blobTypes (blockBlob, and appendBlob for delete actions), prefixMatch values such as container/logs/, and blobIndexMatch conditions on blob index tags. Actions apply separately to the baseBlob, version (previous versions) and snapshot.

{
  "rules": [
    {
      "name": "age-out-logs",
      "enabled": true,
      "type": "Lifecycle",
      "definition": {
        "filters": { "blobTypes": [ "blockBlob" ], "prefixMatch": [ "logs/" ] },
        "actions": {
          "baseBlob": {
            "tierToCool":    { "daysAfterModificationGreaterThan": 30 },
            "tierToArchive": { "daysAfterModificationGreaterThan": 90 },
            "delete":        { "daysAfterModificationGreaterThan": 365 }
          },
          "version": { "delete": { "daysAfterCreationGreaterThan": 90 } }
        }
      }
    }
  ]
}

Actions include tierToCool, tierToCold, tierToArchive, delete and enableAutoTierToHotFromCool. Conditions are daysAfterModificationGreaterThan, daysAfterCreationGreaterThan (for versions, snapshots and base blobs), daysAfterLastAccessTimeGreaterThan and daysAfterLastTierChangeGreaterThan. When several actions apply to the same blob, the cheapest outcome wins: delete before archive, archive before cool.

The following diagram shows how a lifecycle policy moves telemetry blobs between tiers over time for each prefix.

A lifecycle policy for telemetry. Blobs under raw/ move to Cool after 14 days, Archive after 60 and are deleted after 730 days; retrieval within a day fits Archive's standard rehydration. A version action deletes previous versions after 30 days, and curated/ is excluded from tiering by the rule's prefix filter.
The rule is abbreviated; the timeline is to scale.
Scenario questions

Reading a lifecycle rule

Exam skills 2.3.6

Read lifecycle rules and predict what they do.

Log in to try this activity Interactive activities are free with an account.

Last access time and timing

Rules based on last access time move blobs that nobody reads, regardless of when they were written, and enableAutoTierToHotFromCool moves a cool blob back to Hot when it is read again. These conditions require access tracking to be enabled on the lifecycle management page, which adds a small transaction cost. The policy runs about once a day, and a new or changed policy can take up to 24 hours to go into effect, after which actions can take time to complete on large accounts.

Lifecycle management is supported for general-purpose v2 and premium block blob accounts (in premium accounts, only delete actions apply). It is configured in the portal's Lifecycle management page with a list view wizard or a code view, with az storage account management-policy create, or in templates.

True or false

Timing and access tracking

Exam skills 2.3.6

Check when lifecycle rules run and what access-based rules need.

Log in to try this activity Interactive activities are free with an account.
Worked example

Designing a rule

Telemetry blobs under raw/ are read heavily for 14 days, occasionally until 60 days, and must be kept for two years for compliance with retrieval within a day. Blobs under curated/ must never be tiered. Old blob versions must be removed after 30 days. How should the lifecycle policy be designed?

Create a rule filtered on prefixMatch: raw/ with tierToCool after 14 days, tierToArchive after 60 days and delete after 730 days since modification; Archive's standard rehydration fits retrieval within a day. Add a version action to delete previous versions 30 days after creation, in the same or a separate rule without a prefix if it applies to all blobs. Blobs under curated/ are unaffected because no tiering rule matches their prefix.

Check yourself

A lifecycle rule uses daysAfterLastAccessTimeGreaterThan but never moves any blobs. What is missing?

Show answer

Last access time tracking, which must be enabled for access-based conditions.

Exam Tips

Remember for the exam

  • Up to 100 rules per policy; filters by prefix, blob type and index tags.
  • Last access time conditions require access tracking.
  • New policies take up to 24 hours to apply.
  • Separate actions for base blobs, previous versions and snapshots.