javanexusartifactsnexus3resource-cleanup

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


Solution

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