当前位置: 动力学知识库 > 问答 > 编程问答 >

Remove Azure blob storage contents that are untouch for period of time

问题描述:

The application I developed basically allows users to upload contents and get stored in Azure Blob Storage.

Since the nature of the contents are for quick sharing between users, many of the contents are quickly become untouched after a period of time. But for some contents can be used over and over again.

In order to stop the unprecedented growth of the size of blob storage, I am planning to write tool that basically find any blobs that aren't used for period of time and delete them off the storage.

If it was standard file system, I can use "Last Access Time" to indicate when the last time file being used. However, I can't seem to find similar property of the blob to determine Last Access Time.

So does anyone ever come across this situation, what would be the best way to achieve this?

Or am I too concerned about this?

Any feedback or suggestion are greatly appreciated.

Thank you in advanced.

网友答案:

I can only see two ways of handling this:

  1. Front the access to the blob such that they must hit a service to get the blob URL with SAS signature. This way you can count and monitor which blobs are getting accessed. Remove older blobs that have low/no access after some time. This requires turning off public access so people cannot just go around your SAS signature.
  2. Turn on storage analytics and monitor the GET requests. You would have to parse all the GET accesses for a month for example ($logs are updated hourly) and group by resource. If you automated this, it would not be too terrible. This would give you a list of all the resources that had been accessed.
网友答案:

If you are using Blob storage then following the approach that Gaurav suggested is your best option. See here for a doc on getting started:

https://azure.microsoft.com/en-us/documentation/articles/storage-analytics/.

Note that our .NET client libraries do include support for parsing log files - you can see a demo of this in our client library unit tests:

https://github.com/Azure/azure-storage-net/search?utf8=%E2%9C%93&q=ListLogs

网友答案:

You can use block and page blob Properties.LastModifiedUtc to get the last modified date. With Page or Block blob, you would need to use GetBlockBlobReference or GetPageBlobReference API along with FetchAttributes() to get the blob reference and then you can look for LastModifiedUtc.

For example with Block blob here is the code snippet:

CloudBlockBlob blockBlob = container_name.GetBlockBlobReference(uri.ToString());
blockBlob.FetchAttributes();
// blockBlob.Properties.LastModifiedUtc will return the last modified date for the blob.
分享给朋友:
您可能感兴趣的文章:
随机阅读: