Background:-
There would be scenarios where Customers would require container level capacity in a specific storage account. Below are multiple ways using which we can achieve this
Calculate the size of a Blob storage container – via Blob Inventory
We can make use of the Blob Inventory report and Azure Synapse Workspace to generate container-level stats. This approach would be advisable if there is versioning or snapshots enabled on the Storage Account. Currently, the Blob Inventory report does not include soft deleted blobs (if Soft delete is enabled) to calculate the capacity. For this approach, we need to first enable the Blob Inventory report on the storage account and the next step would be to generate Container capacity using Azure Synapse Workspace.
The Azure Storage blob inventory feature provides an overview of your containers, blobs, snapshots, and blob versions within a storage account. Use the inventory report to understand various attributes of blobs and containers such as your total data size, age, encryption status, immutability policy, legal hold, and so on. The report provides an overview of your data for business and compliance requirements.
Step 1: - Enable Inventory Report
The Add a rule page appears.
If you select Blob, then under Blob subtype, choose the types of blobs that you want to include in your report, and whether to include blob versions and/or snapshots in your inventory report.
8. Select the fields that you would like to include in your report and the format of your reports. Please make sure to include Content-Length from the fields.
9. Choose how often you want to generate reports.
10. Optionally, add a prefix match to filter blobs in your inventory report.
11. Select Save.
Inventory output
Each inventory rule generates a set of files in the specified inventory destination container for that rule. The inventory output is generated under the following path: https://<accountName>.blob.core.windows.net/<inventory-destination-container>/YYYY/MM/DD/HH-MM-SS/<r... where:
Step 2:- Azure Synapse Workspace
Create an Azure Synapse workspace where you will execute a SQL query to report the inventory results.
Create the SQL query
After you create your Azure Synapse workspace, do the following steps.
Run the SQL query
For the bulk parameter, use the URL of the inventory report CSV file that you want to analyze.
SQLCopy
SELECT LEFT([Name], CHARINDEX('/', [Name]) - 1) AS Container, COUNT(*) As TotalBlobCount, SUM([Content-Length]) As TotalBlobSizeFROM OPENROWSET( bulk '<URL to your inventory CSV file>', format='csv', parser_version='2.0', header_row=true) AS SourceGROUP BY LEFT([Name], CHARINDEX('/', [Name]) - 1)
Calculate the size of a Blob storage container – via PowerShell
This script calculates the size of a container in Azure Blob storage by totaling the size of the blobs in the container.
For more details, please visit here: https://docs.microsoft.com/en-us/azure/storage/scripts/storage-blobs-container-calculate-size-powers...
The script that calculates container size for billing purposes, see Calculate the size of a Blob storage container for billing purposes
For calculating the Container capacity with Soft delete and versioning enabled kindly refer to the below script:-
Script is to calculate the capacity of a directory:-
Calculate the size of a Blob storage container – via Storage explorer
The easiest way to calculate the size of the Blob Container is using Storage Explorer. Using the below steps, you would be able to calculate the Container level capacity. Please note that this would not give accurate capacity if Soft Delete and Versioning Enabled.
Hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.