Skip to content

Blob lifecycle

Lab Objective

In this hands-on lab, you will learn how to:

  • Configure blob lifecycle management policies to automatically manage data aging
  • Set up access tier transitions (Hot β†’ Cool β†’ Archive) based on data age
  • Implement automated blob deletion for expired content
  • Create conditional rules using blob filters and prefixes
  • Monitor lifecycle policy execution and cost optimization
  • Test different lifecycle scenarios for various data types
  • Troubleshoot lifecycle policy issues and optimize configurations

Scenario: Your organization stores various types of data with different access patterns and retention requirements. You need to implement automatic lifecycle management to optimize storage costs while ensuring compliance with data retention policies.


Pre-Provisioned Environment

The following Azure resources have been pre-deployed in your environment:

Resource Overview

Resource TypeResource NameConfigurationPurpose
Resource GroupBlobLifecycle-Lab-RGContains all lab resourcesLogical container
Storage Accountlifecyclestore[unique]GPv2, Hot tier, LRSPrimary lifecycle testing
Storage Accountarchivestore[unique]GPv2, Cool tier, GRSArchive scenario testing
Test VMLifecycleVMWindows Server 2019Data upload and monitoring
Blob ContainersVariousDifferent access levelsOrganized test data

Storage Account Configuration

AccountDefault TierRedundancyPurpose
lifecyclestore[unique]HotLRSActive data lifecycle testing
archivestore[unique]CoolGRSLong-term archive scenarios

Container Structure

Primary Storage (lifecyclestore[unique])
β”œβ”€β”€ documents/ (Private access)
β”‚ β”œβ”€β”€ current/ (Active documents)
β”‚ β”œβ”€β”€ archived/ (Old documents)
β”‚ └── temp/ (Temporary files)
β”œβ”€β”€ logs/ (Private access)
β”‚ β”œβ”€β”€ application/ (App logs)
β”‚ β”œβ”€β”€ system/ (System logs)
β”‚ └── audit/ (Audit logs)
β”œβ”€β”€ media/ (Private access)
β”‚ β”œβ”€β”€ images/ (Image files)
β”‚ └── videos/ (Video content)
└── backups/ (Private access)
β”œβ”€β”€ daily/ (Daily backups)
β”œβ”€β”€ weekly/ (Weekly backups)
└── monthly/ (Monthly backups)
Archive Storage (archivestore[unique])
β”œβ”€β”€ compliance-archive/ (Long-term compliance data)
└── cold-storage/ (Rarely accessed data)

Data Types and Expected Lifecycle

Data TypeInitial TierCool TransitionArchive TransitionDeletion
Active DocumentsHot30 days90 days7 years
Application LogsHot7 days30 days1 year
System LogsHot1 day7 days90 days
Media FilesHot60 days180 daysNever
Daily BackupsCoolImmediate30 days90 days
Compliance DataCool30 days90 days10 years

Lab Exercises

Part 1: Understand Current Storage Costs

Step 1: Examine Storage Account Tiers

  1. Navigate to BlobLifecycle-Lab-RG resource group
  2. Click on lifecyclestore[unique] storage account
  3. Go to Storage browser β†’ Blob containers

Review existing containers:

  • documents: Contains various document types
  • logs: Application and system log files
  • media: Image and video files
  • backups: Daily, weekly, monthly backups

Step 2: Check Current Access Tiers

  1. Open each container and examine some blobs
  2. Click on a blob β†’ Properties
  3. Note the Access tier:
    • Most should show β€œHot” (default)
    • Check blob size and last modified date
    • Calculate approximate storage costs

Step 3: Understand Tier Pricing

Review pricing implications:

Access TierStorage CostAccess CostRetrieval CostUse Case
HotHighestLowestNoneFrequently accessed
CoolMediumMediumLowInfrequently accessed (30+ days)
ArchiveLowestHighestHighRarely accessed (180+ days)

Example cost savings:

  • 1TB Hot storage: ~$18/month
  • 1TB Cool storage: ~$10/month (44% savings)
  • 1TB Archive storage: ~$2/month (89% savings)

Part 2: Create Basic Lifecycle Policy

Step 1: Access Lifecycle Management

  1. In lifecyclestore[unique] storage account
  2. Go to Data management β†’ Lifecycle management
  3. Click β€œAdd a rule”

Step 2: Create First Rule - Application Logs

