Symptoms
- Spark, Synapse or ADF jobs fail with
PathNotFound,FilesystemNotFound/ContainerNotFound, orFileNotFoundExceptionfor a path that existed an hour ago. - Delta or Iceberg tables over the path fail. Unity Catalog or Hive external tables return "path does not exist".
- Storage Explorer or the portal shows the directory or container is missing.
On an account with hierarchical namespace, deleting a directory is a single atomic operation. With soft delete on, the directory and everything under it are kept as one soft-deleted item until the retention period ends. You can restore it in one call, as long as nothing has been written to the same path in the meantime.
Caution
The soft-delete retention clock started at the moment of deletion. Do not wait for a root-cause analysis before you restore. Also, don't let pipelines re-create the path: a new directory with the same name blocks a clean restore.
1. Stop writers to the path
Pause the ADF triggers, Databricks jobs and streams that write under the deleted path. Many jobs create their target directory on first write. If a job does that, you end up with a new, almost empty directory where the old one was.
# ADF: stop the trigger that feeds the path
az datafactory trigger stop --factory-name adf-prod --resource-group rg-data --name tr-hourly-orders
# Databricks: cancel active runs of the writer job
databricks jobs cancel-all-runs --job-id <job_id>
2. Confirm soft delete is on and what was deleted
ACCT=stlakeprod; RG=rg-data
az storage account blob-service-properties show --account-name $ACCT --resource-group $RG \
--query "{blobSoftDelete:deleteRetentionPolicy, containerSoftDelete:containerDeleteRetentionPolicy}"
| Result | Meaning |
|---|---|
blobSoftDelete.enabled: true | Deleted directories and files can be restored for days days |
containerSoftDelete.enabled: true | A deleted container can be restored |
Both false | There is nothing to undelete. Go to step 5 |
Find out who deleted the data and when, if StorageBlobLogs diagnostic logs go to Log Analytics:
StorageBlobLogs
| where TimeGenerated > ago(24h)
| where AccountName == "stlakeprod" and OperationName has "Delete"
| project TimeGenerated, OperationName, StatusCode, Uri, AuthenticationType, RequesterObjectId, CallerIpAddress
| order by TimeGenerated asc
Deleting a container through the control plane (portal, ARM, Terraform) also shows in the Activity log:
az monitor activity-log list --resource-group $RG --offset 24h \
--query "[?contains(operationName.value, 'containers/delete')].{time:eventTimestamp, caller:caller, op:operationName.value}" -o table
3. Restore a deleted directory
List soft-deleted paths under the parent directory. Each item has a deletionId, which you need for the restore:
FS=lake
az storage fs list-deleted-path --file-system $FS --path-prefix "silver/sales" \
--account-name $ACCT --auth-mode login \
--query "[].{name:name, deletionId:deletionId, deleted:deletedTime, daysLeft:remainingRetentionDays}" -o table
Restore the directory. Its children come back with it:
az storage fs undelete-path --file-system $FS \
--deleted-path-name "silver/sales/orders" --deletion-id "<deletionId>" \
--account-name $ACCT --auth-mode login
If the restore fails because the path already exists, a job re-created it. Rename the new directory out of the way, restore, then merge any rows the new directory holds that are worth keeping:
az storage fs directory move --file-system $FS --name "silver/sales/orders" \
--new-directory "$FS/silver/sales/orders_recreated_$(date +%Y%m%d%H%M)" \
--account-name $ACCT --auth-mode login
Warning
If the same directory was deleted more than once,
list-deleted-pathshows several entries with the same name. Pick thedeletionIdwhosedeletedTimematches the incident, not an older one.
Your identity needs a data-plane role that allows delete and restore, such as Storage Blob Data Contributor on the account or container. Principals that only have POSIX ACL entries can't see soft-deleted paths. Parameter names can differ on older CLI builds; check az storage fs undelete-path --help.
4. Restore a deleted container
az storage container list --account-name $ACCT --auth-mode login --include-deleted \
--query "[?deleted].{name:name, version:version, deletedTime:properties.deletedTime}" -o table
az storage container restore --account-name $ACCT --auth-mode login \
--name lake --deleted-version "<version>"
A container restore brings back the container with all its contents, ACLs included. You can't restore it while a new container with the same name exists. Copy out anything you need from the replacement, then delete it before you restore.
If the whole storage account was deleted, you may be able to recover it for a limited time from the Storage accounts page in the portal, as long as no new account with the same name exists. Check the current conditions before you promise anything.
5. No soft delete: rebuild
| Data | Recovery route |
|---|---|
| Bronze or raw landing zone | Re-ingest from the source system or the upstream file drop |
| Silver or gold Delta tables | Rebuild from bronze, or restore from a deep clone or a copy in another account |
| Unique data with no source | Open a Microsoft support case right away. Recovery isn't guaranteed |
6. Verify the tables
Delta tables reference files by relative path, so a restored directory is usually readable as soon as the restore finishes:
DESCRIBE HISTORY prod.silver.orders LIMIT 5;
SELECT COUNT(*) FROM prod.silver.orders;
SELECT COUNT(*) FROM prod.silver.orders VERSION AS OF <last_version_before_incident>;
- Refresh catalog metadata where needed (
REFRESH TABLE,MSCK REPAIR TABLEfor Hive-partitioned Parquet). - Restart streams. If a stream's checkpoint was under the deleted path, restore it too, or the stream starts over.
- Turn the triggers back on and check that the first runs write to the restored paths.
Prevent it next time
Turn on blob and container soft delete on every lake account, with a retention longer than the time it takes you to notice an incident:
az storage account blob-service-properties update --account-name $ACCT --resource-group $RG \
--enable-delete-retention true --delete-retention-days 14 \
--enable-container-delete-retention true --container-delete-retention-days 14
- Add a
CanNotDeletelock on the storage account:az lock create --name no-delete --lock-type CanNotDelete --resource-group $RG --resource-name $ACCT --resource-type Microsoft.Storage/storageAccounts. The lock protects the account, not data-plane deletes, so you still need the next points. - Take Storage Blob Data Owner and Contributor away from day-to-day human accounts. Cleanup jobs should use a dedicated identity scoped to the zone they clean.
- Make cleanup scripts refuse to run on paths shallower than a set depth, and add a dry-run mode that logs what would be deleted.
- Alert on bulk deletes: a
StorageBlobLogsquery onOperationName has "Delete"that fires above a threshold. See also recursive ACL overwrite recovery.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get