How to work with Soft Delete in Azure? — Top Tech Notes
Let discuss about another feature of azure blob storage which is the soft delete.
Soft delete for azure blob storage
Soft delete for blob objects helps to recover data when it is erroneously modified or deleted by an application or other storage account user. When turned on, soft delete enables us to save and recover data when blobs or blob snapshots are deleted. This protection extends to blob data that is erased as result of overwrite.
When data is deleted, it transitions to a soft deleted state instead of being permanently erased. When soft delete is on and we overwrite data, a soft deleted snapshot is generated to save the state of the overwritten data.
Soft deleted objects are invisible unless explicitly listed. We can configure the amount of time soft deleted data is recoverable before it is permanently expired. When we create a new account, soft delete is off by default. Soft delete is also off by default for existing storage accounts. We can change the feature on and off at any time during the life of a storage account. We will still be able to access and recover soft deleted data when the feature is turned off assuming that soft deleted data was saved when the feature was previously turned on.
When you turn on soft delete, you also need to configure the retention period. The retention period indicates the amount of time that soft deleted data is stored and available for recovery.
For blobs and blob snapshots that are explicitly deleted, the retention period clock starts when the data is deleted. For soft deleted snapshots generated by the soft delete feature when data is overwritten, the clock starts when the snapshot is generated. Currently you can retain soft deleted data for between 1 and 365 days. You can change the soft delete retention period at any time. An updated retention period will only apply to newly deleted data. Previously deleted data will expire based on the retention period that was configured when that data was deleted. Attempting to delete a soft deleted object will not affect its expiry time.
Now let’s take a demo on how soft delete works in azure blob storage.
How soft delete works?
I am logged into azure portal with my global administrator account and I have opened the storage account blade. Now let’s open any storage account where you want to set soft delete. I will open storageacntpa properties blade once again like we did in our last post.
Now let’s go to the blob service page for this account.
In this blob service page there is a container.
And if I go inside this container there is a file in this container which we uploaded in previous post.
Though this file is empty but for a moment let us consider that this is a very important file for us. And if anyone deletes this file by mistake or for any other reason then we would want to be sure that we will be able to recover this file. At this point there is no snapshot or any other backup created for this file and so if anyone will delete it then we cannot recover this file. So let’s configure soft delete here so that we can recover this file whenever required. Let’s close this blade.
Now on the left hand menu bar for this storage account scroll down and within blobs service section you will find a tab soft delete.
Click on it. And a soft delete blade appears on the right hand side.
Here you can see that soft delete is in disabled state. So all we need to do is enable this. Let’s go ahead and select enable. Once you click on enable it gives us an option to set retention policy to keep the blob that has been marked as deleted. We can scroll this bar and set the retention period up to 365 days. For the purpose of demo I will just set the retention period as 1 day. Now save this change.
Immediately a notification pops up which says successfully updated soft delete settings.
So we have now updated the blob service to enable soft delete for all blobs. So what happens now is that when any blob is deleted then it won’t be visible in the portal or any API’s. But it can be recovered till the retention period is valid. It works like recycle bin for your blob. But once the retention period expires the blob gets hard deleted and then it can’t be recovered.
Now let’s go back into the container and let’s go ahead and delete this blob. To delete the blob you can just select the blob and click on delete button at the top or we can go to context menu and select delete at the bottom. So let’s delete this.
Once you click on delete a box appears for confirmation.
Here click on ok to confirm deletion. And it gives me a message that the blob deletion failed. Notice here it says this operation is not permitted because this blob has snapshot.
So this blob actually do have a snapshot which we created earlier. So let’s go ahead and delete the snapshot first. Now to delete the snapshot go to the blob file properties blade. We can go to the blob file properties blade by going to the context menu and there selecting properties or we can just click on the blob file and its properties blade will open. Here go to the snapshot tab. And again go to the context menu for the snapshot and then select delete snapshot.
Click on yes to confirm.
Our snapshot is deleted now.
Now let’s go back and try to delete the blob again.
Click on ok. And the blob is deleted now. You can see there is no blob in this container. But notice here, there is a check box which allows us to show deleted blobs.
So if we select this check box it shows me the blob that I have deleted.
You can see that the blob exists and its status is set to deleted. This is because we have set soft delete retention period as 1 day. So this blob will remain here for 1 day and we can recover it anytime in the next 24 hours. And after 24 hours it will be hard deleted and it cannot be recovered then.
To recover this blob, again go to the context menu on the right hand side and from the dropdown select undelete.
And a notification pops up which shows successfully undeleted blob. And you can also see the status of blob file has changed from delete state to active now.
This active status is being shown here because the show deleted check box is still selected. Let’s uncheck this.
And the blob has now been brought back. It’s like restoring files and folders from recycle bin on your computer.
So this is how we work with soft delete in azure. Next we will discuss how to host static website in azure storage.
If you like this post, then do not forget to subscribe so that you can receive timely update whenever we publish any new post.
Originally published at https://toptechnotes.com on February 3, 2022.