Configure rule basics:

  • Rule name: ApplicationLogLifecycle
  • Rule scope: Limit blobs with filters
  • Blob type: Block blobs
  • Blob subtype: Base blobs

Set filters:

  • Prefix match: logs/application/
  • Blob index match: (Leave empty for now)

Step 3: Configure Actions for Application Logs

Set up tier transitions:

If base blobs were:

  • Created more than 7 days ago: Move to cool storage
  • Created more than 30 days ago: Move to archive storage
  • Created more than 365 days ago: Delete the blob

Click β€œAdd rule” to save

Step 4: Create Second Rule - System Logs

Create another rule:

  • Rule name: SystemLogLifecycle
  • Blob scope: Limit blobs with filters
  • Prefix match: logs/system/

Configure actions:

  • Created more than 1 day ago: Move to cool storage
  • Created more than 7 days ago: Move to archive storage
  • Created more than 90 days ago: Delete the blob

Step 5: Create Third Rule - Documents

Create document lifecycle rule:

  • Rule name: DocumentLifecycle
  • Prefix match: documents/

Configure actions:

  • Created more than 30 days ago: Move to cool storage
  • Created more than 90 days ago: Move to archive storage
  • Created more than 2555 days ago (7 years): Delete the blob

Part 3: Advanced Lifecycle Rules

Step 1: Create Media Files Rule with Conditions

  1. Add new rule: MediaLifecycle
  2. Prefix match: media/

Configure conditional actions:

  • Created more than 60 days ago: Move to cool storage
  • Created more than 180 days ago: Move to archive storage
  • Never delete (media has long-term value)

Step 2: Create Backup Retention Rule

  1. Add new rule: BackupLifecycle
  2. Prefix match: backups/daily/

Configure aggressive cleanup:

  • Created more than 0 days ago: Move to cool storage (immediate)
  • Created more than 30 days ago: Move to archive storage
  • Created more than 90 days ago: Delete the blob

Step 3: Create Size-Based Rule

  1. Add new rule: LargeFileLifecycle
  2. No prefix filter (applies to all containers)
  3. Blob index match: Add condition for large files

Configure by size (if supported):

  • Target blobs larger than 100MB
  • Created more than 14 days ago: Move to cool storage
  • Created more than 45 days ago: Move to archive storage

Part 4: Test Lifecycle Policies

Step 1: Upload Test Data with Dates

  1. Connect to LifecycleVM:

    • Username: azureuser
    • Password: LabPassword123!
  2. Create test files with different ages:

    • Open PowerShell as Administrator
    • Create files and set their creation dates
Terminal window
# Create test directories locally
$testPath = "C:\LifecycleTest"
New-Item -ItemType Directory -Path $testPath -Force
# Create application log files with different ages
$logPath = "$testPath\logs\application"
New-Item -ItemType Directory -Path $logPath -Force
# Current log (0 days old)
"Current application log - $(Get-Date)" | Out-File "$logPath\current.log"
# Old log (10 days old)
"Old application log - $(Get-Date)" | Out-File "$logPath\old.log"
(Get-Item "$logPath\old.log").CreationTime = (Get-Date).AddDays(-10)
(Get-Item "$logPath\old.log").LastWriteTime = (Get-Date).AddDays(-10)
# Ancient log (40 days old)
"Ancient application log - $(Get-Date)" | Out-File "$logPath\ancient.log"
(Get-Item "$logPath\ancient.log").CreationTime = (Get-Date).AddDays(-40)
(Get-Item "$logPath\ancient.log").LastWriteTime = (Get-Date).AddDays(-40)

Step 2: Upload Test Files to Storage

  1. In Azure portal, go to Storage browser
  2. Navigate to logs/application/ container
  3. Upload the test files created above
  4. Verify upload and note their creation times

Step 3: Force Policy Execution (Simulation)

Note: Lifecycle policies run once per day. For testing:

  1. Check policy status:

    • Go to Lifecycle management
    • Review your rules and ensure they’re enabled
    • Note: β€œLast run” shows when policies last executed
  2. Simulate policy effects:

    • Manually change access tiers to simulate policy execution
    • Go to blob β†’ Change access tier
    • Test transitions: Hot β†’ Cool β†’ Archive

Step 4: Monitor Tier Changes

  1. Wait 24-48 hours for actual policy execution
  2. Check blob access tiers:
    • Navigate to each test blob
    • Verify tier changes match your policy rules
    • Document any unexpected behavior

Part 5: Monitor Costs and Policy Performance

