So we have our own private Maven repository that we publish snapshot builds to.
We have lots builds so diskspace is starting to become a problem for all our snapshot builds. While its fun and all to go manually do this I was wondering if anyone knows of a CRON script that I can run to do the snap开发者_StackOverflow中文版shot cleanup.
I know sonatype does this for their own repo but I could not find a script.
To find all snapshot files that were updated more than two weeks ago:
find . -type f -mtime +14 | grep SNAPSHOT
Pipe that to xargs rm
and you should be good.
The one caveat: a repository manager will create a metadata.xml
file that lists all published revisions. Assuming that you're just using scp
to publish, and a webserver to retrieve, I don't think that file exists (so the fact that this script doesn't touch it shouldn't be an issue).
The following script works fine for me:
#!/bin/sh
REPO=/var/www/maven2/snapshots
find $REPO -type d -name '*-SNAPSHOT' | while read project; do
if [ -f $project/maven-metadata.xml ]; then # Make sure this is a maven artifact directory
# Assume that snapshot numbering is designed to be sorted numerically
latestversion=$(ls $project | grep -v 'maven-metadata.*' | sort -n | grep '\.pom$' | tail -n1)
latestversion=$(basename $latestversion .pom)
# Delete everything, but the latest version and the maven metadata
find $project -type f | grep -v -e 'maven-metadata.*' -e "$latestversion.*" | xargs rm
fi
done
精彩评论