Skip to content
Snippets Groups Projects
Commit cd76106c authored by david_williams's avatar david_williams
Browse files

cleanup more during daily cleanup

parent f1742561
No related branches found
No related tags found
No related merge requests found
...@@ -10,30 +10,118 @@ then ...@@ -10,30 +10,118 @@ then
source ${RELENG_CONTROL}/commonComputedVariables.shsource source ${RELENG_CONTROL}/commonComputedVariables.shsource
fi fi
# remove artifacts over n days old # remove directories over n days old
# (where hours = 24 + (n * 24), basically, so that # (where hours = 24 + (n * 24), basically, so that
# even n=0 means "1 day") # even n=0 means "1 day")
# set at 10 days, under assumption that before that time, # set at ndays, under assumption that before that time,
# artifacts will be "saved" elsewhere, if needed. # direcotory will be "saved" elsewhere, if needed.
# if more cleanup is needed, we should take time, and # We never delete the last existing build (even if "old").
# existence of more recent builds into account, so we never
# delete the last existing build (even if "old").
ndays=4;
artifactsDir=${PROJECT_ARTIFACTS};
# requires parent Directiory as first argument
# if nDays not specified as second argument, then 0 is assumed
# (which is one day)
# if "saveAtLeast" is not set, as third argument, then assumed to be 1
# (that is, at least "saveAtLeast" directories will be saved, no matter how old)
function removeOldArtifactsDirectories () {
parentDir=$1;
ndays=$2;
saveAtLeast=$3;
if [ -z $parentDir ]
then
echo "ERROR: no parent directory specified in function call";
return -1;
fi
if [ -z ndays ]
then
echo "INFO: ndays not specified, 1 day assumed";
ndays=0
else
echo "INFO: ndays set to $ndays";
fi
if [ -z saveAtLeast ]
then
echo "INFO: saveAtLeast not specified, 1 assumed";
saveAtLeast=0
else
echo "INFO: saveAtLeast set to $saveAtLeast";
fi
echo; echo;
echo " Removing artifact directories older than ${ndays} days"; echo " Removing directories older than ${ndays} days";
echo " (from ${artifactsDir})"; echo " (from under ${parentDir})";
before=`find ${artifactsDir} -mindepth 2 -maxdepth 2 | wc -l`; before=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`;
echo " number of directories before cleaning: ${before}"; echo " number of directories before cleaning: ${before}";
# empty directories often result from "bad builds". We remove those no matter how old # empty directories often result from "bad builds". We remove those no matter how old
find ${artifactsDir} -mindepth 2 -maxdepth 3 -type d -empty -exec rm -fr '{}' \; find ${parentDir} -mindepth 2 -maxdepth 3 -type d -empty -exec rm -fr '{}' \;
# now remove old ones # now remove old ones
find ${artifactsDir} -mindepth 2 -maxdepth 2 -type d -ctime +$ndays -execdir ${RELENG_CONTROL}/removeIf.sh '{}' \; find ${parentDir} -mindepth 2 -maxdepth 2 -type d -ctime +$ndays -execdir ${RELENG_CONTROL}/removeIf.sh '{}' $saveAtLeast \;
after=`find ${artifactsDir} -mindepth 2 -maxdepth 2 | wc -l`; after=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`;
echo " number of directories after cleaning: ${after}"; echo " number of directories after cleaning: ${after}";
echo echo;
}
# requires parent Directiory as first argument
# if nDays not specified as second argument, then 0 is assumed
# (which is one day)
# if "saveAtLeast" is not set, as third argument, then assumed to be 1
# (that is, at least "saveAtLeast" directories will be saved, no matter how old)
function removeOldArtifactsDirectories () {
parentDir=$1;
ndays=$2;
saveAtLeast=$3;
if [ -z $parentDir ]
then
echo "ERROR: no parent directory specified in function call";
return -1;
fi
if [ -z ndays ]
then
echo "INFO: ndays not specified, 1 day assumed";
ndays=0
else
echo "INFO: ndays set to $ndays";
fi
if [ -z saveAtLeast ]
then
echo "INFO: saveAtLeast not specified, 1 assumed";
saveAtLeast=0
else
echo "INFO: saveAtLeast set to $saveAtLeast";
fi
echo;
echo " Removing directories older than ${ndays} days";
echo " (from under ${parentDir})";
before=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`;
echo " number of directories before cleaning: ${before}";
# empty directories often result from "bad builds". We remove those no matter how old
find ${parentDir} -mindepth 1 -maxdepth 1 -type d -empty -exec rm -fr '{}' \;
# now remove old ones
find ${parentDir} -mindepth 1 -maxdepth 1 -type d -ctime +$ndays -execdir ${RELENG_CONTROL}/removeIf.sh '{}' $saveAtLeast \;
after=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`;
echo " number of directories after cleaning: ${after}";
echo;
}
removeOldArtifactsDirectories ${PROJECT_ARTIFACTS} 3 1;
removeOldDirectories ${PROJECT_PROJECTS} 1 0;
removeOldDirectories ${PROJECT_TESTS} 1 0;
...@@ -7,8 +7,14 @@ if [ -z $1 ] ...@@ -7,8 +7,14 @@ if [ -z $1 ]
echo " This script requires an argument. " ; echo " This script requires an argument. " ;
exit 1; exit 1;
fi fi
foundDirectory=$1 foundDirectory=$1
nSave=$2
if [ -z $nSave ]
then
nSave=1;
fi
# should already be in foundDirectory, if execDir used # should already be in foundDirectory, if execDir used
cd $foundDirectory cd $foundDirectory
# move up one so we can examine syblings # move up one so we can examine syblings
...@@ -20,7 +26,7 @@ ndirs=$(($ndirs - 1)); # don't count the "totals" line ...@@ -20,7 +26,7 @@ ndirs=$(($ndirs - 1)); # don't count the "totals" line
# echo "NDirs: $ndirs" # echo "NDirs: $ndirs"
# if only one left, do not remove it, no matter how old # if only one left, do not remove it, no matter how old
if [ $ndirs -eq 1 ] if [ $ndirs -le $nSave ]
then then
exit 0; exit 0;
fi fi
...@@ -35,18 +41,8 @@ fi ...@@ -35,18 +41,8 @@ fi
# adding a few "should never happen" errror checks # adding a few "should never happen" errror checks
if [ -d $foundDirectory ] if [ -d $foundDirectory ]
then then
basedirname=$(basename $foundDirectory) rm -fr $foundDirectory
if [[ "$basedirname" =~ [[:digit:]]{14} ]] echo "removed $foundDirectory";
then
echo "removing $basedirname"
rm -fr $foundDirectory
else
# patches is expected, warn of others
if [ "patches" != $foundDirectory ]
then
echo "ERROR: The foundDirectory, $foundDirectory, didn't match timestamp pattern"
fi
fi
else else
echo "ERROR: the foundDirectory, $foundDirectory, is not a directory" echo "ERROR: the foundDirectory, $foundDirectory, is not a directory"
fi fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment