OnCallReadyStart learning

Azure Lesson 32.29 · Azure IV: Governance, Storage & Backup · 19 min read

Protecting blob data: soft delete, versioning, lifecycle and object replication

In plain words

Imagine a filing cabinet with three safety features. A recycle bin (soft delete): thrown-away files wait there for two weeks before they are really gone. Photocopies of every old version (versioning): if someone scribbles over a page, the previous page is still kept. And a cleaner who comes every night (lifecycle rules) and moves old papers to the basement or shreds them after a year - but only from the drawers you told them about.

You can also have a second cabinet in another city that gets a copy of every new page (object replication).

Protecting blob data: soft delete, versioning, lifecycle and object replication

Redundancy protects against hardware. It does not protect against the most common data loss: a person or a script that deletes or overwrites the wrong thing. All six copies of a GZRS account delete the blob together. This lesson is the toolkit for that: soft delete for blobs and containers, versioning for overwrites, lifecycle management for keeping costs down without manual work, and object replication for an asynchronous copy of selected containers in another account. Each one has a failure mode, and you will meet them in the incidents.

Need to know:

FeatureProtects againstKept forRestore with
Blob soft deletea deleted blob (or snapshot)1-365 daysaz storage blob undelete
Container soft deletea deleted container1-365 daysaz storage container restore
Versioningoverwrite and delete: every write keeps the previous versionuntil a lifecycle rule deletes itcopy a version over the current blob
Point-in-time restorea bad batch job across many blobs (needs versioning, soft delete and change feed)its windowrestore block blobs to a moment
Change feed(an audit trail) every create, update, delete, in orderconfigurableread it, feed replication

Soft delete and versioning are blob service properties. Turn them on for every account holding data someone would miss. Advisor reminds you if you don't.

$ az group create -n rg-try-data -l westeurope -o none
$ az storage account create -n sttrydata06 -g rg-try-data -o none
$ az role assignment create --assignee [email protected] --role "Storage Blob Data Contributor" --scope $(az storage account show -n sttrydata06 -g rg-try-data --query id -o tsv) -o none
$ export AZURE_STORAGE_AUTH_MODE=login
$ az storage account blob-service-properties update -n sttrydata06 -g rg-try-data --enable-delete-retention true --delete-retention-days 14 --enable-container-delete-retention true --container-delete-retention-days 14 --query "{blobs:deleteRetentionPolicy.days, containers:containerDeleteRetentionPolicy.days}"
{
  "blobs": 14,
  "containers": 14
}

Soft delete

$ az storage container create --account-name sttrydata06 -n configs -o none
$ echo "timeout=30" > app.conf
$ az storage blob upload --account-name sttrydata06 -c configs -n app.conf -f app.conf -o none 2>/dev/null
$ az storage blob delete --account-name sttrydata06 -c configs -n app.conf
$ az storage blob list --account-name sttrydata06 -c configs --query "[].name" -o tsv
$ az storage blob list --account-name sttrydata06 -c configs --include d --query "[].{name:name, deleted:deleted, daysLeft:properties.remainingRetentionDays}" -o table
Name      Deleted  DaysLeft
--------  -------  --------
app.conf  True     14
$ az storage blob undelete --account-name sttrydata06 -c configs -n app.conf
$ az storage blob list --account-name sttrydata06 -c configs --query "[].name" -o tsv
app.conf

A soft-deleted blob is invisible to normal listing (and to the application): --include d shows it. The whole container works the same way:

$ az storage container delete --account-name sttrydata06 -n configs -o none
$ az storage container list --account-name sttrydata06 --include-deleted --query "[].{name:name, deleted:deleted, version:version}" -o table
Name     Deleted  Version
-------  -------  ---------------------
configs  True     01D639257040055500000
$ V=$(az storage container list --account-name sttrydata06 --include-deleted --query "[?deleted].version" -o tsv)
$ az storage container restore --account-name sttrydata06 -n configs --deleted-version $V -o none
$ az storage blob list --account-name sttrydata06 -c configs --query "[].name" -o tsv
app.conf

Soft delete does not protect against an overwrite: uploading a new app.conf replaces the content, and without versioning the old content is gone.

Versioning