Step 1: Set Up Cost Monitoring

  1. Go to Cost Management + Billing
  2. Create cost alert:
    • Scope: BlobLifecycle-Lab-RG
    • Alert condition: When cost exceeds $10
    • Action group: Email notification

Step 2: Analyze Storage Metrics

  1. In lifecyclestore[unique], go to Insights
  2. Review metrics:
    • Capacity trends by access tier
    • Transaction patterns
    • Data retrieval costs

Step 3: Create Lifecycle Dashboard

Track key metrics:

MetricBefore LifecycleAfter LifecycleSavings
Hot storage (GB)[Record baseline][Monitor change][Calculate]
Cool storage (GB)[Record baseline][Monitor change][Calculate]
Archive storage (GB)[Record baseline][Monitor change][Calculate]
Monthly cost[Record baseline][Monitor change][Calculate]

Step 4: Review Policy Effectiveness

Create effectiveness report:

Rule NameObjects AffectedTier ChangesCost ImpactStatus
ApplicationLogLifecycle[Count][Transitions][Savings]βœ… Active
SystemLogLifecycle[Count][Transitions][Savings]βœ… Active
DocumentLifecycle[Count][Transitions][Savings]βœ… Active
MediaLifecycle[Count][Transitions][Savings]βœ… Active

Part 6: Troubleshoot and Optimize

Step 1: Common Issues and Solutions

Check for common problems:

  1. Policy not executing:

    • Verify: Policy is enabled
    • Check: Syntax errors in filters
    • Ensure: Sufficient permissions
  2. Unexpected tier changes:

    • Review: Filter conditions (prefixes)
    • Check: Date calculations
    • Verify: Blob metadata
  3. High retrieval costs:

    • Analyze: Access patterns
    • Adjust: Archive timing
    • Consider: Cool tier instead of archive

Step 2: Optimize Existing Rules

Review and adjust rules:

  1. Check rule efficiency:

    • Are transitions happening as expected?
    • Are there too many or too few objects affected?
    • Is timing appropriate for access patterns?
  2. Adjust based on usage:

    • Extend cool period if data accessed more than expected
    • Shorten archive period if retrieval costs are low
    • Add exceptions for critical data

Step 3: Create Exception Rules

Handle special cases:

  1. Important documents exception:

    • Rule name: ImportantDocumentsException
    • Prefix: documents/important/
    • Actions: Move to cool after 90 days only (no archive/delete)
  2. Audit logs exception:

    • Rule name: AuditLogsException
    • Prefix: logs/audit/
    • Actions: Move to archive after 2555 days (7 years), never delete

Troubleshooting Guide

Common Lifecycle Management Issues

IssueSymptomsPossible CauseSolution
Policy not runningNo tier changes after 24+ hoursPolicy disabled or syntax errorCheck policy status and JSON syntax
Wrong blobs affectedUnexpected objects changing tiersOverly broad filtersRefine prefix filters and conditions
High retrieval costsUnexpected archive access chargesData accessed too frequentlyAdjust archive timing or use cool tier
Compliance violationsData deleted prematurelyIncorrect deletion rulesReview and extend retention periods
Performance issuesSlow access to archived dataData in archive tierPlan ahead for archive retrieval times

Policy Configuration Checklist

ComponentRequirementStatusNotes
Rule enabledMust be activeβœ…Check policy status
Correct filtersPrefix matches intended dataβœ…Test with sample data
Appropriate timingMatches business requirementsβœ…Verify with stakeholders
Deletion safeguardsLong retention for critical dataβœ…Review retention policies
Cost optimizationBalance access needs vs. costβœ…Monitor cost metrics

Best Practices

ScenarioRecommendationBenefit
Log filesHot β†’ Cool (1-7 days), Archive (7-30 days)Fast troubleshooting, cost effective
DocumentsHot β†’ Cool (30 days), Archive (90+ days)Balance accessibility and cost
BackupsCool immediately, Archive (30 days)Maximum cost savings
Media filesHot β†’ Cool (60+ days), rarely archivePreserve access quality
Compliance dataCool β†’ Archive quickly, long retentionMeet regulations cost-effectively

Optional Advanced Exercises

For users wanting more technical depth, try these exercises:

Advanced Exercise 1: Automated Policy Creation

Terminal window
# Connect to Azure
Connect-AzAccount
# Create lifecycle policy via PowerShell
$resourceGroup = "BlobLifecycle-Lab-RG"
$storageAccount = "lifecyclestore[unique]"
# Define policy JSON
$policyJson = @"
{
"rules": [
{
"enabled": true,
"name": "PowerShellCreatedRule",
"type": "Lifecycle",
"definition": {
"filters": {
"blobTypes": ["blockBlob"],
"prefixMatch": ["test/"]
},
"actions": {
"baseBlob": {
"tierToCool": {"daysAfterModificationGreaterThan": 7},
"tierToArchive": {"daysAfterModificationGreaterThan": 30},
"delete": {"daysAfterModificationGreaterThan": 365}
}
}
}
}
]
}
"@
# Apply policy
$policy = $policyJson | ConvertFrom-Json
Set-AzStorageAccountManagementPolicy -ResourceGroupName $resourceGroup -StorageAccountName $storageAccount -Policy $policy

Advanced Exercise 2: Policy Impact Analysis

Terminal window
# Analyze potential cost savings
$storageAccount = Get-AzStorageAccount -ResourceGroupName "BlobLifecycle-Lab-RG" -Name "lifecyclestore[unique]"
$ctx = $storageAccount.Context
# Get blob statistics by container
Get-AzStorageContainer -Context $ctx | ForEach-Object {
$containerName = $_.Name
$blobs = Get-AzStorageBlob -Container $containerName -Context $ctx
$stats = $blobs | Group-Object {$_.AccessTier} | ForEach-Object {
@{
Container = $containerName
Tier = $_.Name
Count = $_.Count
TotalSize = ($_.Group | Measure-Object Length -Sum).Sum
}
}
Write-Host "Container: $containerName"
$stats | Format-Table
}

Advanced Exercise 3: Custom Monitoring Dashboard

Terminal window
# Create custom lifecycle monitoring report
function Get-LifecycleReport {
$storageAccount = Get-AzStorageAccount -ResourceGroupName "BlobLifecycle-Lab-RG" -Name "lifecyclestore[unique]"
# Get management policy
$policy = Get-AzStorageAccountManagementPolicy -ResourceGroupName "BlobLifecycle-Lab-RG" -StorageAccountName "lifecyclestore[unique]"
Write-Host "=== LIFECYCLE MANAGEMENT REPORT ==="
Write-Host "Generated: $(Get-Date)"
Write-Host "Storage Account: $($storageAccount.StorageAccountName)"
Write-Host ""
if ($policy) {
Write-Host "Active Rules: $($policy.Policy.Rules.Count)"
$policy.Policy.Rules | ForEach-Object {
Write-Host " - $($_.Name): $($_.Enabled)"
}
} else {
Write-Host "No lifecycle policies configured"
}
}
Get-LifecycleReport

Key Takeaways

After completing this lab, you should understand:

  • Lifecycle management policies automatically optimize storage costs by moving data through access tiers
  • Rule-based automation reduces manual intervention and ensures consistent data management
  • Filter conditions (prefixes, blob types) allow granular control over which data is affected
  • Tier transitions should align with actual data access patterns to avoid unexpected costs
  • Archive tier provides maximum cost savings but has retrieval delays and costs
  • Deletion rules require careful consideration of business and compliance requirements
  • Policy monitoring is essential to ensure rules work as expected and optimize costs

Lifecycle Decision Matrix

Choosing the Right Lifecycle Strategy

Data TypeAccess PatternRecommended StrategyJustification
Application logsHigh initially, rare after 30 daysHot β†’ Cool (7d) β†’ Archive (30d) β†’ Delete (1y)Debugging needs vs. storage cost
User documentsVariable, decreasing over timeHot β†’ Cool (30d) β†’ Archive (90d) β†’ Keep long-termBusiness value retention
System backupsRare access, compliance drivenCool immediately β†’ Archive (30d) β†’ Delete (90d)Cost optimization priority
Media contentModerate access, long-term valueHot β†’ Cool (60d) β†’ Archive (180d) β†’ Never deleteQuality preservation
Compliance dataRare access, legal requirementsCool β†’ Archive (30d) β†’ Delete after legal minimumRegulatory compliance

Cost Optimization Guidelines

ScenarioOptimization StrategyExpected Savings
Log managementAggressive archiving after 30 days70-80% storage cost reduction
Document managementBalanced approach with 90-day cool transition40-50% storage cost reduction
Backup optimizationImmediate cool tier, fast archive80-90% storage cost reduction
Media optimizationConservative transitions, no deletion30-40% storage cost reduction

Additional Resources