Enable soft delete for blobs

Blob soft delete protects an individual blob and its versions, snapshots, and metadata from accidental deletes or overwrites by maintaining the deleted data in the system for a specified period of time. During the retention period, you can restore the blob to its state at deletion. After the retention period has expired, the blob is permanently deleted. For more information about blob soft delete, see Soft delete for blobs.

Blob soft delete is part of a comprehensive data protection strategy for blob data. To learn more about Azure's recommendations for data protection, see Data protection overview.

Enable blob soft delete

You can enable or disable soft delete for a storage account at any time by using the Azure portal, PowerShell, or Azure CLI.

Blob soft delete is not enabled when you create a new storage account with Azure CLI. You can enable blob soft delete after the new account has been created.

To enable blob soft delete for an existing storage account with Azure CLI, call the az storage account blob-service-properties update command, specifying the retention period in days.

The following example enables blob soft delete and sets the retention period to seven days. Remember to replace the placeholder values in brackets with your own values:

az storage account blob-service-properties update --account-name <storage-account> \
    --resource-group <resource-group> \
    --enable-delete-retention true \
    --delete-retention-days 7

To check the current settings for blob soft delete, call the az storage account blob-service-properties show command:

az storage account blob-service-properties show --account-name <storage-account> \
    --resource-group <resource-group>

Enable blob soft delete (hierarchical namespace)

Blob soft delete can also protect blobs and directories in accounts that have the hierarchical namespace feature enabled on them.

  1. If you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.

  2. Install the storage-preview extension.

    az extension add -n storage-preview
    
  3. Connect to your storage account. For more information, see Connect to the account.

    Note

    The example presented in this article show Microsoft Entra authorization. To learn more about authorization methods, see Authorize access to blob or queue data with Azure CLI.

  4. To enable soft delete with Azure CLI, call the az storage fs service-properties update command, specifying the retention period in days.

    The following example enables blob and directory soft delete and sets the retention period to 5 days.

    az storage fs service-properties update --delete-retention --delete-retention-period 5 --auth-mode login
    
  5. To check the current settings for blob soft delete, call the az storage fs service-properties update command:

    az storage fs service-properties update --delete-retention false --connection-string $con
    

Next steps