Nexus Repository Manager-删除旧的二进制资源

时间:2019-02-14 12:25:21

标签: java nexus artifacts nexus3 resource-cleanup

我想知道是否有一种方法可以从nexus存储库中删除许多项目。我有一些for f in $(find /work/pr-${DOMINIO}-0[0-2]/servers -name "*.log*[^gz]" -type f -user bea -mtime +${GGZIP}) ; do /usr/bin/gzip -9 -f $f ; mv $f.gz $f.gz.$DATAORA_ATTUALI; done 类型的存储库,其中包含一些Web应用程序版本(简单的tar.bz2  二进制文件):

enter image description here

在某些存储库中,有很多。我想释放一些磁盘空间。我可以删除单个文件:

enter image description here

但是我看不到批量删除选项。

对我来说最好的解决方案是自动或手动清理旧文件。有可能是免费版本吗?如果是,怎么办?

主菜单中没有看到RAW

enter image description here

Cleanup Policies

2 个答案:

答案 0 :(得分:3)

使用Nexus3 OSS完全可以实现:

1。创建清理政策
在“存储库->清理策略”下,您可以添加一个策略,该策略将从存储库中删除工件:

  • 在X天前发布
  • X天前最新下载

2。将此政策添加到您的存储库
编辑您的存储库。在“清理策略”下,选择新策略。

由于仅清理存储库soft-delete(需要将其标记为删除),所以您需要:

3。压缩您的Blob存储区
转到“系统->任务->创建任务”,选择“管理员-紧凑型Blob存储”任务,选择存储库的Blob存储,并将此任务配置为在清理任务之后运行。

所有这些都在nexus documentation中进行了详细说明。

我已经测试了Nexus 3.15.2-01 OSS版的步骤。

答案 1 :(得分:0)

我找到了解决问题的方法。

我的管理控制台中没有Cleanup Policy部分(I think this option is available only for professional or nevest versions)-感谢@Sebastian的建议,您直接将我引向了解决方案。

基于以下问题:Purge old release from Nexus 3

我创建了一些手动任务来清理我的二进制存储库:

enter image description here

我的清理任务非常简单,但是任何需要更复杂内容的人都可以编写自己的Groovy脚本或寻找现成的解决方案。

import org.sonatype.nexus.repository.storage.Component
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet

def removeFromDate = '2019-02-01'

log.info("delete components for repository: HereYourRepoName")
def compInfo = { Component c -> "${c.group()}:${c.name()}:${c.version()}[${c.lastUpdated()}]}" }
def repo = repository.repositoryManager.get("HereYourRepoName")
StorageFacet storageFacet = repo.facet(StorageFacet)

def tx = storageFacet.txSupplier().get()
tx.begin()
Iterable<Component> components = tx.findComponents(Query.builder().where('last_updated < ').param(removeFromDate).build(), [repo])
tx.commit()
tx.close()

log.info("about to delete " + components.flatten(compInfo))
for(Component c : components) {
    log.info("deleting " + compInfo(c))
    tx2 = storageFacet.txSupplier().get()
    tx2.begin()
    tx2.deleteComponent(c)
    tx2.commit()
    tx2.close()
}

log.info("finished deleting " + components.flatten(compInfo))

日志查看器对于调试脚本非常有用:)