【问题标题】:Azure CLI - az storage blob delete-batch patternAzure CLI - az storage blob delete-batch 模式
【发布时间】:2020-02-21 14:14:53
【问题描述】:

我的存储帐户 storageaccount1 中有一个名为 container1 的容器,其中包含以下文件:

blobs/tt-aa-rr/data/0/2016/01/03/02/01/20.txt  
blobs/tt-aa-rr/data/0/2016/01/03/02/02/12.txt  
blobs/tt-aa-rr/data/0/2016/01/03/02/03/13.txt  

blobs/tt-aa-rr/data/0/2016/01/03/03/01/10.txt

我想删除前 3 个,为此我使用以下命令:

az storage blob delete-batch --source container1 --account-key XXX --account-name storageaccount1 --pattern 'blobs/tt-aa-rr/data/0/2016/01/03/02/*' --debug

文件没有被删除,我看到以下日志:

urllib3.connectionpool : Starting new HTTPS connection (1): storageaccount1.blob.core.windows.net:443
urllib3.connectionpool : https://storageaccount1.blob.core.windows.net:443 "GET /container1?restype=container&comp=list HTTP/1.1" 200 None

我的模式有什么问题?

如果我尝试逐个删除文件,它会起作用。

【问题讨论】:

  • 尝试在通配符 (*) 后添加 .txt,这样 'blobs/tt-aa-rr/data/0/2016/01/03/02/*.txt'
  • @HugoBarona 试过了,没用 :( 还有 'blob/tt-aa-rr/data/0/2016/01/03/02/*/*.txt
  • @mibrl12 是位于您容器下的子文件夹中的文件吗?如果是这种情况,模式将无法拾取这些。
  • @RoadRunner 是的,在子文件夹中。比它很伤心..
  • 哦,对不起,我以为它们在根文件夹中。是的,这是真的。子文件夹无法扫描,只能扫描一级文件夹。您可以在这里参考 - docs.microsoft.com/en-us/cli/azure/storage/…

标签: azure azure-blob-storage azure-cli azure-storage-account


【解决方案1】:

如 cmets 中所述,您无法将模式应用于子文件夹,只能应用于一级文件夹,如 here 所述。但是,如果您愿意,您可以轻松编写一个脚本来列出容器中的 blob,使用前缀 az storage blob list 过滤它们,然后对每个结果 blob 应用删除。

【讨论】:

  • 嗯,在明确说明子文件夹的文档中没有看到它。但是,这是有道理的 - 列表的天蓝色收费 :) thx!