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):
In some repositories are a lot of them. I want to free up some disk space. I can delete individual files:
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:
Nexus Repository ManagerOSS 3.3.2-02
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:
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.
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:
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With