问题
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