$ az storage account blob-service-properties update -n sttrydata06 -g rg-try-data --enable-versioning true --query isVersioningEnabled
true
$ echo "timeout=5" > app.conf
$ az storage blob upload --account-name sttrydata06 -c configs -n app.conf -f app.conf --overwrite -o none 2>/dev/null
$ az storage blob list --account-name sttrydata06 -c configs --include v --query "[].{name:name, version:versionId, current:isCurrentVersion}" -o table
Name      Version                       Current
--------  ----------------------------  -------
app.conf  2026-09-22T20:00:06.2500000Z  True
app.conf  2026-09-22T20:00:04.0000000Z  False

Every write creates a new version. The current one is the blob, the old ones have a versionId. Restoring is a copy of the old version over the current blob:

$ OLD=$(az storage blob list --account-name sttrydata06 -c configs --include v --query "[?isCurrentVersion!=\`true\`] | [0].versionId" -o tsv)
$ az storage blob copy start --account-name sttrydata06 --destination-container configs --destination-blob app.conf --source-uri "https://sttrydata06.blob.core.windows.net/configs/app.conf?versionid=$OLD" --query status -o tsv
success
$ az storage blob download --account-name sttrydata06 -c configs -n app.conf -f restored.conf -o none 2>/dev/null; cat restored.conf
timeout=30

With versioning on, a delete is different too: the current blob becomes a previous version, and undelete has nothing to restore. You copy the version back, exactly as above.

Versions and snapshots cost storage like any data. A file overwritten every minute grows a version per minute. Lifecycle rules delete old versions after N days.

Snapshots are the older, manual way: a read-only copy of a blob at a moment (az storage blob snapshot), kept until you delete it. With versioning on, you rarely need them for blobs. Azure Files uses share snapshots (next lesson).

Lifecycle management

A management policy is a JSON set of rules the service runs about once a day: move blobs to Cool, Cold or Archive, or delete them, based on days since modification, creation or last access, for blobs matching a prefix (container/path/) or blob index tags. Separate actions for current blobs, previous versions and snapshots.

$ cat ~/oncall-lab/labs/azure4/try/lifecycle.json
{
  "rules": [
    {
      "enabled": true,
      "name": "logsCoolThenDelete",
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "logs/app/"
          ]
        },
        "actions": {
          "baseBlob": {
            "tierToCool": {
              "daysAfterModificationGreaterThan": 30
            },
            "delete": {
              "daysAfterModificationGreaterThan": 365
            }
          }
        }
      }
    },
    {
      "enabled": true,
      "name": "oldConfigVersions",
      "type": "Lifecycle",
      "definition": {
        "filters": {
          "blobTypes": [
            "blockBlob"
          ],
          "prefixMatch": [
            "configs/"
          ]
        },
        "actions": {
          "version": {
            "delete": {
              "daysAfterCreationGreaterThan": 90
            }
          }
        }
      }
    }
  ]
}
$ az storage account management-policy create --account-name sttrydata06 -g rg-try-data --policy @/home/learner/oncall-lab/labs/azure4/try/lifecycle.json --query "policy.rules[].{name:name, prefixes:definition.filters.prefixMatch}"
[
  {
    "name": "logsCoolThenDelete",
    "prefixes": [
      "logs/app/"
    ]
  },
  {
    "name": "oldConfigVersions",
    "prefixes": [
      "configs/"
    ]
  }
]
  • Rule names are letters and digits only (no hyphens). prefixMatch is container/prefix. No filter means every blob in the account. That is how the config file in the next incident ended up in Archive.
  • Rules run on the service's schedule, not when you save the policy: the first run can take up to 24 hours, and a big account takes longer to go through.
  • Moving to Cool/Cold/Archive early or deleting before the tier's minimum period has a charge. Archive makes blobs unreadable until rehydrated, so never archive anything an application reads.

Object replication

Object replication copies block blobs asynchronously from a source container to a destination container in another account (any region, even another tenant if allowed). Use cases: keep a copy near readers in another region, keep a copy in an account the source team can't delete, separate dev reads from prod.

Prerequisites: versioning on both accounts, change feed on the source. The policy is created on the destination first, then on the source with the destination's policy id. Only blobs written after the policy exists are copied (unless you choose to copy existing ones). Replication is async, usually within minutes, with no SLA, and the destination container becomes read-only for writes.

