How to Automatically Move Blobs to Cool or Archive Tier After a Period of Time
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.
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.
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".
In the next step. I set a rule for blobs that are created more then 30 days, move them to cool storage.
In the last step, add blob prefix of "attachments".
This is for targeting only a specific container, which in my case is the "attachments" container.
You can create similar rules for archive tier. Make sure all your rules are Enabled.
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK