寻找用于快照构建(磁盘空间)的 Maven 存储库清理脚本(unix)

发布于 2024-10-30 23:42:33 字数 176 浏览 7 评论 0原文

所以我们有自己的私有 Maven 存储库,我们将快照版本发布到其中。

我们有很多构建,因此磁盘空间开始成为我们所有快照构建的问题。虽然这很有趣并且需要手动执行此操作,但我想知道是否有人知道我可以运行来执行快照清理的 CRON 脚本。

我知道 sonatype 为他们自己的存储库执行此操作,但我找不到脚本。

So we have our own private Maven repository that we publish snapshot builds to.

We have lots builds so diskspace is starting to become a problem for all our snapshot builds. While its fun and all to go manually do this I was wondering if anyone knows of a CRON script that I can run to do the snapshot cleanup.

I know sonatype does this for their own repo but I could not find a script.

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

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

发布评论

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

评论(2

Oo萌小芽oO 2024-11-06 23:42:33

要查找两周前更新的所有快照文件:

 find . -type f -mtime +14 | grep SNAPSHOT

将其通过管道传输到 xargs rm ,您应该就可以了。

需要注意的是:存储库管理器将创建一个 metadata.xml 文件,其中列出所有已发布的修订版本。假设您只是使用 scp 进行发布,并使用网络服务器进行检索,我认为该文件不存在(因此该脚本不接触它的事实不应该成为问题)。

To find all snapshot files that were updated more than two weeks ago:

 find . -type f -mtime +14 | grep SNAPSHOT

Pipe that to xargs rm and you should be good.

The one caveat: a repository manager will create a metadata.xml file that lists all published revisions. Assuming that you're just using scp to publish, and a webserver to retrieve, I don't think that file exists (so the fact that this script doesn't touch it shouldn't be an issue).

双手揣兜 2024-11-06 23:42:33

以下脚本对我来说效果很好:

#!/bin/sh
REPO=/var/www/maven2/snapshots
find $REPO -type d -name '*-SNAPSHOT' | while read project; do
    if [ -f $project/maven-metadata.xml ]; then # Make sure this is a maven artifact directory
            # Assume that snapshot numbering is designed to be sorted numerically
            latestversion=$(ls $project | grep -v 'maven-metadata.*' | sort -n | grep '\.pom
 | tail -n1)
            latestversion=$(basename $latestversion .pom)
            # Delete everything, but the latest version and the maven metadata
            find $project -type f | grep -v -e 'maven-metadata.*' -e "$latestversion.*" | xargs rm
    fi
done

The following script works fine for me:

#!/bin/sh
REPO=/var/www/maven2/snapshots
find $REPO -type d -name '*-SNAPSHOT' | while read project; do
    if [ -f $project/maven-metadata.xml ]; then # Make sure this is a maven artifact directory
            # Assume that snapshot numbering is designed to be sorted numerically
            latestversion=$(ls $project | grep -v 'maven-metadata.*' | sort -n | grep '\.pom
 | tail -n1)
            latestversion=$(basename $latestversion .pom)
            # Delete everything, but the latest version and the maven metadata
            find $project -type f | grep -v -e 'maven-metadata.*' -e "$latestversion.*" | xargs rm
    fi
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文