$ az storage account create -n sttrydata07 -g rg-try-data -l northeurope -o none
$ az storage account blob-service-properties update -n sttrydata07 -g rg-try-data --enable-versioning true -o none
$ az storage account blob-service-properties update -n sttrydata06 -g rg-try-data --enable-change-feed true -o none
$ az storage container create --account-name sttrydata07 -n configs-replica --auth-mode key -o none 2>/dev/null
$ PID=$(az storage account or-policy create --account-name sttrydata07 -g rg-try-data --source-account sttrydata06 --destination-account sttrydata07 --source-container configs --destination-container configs-replica --query policyId -o tsv)
$ az storage account or-policy create --account-name sttrydata06 -g rg-try-data --source-account sttrydata06 --destination-account sttrydata07 --source-container configs --destination-container configs-replica --policy-id $PID --query "rules[0].{from:sourceContainer, to:destinationContainer}"
{
  "from": "configs",
  "to": "configs-replica"
}

Object replication is not a backup: a delete on the source isn't replicated, but an overwrite is. Bad data travels too. For "we deleted the wrong thing", soft delete and versioning are the tools, and for a copy nobody in the source account can touch, Azure Backup's blob vaulted backup (later in this chapter).

On the exam (AZ-104 2.2.3, 2.3.4, 2.3.6, 2.3.7): blob and container soft delete (retention 1-365 days, undelete/restore), versioning (every write, restore by copying a version), lifecycle rules (prefix filters, base blob / version / snapshot actions, daily run), object replication prerequisites (versioning both sides, change feed on the source, destination policy first, new blobs only by default).

In an interview: "Someone overwrote an important blob. Can you get it back?" - "Only if versioning was on: the old content is a previous version, and I copy that version back over the blob. Soft delete alone covers deletes, not overwrites. That's why accounts with important data get versioning, blob and container soft delete, and a lifecycle rule that deletes old versions after a while so they don't grow forever."

What you can now do

  • Turn on blob and container soft delete and versioning, and restore from each.
  • Write a lifecycle rule with the right prefix, and know when it runs.
  • Set up object replication in the right order, and say what it does not protect against.

Why it helps

Most data loss is not hardware: it is a script or a person deleting or overwriting the wrong thing. These features are cheap, quick to turn on and decisive on the day something is deleted - but only if they were on before.

Lifecycle rules save real money on logs and backups and, scoped badly, archive live data. Both outcomes appear in this chapter's labs.

Commands in this lesson

az export echo cat

FAQ

Is soft delete enough to undo an overwrite?

No. Soft delete keeps deleted blobs; an overwrite replaces the content without deleting anything. Versioning keeps the previous content as a version, and you restore it by copying that version back over the blob. Turn on both.

Why doesn't undelete work with versioning on?

With versioning, deleting a blob turns the current version into a previous version; there is no soft-deleted blob to undelete. Copy the version you want back to the blob name. Soft delete then protects the versions themselves from being deleted for good.

When does a new lifecycle rule run?

The service runs lifecycle policies about once a day; the first run after you create or change a policy can take up to 24 hours, and large accounts take longer to process. Rules are not applied when you save them.

Does object replication copy existing blobs?

By default only blobs written after the policy exists are replicated (you can choose to copy existing ones when creating it). It needs versioning on both accounts and change feed on the source, and the destination policy is created first.

Aren't versions expensive?

Each version is billed like data, and a frequently overwritten blob collects many. Add a lifecycle rule that deletes previous versions after a number of days, for example 30 or 90. Pick the number from how far back you realistically need to recover.

In an interview Mid

Someone overwrote an important blob. Can you get it back?

Only if versioning was on: the old content is a previous version, and I copy that version back over the blob with az storage blob copy start and the ?versionid= URL. Soft delete alone covers deletes, not overwrites. That is why accounts with important data get versioning plus blob and container soft delete, and a lifecycle rule that deletes old versions after a while so they don't grow forever.

Also asked: What is the difference between blob soft delete and container soft delete? · How would you move logs older than 30 days to a cheaper tier automatically? · What is object replication and what are its prerequisites?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.