Is it possible to List Azure Blobs Where Last Modified Date > Some Date

旧城冷巷雨未停 提交于 2020-12-31 06:50:34

问题


Is it possible to List all blobs on a container where Last Modified Date is greater than a specified date.

I have a container with millions of blobs and want to copy those blobs to a backup container, however don't want to loop through all blobs checking each for Last Modified Date.


回答1:


It is possible to do using Powershell. Please see below snippet.

$StorageAccountName = "AccountName" 
$StorageAccountKey = "What_ever_your_key_is_123asdf5524523A=="
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$ContainerName = "Container"

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt (Get-Date).Date}

Above command will get the blobs for current day from midnight.

You can then use the functions on Get-Date cmdlet to further narrow down the timeframe as below.

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt ((Get-Date).Date).AddDays(-1)}

You can also sort this by piping to Sort-Object cmdlet as below to sort on any property (I sorted on date in below example).

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt (Get-Date).Date.AddDays(-1)} `
| Sort-Object -Property Date



回答2:


Is it possible to List all blobs on a container where Last Modified Date is greater than a specified date.

As of today it is not possible to do so. Blob service does not provide querying capabilities. When you list the blobs, Blob service will return you a list sorted by blob's name.

Not now, but going forward if you need this capability you may want to organize blobs by dates by prefixing their names with year, month and date. Then you can ask blob service to return you blobs names of which start with a particular prefix. If you use Azure App Service, do take a look at how diagnostics data for an Azure App Service is stored in a blob container. It does prefixing by year, month and date.




回答3:


If you look into the REST API documentation there is not parameter which does filtering for date/time. So the only way to do this is either listing all blobs and afterwards filter by your criteria (which is also done by Mustafa Salmans answer), or organize blobs by date as Gaurav Mantri already wrote.



来源:https://stackoverflow.com/questions/44777851/is-it-possible-to-list-azure-blobs-where-last-modified-date-some-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!