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

improve daily cleanup scripts

parent d0bdbd23
No related branches found
No related tags found
No related merge requests found
......@@ -186,9 +186,9 @@ removeOldDirectoriesAndFiles ${RECOMMENDED_TMP_DIR} 13;
# autodownload so when if/when we want it, we have to get our selves, and copy into prereqs directory.
# And one of those, I think oagis_release? has some write protected files that prevents their deletion,
# once unzipped, so we have tweeked the permissions.
echo "INFO: Checking to remove old pre-req directories and files not accessed for 1 month."
removeOldDirectoriesAndFiles ${LOCAL_PREREQS_CACHE} 30;
echo "INFO: Checking to remove old pre-req directories and files not accessed for 3 months."
removeOldDirectoriesAndFiles ${LOCAL_PREREQS_CACHE} 90;
echo "INFO: Checking to remove old pre-req directories and files not accessed for 1 month."
removeOldDirectories ${BASE_BUILDERS} 30;
echo "INFO: Checking to remove old basebuilders not accessed for 3 months."
removeOldDirectories ${BASE_BUILDERS} 90;
#!/usr/bin/env bash
source removeUtils.shsource
return removeArtifactsDirIf "$*"
#!/usr/bin/env bash
source removeUtils.shsource
return removeIf "$*"
#!/usr/bin/env bash
# simple function that can be called via 'find' that removes and displays name of removed directory
function removeIf ()
{
# echo "arg: $1";
if [ -z $1 ]
then
echo "ERROR: No argument. This function requires a directory as an argument. " ;
return 1;
fi
foundDirectory=$1
if [ ! -d $foundDirectory ]
then
echo "ERROR: " "${foundDirectory}" ", is not a directory. This function requires a directory as an argument. "
return 2;
fi
# should already be in foundDirectory, if execDir used (and execDir, in a 'find' is recommended, as more secure)
cd $foundDirectory
rm -fr $foundDirectory
rc=$?
if [ rc == 0 ]
then
echo " removed: $foundDirectory";
else
echo "WARNING: rc: " $rc " could not remove " $foundDirectory;
fi
return rc;
}
# function that can remove a directory (e.g. via find) but checks to make sure not to remove the last one (or, last 'saveAtLeast')
function removeArtifactsIf ()
{
# echo "arg: $1";
if [ -z $1 ]
then
echo "ERROR: No argument. This function requires a directory as an argument. " ;
return 1;
fi
foundDirectory=$1
nSave=$2
if [ -z $nSave ]
then
nSave=1;
fi
if [ ! -d $foundDirectory ]
then
echo "ERROR: " "${foundDirectory}" ", is not a directory. This function requires a directory as an argument. "
return 2;
fi
# should already be in foundDirectory, if execDir used (and execDir, in a 'find' is recommended, as more secure)
cd $foundDirectory
# move up one so we can examine syblings
cd ..
currentDirectory=`pwd`
echo " current working directory: $currentDirectory";
ndirs=`ls -lA | wc -l`
ndirs=$(($ndirs - 1)); # don't count the "totals" line
# echo "NDirs: $ndirs"
# if only one left, do not remove it, no matter how old
# or, as improved ... if less than or equal to nSave is left, do not remove
if [ $ndirs -le $nSave ]
then
return 0;
fi
# To have no directories is unexpected, since otherwise this method should not have been called.
# So, this check is just a safety check.
if [ $ndirs -lt 1 ]
then
exit 101;
fi
rm -fr $foundDirectory
rc=$?
if [ rc == 0 ]
then
echo " removed: $foundDirectory";
else
echo "WARNING: rc: " $rc ". could not remove " $foundDirectory;
fi
return rc;
}
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