Jon Freedman
Jon Freedman

Reputation: 9707

Deleting artifacts older than 2 years from local nexus repository

We're running nexus on some old hardware which is limited in disk space and would like to remove artifacts older than a certain threshold.

Is there any way to do this other than a combination of find and curl?

Upvotes: 13

Views: 18686

Answers (5)

Pierluigi Vernetto
Pierluigi Vernetto

Reputation: 2050

For Nexus2, you can use my Spring Boot application https://github.com/vernetto/nexusclean , you can define rules based on date and on a minimum number of Artifacts to retain, and it generates "rm -rf" commands (using the REST API is damn slow).

For Nexus3, I would definitely use a Groovy script as a "Execute Admin Task". One is posted here groovy script to delete artifacts on nexus 3 (not nexus 2)

Upvotes: 0

AnJia
AnJia

Reputation: 149

auto purge older than 30 days(u can change it) not download docker images from nexus 3

https://gist.github.com/anjia0532/4a7fee95fd28d17f67412f48695bb6de

# nexus3's username and pwd
username = 'admin'
password = 'admin123'

# nexus host
nexusHost = 'http://localhost:8081'

# purge repo
repoName = 'docker'

# older than days
days = 30

#change and run it

Upvotes: 0

Jon Freedman
Jon Freedman

Reputation: 9707

As mentioned on a Sonatype blog post linked from a comment in the blog in gavenkoa's answer, since Nexus 2.5 there is a built in "Remove Releases From Repository" scheduled task which can be configured to delete old releases keeping a defined number.

This is sufficient to meet our needs.

Upvotes: 6

gavenkoa
gavenkoa

Reputation: 48923

Delete all files to which no one access more then 100 days and not modified more then 200 days:

find . -type f -atime +100 -mtime 200 -delete

To cleanup empty directories:

find . -type d -empty -delete

Or alternatively look to https://github.com/akquinet/nexus_cleaner/blob/master/nexus_clean.sh and corresponding blog entry http://blog.akquinet.de/2013/12/09/how-to-clean-your-nexus-release-repositories/ (delete all except last 10 releases).

Upvotes: 2

Mark O'Connor
Mark O'Connor

Reputation: 78021

There is a scheduled task that can automatically remove old snapshot releases:

Unfortunately, this does not work for hosted release repositories.

Upvotes: 8

Related Questions