Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nexus Repository Manager - removing old binary resources

I wonder if there is a way to delete many items from nexus repository. I have some RAW type repositories with some web application releases(simple tar.bz2 binary files):

enter image description here

In some repositories are a lot of them. I want to free up some disk space. I can delete individual files:

enter image description here

but I don't see a bulk removal option.

The best solution for me would be to automatically or manually clean up old files. It's possible in free version? If yes - how?

I don't see Cleanup Policies in main menu:

enter image description here

Nexus Repository ManagerOSS 3.3.2-02

like image 208
Krzysztof Raciniewski Avatar asked Dec 05 '22 10:12

Krzysztof Raciniewski


2 Answers

This is perfectly possible with Nexus3 OSS:

1. Create a cleanup policy
Under "Repository -> Cleanup Policies" you can add a policy that deletes artifacts from a repository that:

  • Are published before X days
  • Last downloaded before X days

2. Add this policy to your repository
Edit your repository. Under "Cleanup Policy" select your new policy.

Since cleaned up repositories only soft-delete the artifacts (mark them for deleteion) you need to:

3. Compact your blob store
Go to "System -> Tasks -> Create Task", select the "Admin - Compact Blob Store" task, select the blob store of your repository and configure this task to run after the cleanup task.

All this is described in more detail in the nexus documentation.

I have tested the steps with Nexus 3.15.2-01 OSS edition.

like image 116
Sebastian Avatar answered Dec 28 '22 17:12

Sebastian


I found solution for my problem.

I don't have Cleanup Policy section in my admin console(I think this option is available only for professional or nevest versions) - Thank you @Sebastian for your advices, you directed me to the solution.

Based on this question: Purge old release from Nexus 3

I created some manual tasks to cleanup my binary repositories:

enter image description here

My cleanup task is very simple but anyone who needs something more complicated can write own Groovy script or look for ready solutions.

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))

Logs viewer is very helpful to debug scripts :)

like image 38
Krzysztof Raciniewski Avatar answered Dec 28 '22 18:12

Krzysztof Raciniewski