-
Notifications
You must be signed in to change notification settings - Fork 15
/
devstudio-product-cleanup.sh
executable file
·55 lines (48 loc) · 1.81 KB
/
devstudio-product-cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# This script is run here: http://hudson.qa.jboss.com/hudson/job/devstudio-cleanup/configure
# And archived here: https://raw.github.com/jbosstools/jbosstools-build-ci/master/util/cleanup/devstudio-product-cleanup.sh
# --------------------------------------------------------------------------------
# clean JBDS builds from fish://dev01.qa.atl2.redhat.com:/qa/services/http/binaries/RHDS/{nightly,release}
roots=$(find /qa/services/http/binaries/RHDS/builds/staging/ -maxdepth 2 -name builds | egrep "devstudio.*product")
log=/tmp/${0##*/}.log.`date +%Y%m%d-%H%M`.txt
echo "Logfile: $log" | tee -a $log
echo "" | tee -a $log
# before
df -h $roots | tee -a $log
echo "" | tee -a $log
# Check for $type builds more than $threshhold days old; keep minimum $numkeep builds per branch
clean ()
{
type=$1 # nightly or release
numkeep=$2 # number of builds to keep per branch
threshhold=$3 # age at which a build is available for delete
echo "Check for $type builds more than $threshhold days old; keep minimum $numkeep builds per branch" | tee -a $log
for root in $roots; do
for d in $(find $root/$type -maxdepth 1 -mindepth 1 -type d); do
echo "searching in $d"
newest=$(find $d -maxdepth 1 -mindepth 1 -type d -name "*" | sort -r | head -$numkeep) # keep these
echo "newest=$newest"
all=$(find $d -maxdepth 1 -mindepth 1 -type d -name "*" | sort -r) # only look to delete things more than $threshhold days old
echo "all=$all"
for dd in $all; do
keep=0;
for n in $newest; do
if [[ $dd == $n ]]; then
keep=1
fi
done
if [[ $keep -eq 0 ]]; then
echo "- $dd... " | tee -a $log
if [[ $USER == "hudson" ]]; then rm -fr $dd; fi
else
echo "+ $dd" | tee -a $log
fi
done
done
done
echo "" | tee -a $log
}
clean nightly 3 3
# after
df -h $roots | tee -a $log
echo "" | tee -a $log