简体   繁体   English

使用Python获取Azure Blob存储中的容器大小

[英]Get container sizes in Azure Blob Storage using Python

I am trying to use block_blob_service library in Python in order to get the sizes of all containers in an Azure blob storage. 我试图在Python中使用block_blob_service库,以获取Azure blob存储中所有容器的大小。 The following works, but takes too long (around 10 minutes for 50TB blob). 可以执行以下操作,但是花费的时间太长(50TB blob大约需要10分钟)。

Is there a quicker way? 有没有更快的方法?

block_blob_service = BlockBlobService(account_name=azureAccount, account_key=azurekey)
containers = block_blob_service.list_containers()
for c in containers:
        contName = c.name
        generator = block_blob_service.list_blobs(contName)
        contSize = 0
        contNum = 0
        for blob in generator: 
            contSize += blob.properties.content_length
            contNum += 1
        print(contName + " : " + str(contSize/1000000) + " MB" + " in " + str(contNum) + " blobs")

In addition to the SDK, you can use PowerShell script or a CLI script to get container size. 除了SDK,您还可以使用PowerShell脚本CLI脚本来获取容器大小。

Also , you can view the container size on the portal directly. 另外,您可以直接在门户上查看容器的大小。

在此处输入图片说明

I think the main issue of executing so long is that the storage blobs are too fragmented to increase the number of loops, compared to the capacity of the storage blobs. 我认为执行如此长时间的主要问题是,与存储blob的容量相比,存储blob过于分散,无法增加循环数。

So , I suggest you put the calculation in Azure Function to ease the pressure of your application. 因此,我建议您将计算结果放入Azure Function中,以减轻应用程序的压力。

Hope it helps you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 和 Azure 函数在 Azure 存储容器中创建 blob - How to create a blob in an Azure Storage Container using Python & Azure Functions 使用 Azure-Storage-Blob Python 读取 Blob 容器目录中每个 Blob 的文件大小 - Reading the File size for each blob inside a directory of a Blob Container using Azure-Storage-Blob Python 使用 python 条件删除 Azure blob 存储 - Conditional Delete Azure blob storage using python 使用 Python 的 azure httptrigger blob 存储 - azure httptrigger blob storage using Python 使用 python 将图像上传到 azure blob 存储 - Upload image to azure blob storage using python 使用 python 将文件上传到 azure blob 存储 - Uploading file to azure blob storage using python 如何使用 Python 从给定 SAS URI 和容器名称的 Azure Blob 存储下载文件列表? - How to download a list of files from Azure Blob Storage given SAS URI and container name using Python? 如何使用 python sdk 将 blob 上传到带有子目录的 azure 存储容器中? - How to upload a blob into azure storage container with sub directories using the python sdk? Azure:使用容器创建存储帐户并将 Blob 上传到 Python 中 - Azure: create storage account with container and upload blob to it in Python 在Python中的Azure Blob存储容器上应用SAS权限 - Apply SAS Permissions on Azure Blob Storage Container in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM