简体   繁体   English

如何检查 Azure blob 是否存在于多个容器的存储帐户中的任何位置?

[英]How to check if Azure blob exists anywhere in storage account in multiple containers?

I have an Azure Storage account and in it are multiple Containers.我有一个 Azure 存储帐户,其中有多个容器。 How can I check all of the Containers to see if a specific named blob is in any of them?如何检查所有容器以查看其中是否有特定命名的 blob? Also the blobs have multiple directories. blob 也有多个目录。
I know there's the az storage blob exists command, but that requires a Container name parameter.我知道有az storage blob exists命令,但这需要容器名称参数。 Will I have to use the List Containers command first?我必须先使用 List Containers 命令吗?

Yes, you need to get the containers list.是的,您需要获取容器列表。 I have reproduced in my environment and got expected results as below and I followed Microsoft-Document :我已经在我的环境中复制并获得如下预期结果,并且我遵循了Microsoft-Document

One of the way is Firstly, i have executed below code for getting containers list:其中一种方法是首先,我执行了以下代码来获取容器列表:

$storage_account_name="rithemo"
$key="T0M65s8BOi/v/ytQUN+AStFvA7KA=="
$containers=az storage container list --account-name $storage_account_name  --account-key $key 
$x=$containers | ConvertFrom-json
$x.name

在此处输入图像描述 $key = Key of Storage Account $key = 存储账户的密钥

Now getting every blob present in all containers in my Storage account:现在获取存储帐户中所有容器中的每个 blob:

$Target = @()
foreach($emo in $x.name )
 {
$y=az storage blob list -c $emo --account-name $storage_account_name  --account-key $key
$y=$y | ConvertFrom-json
$Target += $y.name
}  
$Target

在此处输入图像描述

Now checking if given blob exists or not as below:现在检查给定的 blob 是否存在,如下所示:

$s="Check blob name"
 if($Target -contains $s){
Write-Host("Blob Exists")
}else{
 Write-Host("Blob Not Exists")
 }
 

在此处输入图像描述

Or you can directly use az storage blob exists command as below after getting containers list:或者您可以在获取容器列表后直接使用az storage blob exists命令,如下所示:

foreach($emo in $x.name )
 {
az storage blob exists --account-key $key --account-name $storage_account_name --container-name mycontainer --name $emo --name "xx"
} 

在此处输入图像描述

Yes, you will need to use the List Containers command to get a list of all the containers in your storage account, and then you can loop through the list of containers and check each one for the specific blob that you are looking for.是的,您将需要使用 List Containers 命令获取存储帐户中所有容器的列表,然后您可以遍历容器列表并检查每个容器是否有您要查找的特定 blob。

Here's an example of how you can accomplish this using the Azure CLI下面是一个示例,说明如何使用 Azure CLI 完成此操作

# First, get a list of all the containers in your storage account
containers=$(az storage container list --account-name YOUR_STORAGE_ACCOUNT_NAME --output tsv --query '[].name')

# Loop through the list of containers
for container in $containers
do
    # Check if the specific blob exists in the current container
    az storage blob exists --account-name YOUR_STORAGE_ACCOUNT_NAME --container-name $container --name YOUR_BLOB_NAME
    # If the blob exists, print a message and break out of the loop
    if [ $? -eq 0 ]; then
        echo "Blob found in container: $container"
        break
    fi
done

暂无
暂无

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

相关问题 使用新的 Azure.Storage.Blobs 时如何计算存储帐户中 Blob 存储容器的总大小 - How to calculate the total size of Blob storage containers in an storage account when using the new Azure.Storage.Blobs 如何将多个 Blob 容器从一个存储帐户复制到另一个存储帐户(不同订阅) - How to copy multiple blob containers from one storage account to another storage account(different subscriptions) 用于容器的 Azure webapp,无法将 azure blob 存储帐户附加到容器 - Azure webapp for containers,cant attach azure blob storage account to container Umbraco7:在同一个Azure存储帐户中设置多个/ media / blob容器 - Umbraco7: Set up multiple /media/ blob containers within the same Azure Storage account 使用 Azure 函数检查 Blob 存储上是否存在文件 - Check if file exists on blob storage with Azure functions 需要将 Azure 存储帐户容器和 blob 访问级别更改为私有 - Need to change Azure Storage account containers and blob access levels to private 如何列出 azure blob 存储中的容器? - How to List the containers in azure blob storage? 如何使用Get-AzureStorageAccount检查Azure中是否存在存储帐户 - How to check storage account exists in Azure with Get-AzureStorageAccount 如何使用 Azure 数据工厂获取 blob 存储帐户中的容器计数? - How to get the count of containers in blob storage account using Azure Data Factory? Azure如何将高级Blob存储更改为标准Blob存储帐户? - Azure how to change premium blob storage to standard blob storage account?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM