如何设置生命周期策略以删除Google云存储桶中的所有版本,除了最新的3个版本

发布于 2025-01-27 14:00:33 字数 963 浏览 6 评论 0 原文

因此,我已经在 Google Cloud Storage上上传到ZIP文件的多个微服务代码,例如 livewinpkgs,uatwinpkgs,devwinpkgs 等。与CustomerService,LoginService,CheckoutService

一样结构类似于

livewinpkgs ----> customerService ----> customerService.1.0.1.zip,customerservice.1.0.2.2.2.zip等,该版本列出了一长串版本。

现在,我的要求是我需要设置一个策略,除了最后2或3个版本,我将从每个服务文件夹中删除所有版本。我知道可以通过对象版本来实现这些事情。当我们的文件名相同时,它可以完美无缺,并且仅使用新版本覆盖当前版本。但是在我的情况下,该名称不断更改每个版本,例如1.0.1、1.0.2、1.0.3附加了服务名称。

另一个选项是使用年龄选项设置删除生命周期,但是对于某些服务,我们在多个月内不会进行任何更改,因此,如果我设置了删除比90天大的文件的策略,那么我有可能会失去当前的实时版本。

仅分享一个参考图像以更好地理解。如上图所示,这就是我的文件在存储夹文件夹中的外观,除了最后一个(版本4.txt),它具有多个版本。现在,我想继续说只说2个版本,以便理想地删除版本。1.0.1.zipand version.1.0.2.2.zip在维护版本。1.0.3.3.zip时,

应该是这样的最好的方法我想保留最后版本并在此之前删除所有内容的情况。最后2或3个版本可以通过创建的日期知道,但对于不同的服务会有所不同。

So I've multiple microservices code uploaded on Google Cloud Storage as zip files in different buckets like livewinpkgs, uatwinpkgs, devwinpkgs, etc. Inside these buckets, there are various microservices folder like customerservice, loginservice, checkoutservice, etc.

And in the services folders, we have been maintaining the names as customerservice.1.0.1.zip, customerservice.1.0.2.zip, etc.

So the tree structure is something like this

livewinpkgs--->customerservice--->customerservice.1.0.1.zip,customerservice.1.0.2.zip, etc which goes on for a long list of versions.

Now, my requirement is that I need to setup a policy wherein I'll delete all the versions from each of the services folders except for the last 2 or 3 versions. I know such things can be achieved via object versioning. It works flawlessly when our file name is same and it just overwriting current versions with new version. But in my case, the name keeps on changing for every version like 1.0.1, 1.0.2, 1.0.3 with the service name appended to it.

Another option was to setup the delete lifecycle using Age option but for some services we don't do any changes for many months so if I setup a policy to delete the files which are older than 90 days then there are chances that I may loose the current live version also.

enter image description here

Just sharing a reference image for better understanding. As seen in the above image, this is how my files looks like in the bucket folder except for the last one(version4.txt) which has multiple versions of it. Now, I want to keep let's say only 2 versions so the policy should ideally delete version.1.0.1.zip and version.1.0.2.zip while maintaining the version.1.0.3.zip

What should be the best approach in such cases where I want to keep the last versions and delete anything before that. The last 2 or 3 versions can be known via the created date but it will be different for different services.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2025-02-03 14:00:33

好吧,您可以用来编写生命周期规则的条件相对有限:

因此,如果您对每个修订版都使用其他对象名称,则仅使用LifeCycle规则清理似乎是不可能的。

如果要切换到版本管理的纯GCS对象版本操作,但是要做的是:

"rule": [
    {
        "action": {
            "type": "Delete"
        },
        "condition": {
            "numNewerVersions": 2
        }
    }
]

}

如果您确实需要每次使用不同的对象名称,那么对我来说,最简单的解决方案似乎使具有逻辑的小脚本来确定最新的脚本根据对象名称列表(和/或其修改日期)的2个文件的2个版本,然后删除最古老的版本。将此脚本添加为云功能,提供正确的服务帐户权限,以便它可以列出并在存储桶中删除,然后每x小时/天用云调度程序作业触发此脚本。

另外,您可以使用在对象上触发的云功能创建通知,并检查新创建的对象的旧版本的数量,并在需要时清理它们。

Well the conditions you can use to write lifecycle rules are relatively limited in what you can do: https://cloud.google.com/storage/docs/lifecycle#conditions

So if you use a different object name for every revision, cleaning up with just lifecycle rules seems impossible to me.

If you were to switch to purely GCS object versioning for version management it is however trivial to do:

"rule": [
    {
        "action": {
            "type": "Delete"
        },
        "condition": {
            "numNewerVersions": 2
        }
    }
]

}

If you do need to use different object names each time, the easiest solution to me seems to make a small script with logic to determine the latest 2 versions of a file based on the list of object names (and/or their modification dates) and which then deletes the oldest versions. Add this script as a cloud function, give the correct service account rights so it can list and delete in the bucket and then trigger this script with a cloud scheduler job every x hours/days.

Alternatively you could use a cloud function which is triggered on object create notifications and checks the number of older versions of the newly created object and cleans them up if needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文