Skip to main content

Managing Storage Lifecycle in Azure



Requirements

The Nautilus DevOps team needs to optimize data retention costs by automating the deletion of old blobs. They plan to implement Blob Lifecycle Management for a specific container in Azure Storage.

Task

  1. Create a Storage Account:
  • Name the storage account devopsstor14097.
  • Set the region to East US.
  • Use Locally-redundant storage (LRS) as the redundancy option.
  1. Create a Blob Container:
  • Name the container devops-container14097.
  1. Upload a File to the Container:
  • Upload the file named tempfile.txt to the container. The file is present under /root of the client host.
  1. Configure Blob Lifecycle Management:
  • Apply a Lifecycle Management rule named devops-del-rule to the container devops-container14097 to delete blobs after 7 days of last modification.
  1. Validation:
  • Verify that the Lifecycle Management rule named devops-del-rule is correctly applied.

Note

This lab uses Azure CLI to create storage resources and apply a lifecycle policy in a single, reproducible flow.

Prerequisites

  • Azure CLI installed and logged in (az login).
  • Access to the target subscription and resource group.
  • File /root/tempfile.txt present on the client host.

Steps

RG=$(az group list --query "[?contains(name, 'kml')].name" --output tsv)
STORAGE_ACCOUNT="devopsstor14097"
CONTAINER_NAME="devops-container14097"
LOCATION="eastus"
RULE_NAME="devops-del-rule"
FILE_PATH="/root/tempfile.txt"

az storage account create \
--name "$STORAGE_ACCOUNT" \
--resource-group "$RG" \
--location "$LOCATION" \
--sku Standard_LRS \
--kind StorageV2

az storage container create \
--name "$CONTAINER_NAME" \
--account-name "$STORAGE_ACCOUNT" \
--auth-mode login

az storage blob upload \
--account-name "$STORAGE_ACCOUNT" \
--container-name "$CONTAINER_NAME" \
--name tempfile.txt \
--file "$FILE_PATH" \
--auth-mode login

cat > lifecycle.json <<EOF
{
"rules": [
{
"enabled": true,
"name": "${RULE_NAME}",
"type": "Lifecycle",
"definition": {
"actions": {
"baseBlob": {
"delete": {
"daysAfterModificationGreaterThan": 7
}
}
},
"filters": {
"blobTypes": ["blockBlob"],
"prefixMatch": ["${CONTAINER_NAME}/"]
}
}
}
]
}
EOF

az storage account management-policy create \
--account-name "$STORAGE_ACCOUNT" \
--resource-group "$RG" \
--policy @lifecycle.json

Verification

  • Confirm container exists:
    • az storage container show --name "$CONTAINER_NAME" --account-name "$STORAGE_ACCOUNT" --auth-mode login --query name -o tsv
  • Confirm blob upload:
    • az storage blob show --account-name "$STORAGE_ACCOUNT" --container-name "$CONTAINER_NAME" --name tempfile.txt --auth-mode login --query name -o tsv
  • Confirm lifecycle rule:
    • az storage account management-policy show --account-name "$STORAGE_ACCOUNT" --resource-group "$RG" --query "policy.rules[0].name" -o tsv

Resources