Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 19 of 47
❮Prev Next❯

Blob Soft Delete and Versioning

Module 2: Storage ⏱ 10 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    Blob soft delete keeps deleted blobs (and their versions and snapshots) for 1 to 365 days so you can undelete them. Container soft delete does the same for whole containers (1 to 365 days) and restores them with their blobs. Blob versioning automatically keeps the previous version of a blob every time it's overwritten or deleted, so you recover from a bad edit by copying an older version back over the current one. Turn them on in Data management > Data protection. Microsoft recommends using them together; none of them protects against deleting the storage account (use a resource lock).

    Simulate it » No Azure account needed

    Exam objective: 2.3.4 Configure soft delete for blobs and containers. 2.3.7 Configure blob versioning. (Skills measured as of April 17, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Turn on blob soft delete and versioning, then recover data Turn on soft delete and versioning, then undelete and restore a version.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Under <strong>Data management</strong> open <strong>Data protection</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Under Data management open Data protection.
    2. Turn on soft delete for blobs (14 days), for containers (7 days) and versioning. Each takes 1 to 365 days. Select Save.
    3. Someone deleted contract-88.docx. In the container, toggle Show deleted blobs.
    4. Select it and choose Undelete. With versioning on, you would instead promote its previous version.
    5. A bad edit overwrote contract-12.docx. Open the blob, go to Versions, pick the version from three days ago and Make current version.
    6. Containers deleted by mistake come back from Containers → Show deleted containers → Undelete. Soft delete doesn’t protect against deleting the whole account: use a delete lock for that.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    A contract was deleted on Monday and another overwritten on Tuesday.

    😊 THE SOLUTION

    Turn on soft delete and versioning so both are a two-minute fix.

    • Deleted blob✓ Undelete
    • Overwritten blob✓ Restore a version
    • Deleted container✓ Container soft delete
    🛠️ Solved with: Blob soft delete + versioning

    Start with a question

    Why does your phone's photo app keep deleted photos for 30 days?

    Because people delete the wrong photo all the time. The “Recently deleted” album gives you a month to change your mind. And your document editor keeps a version history, so a bad edit isn’t the end of the world either.

    Azure Blob Storage has both. Soft delete is the recently deleted album. Versioning is the version history.

    Explain it like I’m 10

    The technical explanation

    All three settings live in Data management > Data protection on the storage account (and on the Data protection tab when you create one). The portal turns soft delete on by default for new accounts (7 days); accounts created with the CLI or templates don’t get it unless you ask.

    Blob soft delete

    When a blob, a snapshot or a version is deleted, it’s kept in a soft-deleted state for the retention period (1 to 365 days). You can list it (--include d, or Show deleted blobs in the portal) and undelete it. When versioning is off, overwriting a blob also keeps the old data as a soft-deleted snapshot. Soft-deleted data is billed until it’s purged.

    Container soft delete

    Deleted containers and everything in them are kept for 1 to 365 days. Restore from Containers > Show deleted containers > Undelete, or with az storage container restore. You can’t restore over a container that has since been recreated with the same name.

    Blob versioning

    With versioning on, every write creates a new current version and keeps the old one as a previous version with a timestamp version ID. Deleting a blob turns its current version into a previous version. To recover, copy a previous version over the base blob (portal: blob > Versions > Make current version). Versions are billed, so pair versioning with a lifecycle rule that deletes old versions. Versioning isn’t supported on hierarchical namespace accounts.

    How they fit together

    AccidentWith soft delete onlyWith versioning (and soft delete)
    Blob deletedUndelete itMake a previous version current
    Blob overwrittenRestore the soft-deleted snapshotMake a previous version current
    Version deletedUndelete the versionUndelete the version
    Container deletedNeeds container soft deleteNeeds container soft delete
    Account deletedNot covered (use a lock)Not covered (use a lock)

    Point-in-time restore builds on these: it restores block blobs in chosen containers to a moment in the past, and needs versioning, the change feed and blob soft delete, with a restore window shorter than the soft delete retention. Object replication also needs versioning.

    CLI and PowerShell

    az storage account blob-service-properties update -g rg-storage-prod -n stcontosoprod \
      --enable-delete-retention true --delete-retention-days 14 \
      --enable-container-delete-retention true --container-delete-retention-days 7 \
      --enable-versioning true
    
    # Deleted blob (soft delete): list and undelete
    az storage blob list --account-name stcontosoprod -c contracts --include d -o table
    az storage blob undelete --account-name stcontosoprod -c contracts -n contract-88.docx
    
    # Overwritten blob (versioning): copy a previous version back
    az storage blob list --account-name stcontosoprod -c contracts --include v -o table
    az storage blob copy start --account-name stcontosoprod \
      --destination-container contracts --destination-blob contract-12.docx \
      --source-uri "https://stcontosoprod.blob.core.windows.net/contracts/contract-12.docx?versionid=<version-id>"
    Enable-AzStorageBlobDeleteRetentionPolicy -ResourceGroupName rg-storage-prod -StorageAccountName stcontosoprod -RetentionDays 14
    Enable-AzStorageContainerDeleteRetentionPolicy -ResourceGroupName rg-storage-prod -StorageAccountName stcontosoprod -RetentionDays 7
    Update-AzStorageBlobServiceProperty -ResourceGroupName rg-storage-prod -StorageAccountName stcontosoprod -IsVersioningEnabled $true
    Architect level Immutability is a different tool

    Soft delete and versioning help with mistakes, but an admin can still turn them off and purge data. If regulations say data must not be changed or deleted for a period, use immutable storage: time-based retention policies or legal holds on a container or on versions. Locked policies can’t be shortened, even by the account owner.

    Real-world business scenario

    Hospitality

    Alpine Ski House (fictional)

    The problem
    A sync tool deleted a season's booking contracts on Monday, and on Tuesday an intern saved a blank template over the master price list.
    What they used
    Blob soft delete (14 days), container soft delete (7 days) and versioning, with a lifecycle rule that deletes versions older than 90 days.
    Why that choice
    Undelete brought back the contracts, and the previous version of the price list was made current again in two clicks.
    The result
    Both incidents were fixed before lunch. The team later added a delete lock on the account for the one accident these features don't cover.

    When to use it and when not to

    ✓ Use it when…

    • Any account holding data people or tools can delete or overwrite.
    • You plan to use object replication or point-in-time restore (versioning required).
    • You want a quick undo without restoring from a backup.

    ✕ Think twice when…

    • Data that must be legally unchangeable (use immutable storage).
    • Hierarchical namespace accounts if you need versioning (not supported).
    • Blobs rewritten constantly with no lifecycle rule for versions (cost grows).

    ↔ Alternatives to consider

    • Immutable storage for WORM compliance.
    • Azure Backup for blobs for vaulted, longer-term copies.
    • Resource locks to stop the account itself being deleted.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    Users occasionally delete blobs by mistake. You must be able to recover deleted blobs for 14 days. What should you enable?

    Question 2

    Question 2 of 5

    A document blob is overwritten with incorrect content. You must be able to restore the previous content automatically for future overwrites without taking manual copies. What should you enable?

    Question 3

    Question 3 of 5

    A container named reports was deleted. Container soft delete is enabled. Which Azure CLI command restores the container?

    Question 4

    Question 4 of 5 · Select 3

    You need to configure point-in-time restore for block blobs in a storage account. Which three features must be enabled? Each correct answer presents part of the solution.

    Question 5

    Question 5 of 5

    Blob soft delete and container soft delete are enabled on a storage account. You must also prevent an administrator from accidentally deleting the storage account itself. What should you configure?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What's the difference between soft delete and versioning?

    Model answer

    Soft delete is about deletes: a deleted blob waits for a set number of days before it's really gone, and you can undelete it. Versioning is about changes: every time a blob is overwritten, the old content is kept as a version. Together they cover both "I deleted it" and "I saved over it".

    Intermediate Versioning is on and someone deletes a blob. How do you get it back?

    Model answer

    With versioning, a delete turns the current version into a previous version; there's no current blob left. I list versions with --include v, find the one I want and copy it back over the blob name with az storage blob copy start using the version ID in the source URL, or in the portal pick the version and select Make current version.

    Experienced developer What does versioning cost, and how do you keep it under control?

    Model answer

    Each version is billed for the data it holds, so a blob that's rewritten hourly can pile up versions fast. I add a lifecycle rule that deletes versions older than, say, 90 days, or moves them to a cooler tier. Versioning also isn't supported on accounts with a hierarchical namespace.

    Scenario A container with a year of reports was deleted this morning. Container soft delete was on with 7 days. What do you do?

    Model answer

    List containers with --include-deleted to get its deleted version, then az storage container restore with the name and version, or Show deleted containers and Undelete in the portal. It comes back with its blobs. If a container with the same name was created since, I'd have to remove or rename that first.

    Quick revision

    Key points

    • Portal path: storage account > Data management > Data protection.
    • Blob soft delete and container soft delete - 1 to 365 days each.
    • Portal-created accounts get 7-day soft delete by default; the CLI doesn't turn it on.
    • Versioning keeps a version on every write; restore by copying a version back.
    • Object replication and point-in-time restore need versioning.
    • None of these protect against deleting the storage account; use a CanNotDelete lock.

    Important terminology

    Blob soft delete
    Keeps deleted blobs, snapshots and versions for a retention period of 1 to 365 days.
    Container soft delete
    Keeps deleted containers and their contents for 1 to 365 days so they can be restored.
    Blob versioning
    Automatically keeps a previous version of a blob each time it's modified or deleted.
    Version ID
    A timestamp that identifies one version of a blob.
    Undelete
    Restoring a soft-deleted blob (az storage blob undelete) within the retention period.
    Point-in-time restore
    Restores block blobs in containers to an earlier state; needs versioning, change feed and blob soft delete.

    Common mistakes

    • Expecting undelete to work when soft delete was off at the time of the delete.
    • Using undelete for a blob deleted while versioning was on (promote a version instead).
    • Forgetting that versions are billed.

    Exam tips

    • "Recover a blob that was overwritten" = versioning.
    • "Recover a deleted container" = container soft delete.
    • "Prevent deletion of the storage account" = resource lock, not soft delete.

    Five quick revision questions

    1. 1.What retention range does blob soft delete allow?Show

      1 to 365 days.

    2. 2.Which CLI command restores a soft-deleted blob?Show

      az storage blob undelete

    3. 3.Which CLI flag turns on blob versioning?Show

      --enable-versioning true (az storage account blob-service-properties update)

    4. 4.Which three features does point-in-time restore need?Show

      Versioning, change feed and blob soft delete.

    5. 5.Does container soft delete protect against deleting the storage account?Show

      No.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Read and Modify ARM Templates and Bicep Files

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.