3

How to Automatically Move Blobs to Cool or Archive Tier After a Period of Time

 1 year ago
source link: https://edi.wang/post/2023/2/13/how-to-automatically-move-blobs-to-cool-or-archive-tier-after-a-period-of-time
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Automatically Move Blobs to Cool or Archive Tier After a Period of Time

Original

Edi Wang

2/13/2023, 11:48:51 PM

9 Reads


Problem


Azure Storage Account offers three tiers of blob storage. Hot, cool and archive. We usually use hot tier for data that needs to be accessed frequently, move blobs to cool tier if they won't be used very often, and archive blobs when they are not used at all. This is a good practice to reduce costs when using Azure.

In my case, I am building a system that stores attachments to Azure Storage Account. These attachments will only be frequently accessed within a month. So hot tier is only when attachments are uploaded, after 30 days, they are moved to cool tier, and after 365 days, they will be archived.

However, manually, or programmatically moving blobs still require an amount of work to do, which can make you work 996. Let's see how to do it without any programming.

Solution


It's a built-in feature in Azure Storage Account. Go to Lifecycle management blade of your Storage Account in Azure portal. 

img-8ee72db8-876e-497f-b584-04d2ef0fd26b.png

Click "+ Add a rule". Enter a name, for example "move attachments to cool tier". In my case I am targeting blobs that are only in the "attachments" container. So, I will select "Limit blobs with filters".

img-e0a9a268-2933-45cf-b74e-f676f2deb96f.png

In the next step. I set a rule for blobs that are created more then 30 days, move them to cool storage.

img-ed410c3d-6d7b-4c2e-92e8-17b043b659b8.png

In the last step, add blob prefix of "attachments". 

img-ba0ebc92-67c0-45d8-b652-2430a91cd536.png

This is for targeting only a specific container, which in my case is the "attachments" container.

img-5ac9dfc3-ffbf-4acd-992f-05044956bc71.png

You can create similar rules for archive tier. Make sure all your rules are Enabled.

img-69d388de-032e-4de2-ac51-3d74c00d2555.png

However, when the rule is created, it won't be executed immediately, just wait for a day, then you will find your blobs being correctly moved to cool or archive tier.

All rules can also be created in code, refer to: https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-overview

{
  "enabled": true,
  "name": "move attachments to cool tier",
  "type": "Lifecycle",
  "definition": {
    "actions": {
      "baseBlob": {
        "tierToCool": {
          "daysAfterCreationGreaterThan": 30
        }
      }
    },
    "filters": {
      "blobTypes": [
        "blockBlob"
      ],
      "prefixMatch": [
        "attachments"
      ]
    }
  }
}

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK