Expire Data Based on Age in Azure Blob Storage (Blob Lifecycle Management)

In this blog , We will explore lifecycle management of blob storage from changing tiers (hot to cold) to archive.

Let’s say you are the web admin for an online shopping site. The holidays are coming, so you anticipate holiday themed items becoming popular in your store. You plan to showcase these items on the homepage, in which a web app retrieves the photos for these items from an Azure Storage account.

After the holiday season, you don’t want to keep these images, and the storage costs are too significant. You must find a way to automatically delete these photos after 30 days.How we can solve this problem ??

Let’s see in action through an example.

Upload the Photos to Blob Storage

Step 1– Let’s create a storage account and enable versioning.

Step 2– Create container name holdiaysale and upload some pics in img folder.

Add a Policy to the img Folder

  1. In the Data management section, click Lifecycle Management and add a new rule.
    • Name: 30days
    • Rule scope: Limit blobs with filters
    • Blob type: Block blobs
    • Blob subtype: Base blobs
  2. Click Next and add a new if/then block that deletes the blob after 30 days.
    • If: More than 30 days ago
    • Then: Delete the blob
  3. Click Next.
    • Prefix match: holidaysale/img

Click Next and update time and action (to delete blob or move some other tiers)

Choose action

Click Next and container with folder name as prefix (holidaysale/img)

After 30 days as per lifecycle management rule it will check folder (holidaysales/img) items to delete.

Leave a Reply

Your email address will not be published. Required fields are marked *