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:
| Feature | Protects against | Kept for | Restore with |
|---|---|---|---|
| Blob soft delete | a deleted blob (or snapshot) | 1-365 days | az storage blob undelete |
| Container soft delete | a deleted container | 1-365 days | az storage container restore |
| Versioning | overwrite and delete: every write keeps the previous version | until a lifecycle rule deletes it | copy a version over the current blob |
| Point-in-time restore | a bad batch job across many blobs (needs versioning, soft delete and change feed) | its window | restore block blobs to a moment |
| Change feed | (an audit trail) every create, update, delete, in order | configurable | read 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).
prefixMatchiscontainer/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.