Search code examples
azureazure-storageazure-blob-storageazure-cli

Is there a way to filter by tier in azure blob storage


I would like to list all the files stored in a particular tier. This is what I tried:

az storage fs file list \
  --file-system 'cold-backup' \
  --query "[?contains(properties.blobTier, 'Cold')==\`true\`].properties.blobTier"

But it doesn't work. I also tried with "blobTier" only. No luck.

This is the error I get:

Invalid jmespath query supplied for '--query': In function contains(), invalid type for value: None, expected one of: ['array', 'string'], received: "null"


Solution

  • The command az storage fs file list is for ADLS Gen2 file system, there is no blobTier property in the output, so you could not query with it, also the blobTier should be Cool instead of Cold.

    If you want to list the files filter with blobTier, you could use az storage blob list, it applies to blob storage, but it can also be used for ADLS Gen2 file system.

    Sample:

    az storage blob list --account-name '<storage-account-name>' --account-key 'xxxxxx' --container-name 'cold-backup' --query "[?properties.blobTier=='Cool']"
    

    enter image description here

    If you want to output the blobTier, use --query "[?properties.blobTier=='Cool'].properties.blobTier" instead in the command.