From ae260a69f2d6348e3e835d7350b66f39712fc17c Mon Sep 17 00:00:00 2001 From: Rahul Mahajan Date: Tue, 25 Jun 2024 12:29:29 -0400 Subject: [PATCH 1/2] add cleanup of stale RUNDIRS from an experiment --- parm/config/gefs/config.base | 1 - parm/config/gfs/config.base | 3 +-- scripts/exglobal_cleanup.sh | 18 +++++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/parm/config/gefs/config.base b/parm/config/gefs/config.base index 16e0fefaba..9808b96579 100644 --- a/parm/config/gefs/config.base +++ b/parm/config/gefs/config.base @@ -99,7 +99,6 @@ export EXPDIR="@EXPDIR@/${PSLOT}" export ROTDIR="@COMROOT@/${PSLOT}" export DATAROOT="${STMP}/RUNDIRS/${PSLOT}" # TODO: set via prod_envir in Ops -export RUNDIR="${DATAROOT}" # TODO: Should be removed; use DATAROOT instead export ARCDIR="${NOSCRUB}/archive/${PSLOT}" export ATARDIR="@ATARDIR@" diff --git a/parm/config/gfs/config.base b/parm/config/gfs/config.base index f893eaaf4e..9fd494a9eb 100644 --- a/parm/config/gfs/config.base +++ b/parm/config/gfs/config.base @@ -128,7 +128,6 @@ if [[ "${PDY}${cyc}" -ge "2019092100" && "${PDY}${cyc}" -le "2019110700" ]]; the export DUMP_SUFFIX="p" # Use dumps from NCO GFS v15.3 parallel fi export DATAROOT="${STMP}/RUNDIRS/${PSLOT}" # TODO: set via prod_envir in Ops -export RUNDIR="${DATAROOT}" # TODO: Should be removed; use DATAROOT instead export ARCDIR="${NOSCRUB}/archive/${PSLOT}" export ATARDIR="@ATARDIR@" @@ -295,7 +294,7 @@ export FHOUT_GFS=3 # 3 for ops export FHMAX_HF_GFS=@FHMAX_HF_GFS@ export FHOUT_HF_GFS=1 export FHOUT_OCN_GFS=6 -export FHOUT_ICE_GFS=6 +export FHOUT_ICE_GFS=6 export FHMIN_WAV=0 export FHOUT_WAV=3 export FHMAX_HF_WAV=120 diff --git a/scripts/exglobal_cleanup.sh b/scripts/exglobal_cleanup.sh index 7c3dfafbad..2671b2a998 100755 --- a/scripts/exglobal_cleanup.sh +++ b/scripts/exglobal_cleanup.sh @@ -2,6 +2,7 @@ source "${USHgfs}/preamble.sh" +echo "Begin Cleanup ${DATAROOT}!" # Remove DATAoutput from the forecast model run # TODO: Handle this better DATAfcst="${DATAROOT}/${RUN}fcst.${PDY:-}${cyc}" @@ -9,6 +10,21 @@ if [[ -d "${DATAfcst}" ]]; then rm -rf "${DATAfcst}"; fi #DATAefcs="${DATAROOT}/${RUN}efcs???${PDY:-}${cyc}" rm -rf "${DATAROOT}/${RUN}efcs"*"${PDY:-}${cyc}" +# Search and delete files/directories from DATAROOT/ older than ${purge_every_days} days +# purge_every_days should be a positive integer +purge_every_days=3 + +# Find and delete files older than ${purge_every_days} days +find "${DATAROOT}" -type f -mtime "+${purge_every_days}" -exec rm -f {} \; + +# Find and delete directories older than ${purge_every_days} days +find "${DATAROOT}" -type d -mtime "+${purge_every_days}" -exec rmdir {} \; + +# Note: The -exec rmdir {} \; will only remove empty directories +# If you want to force remove directories along with their contents, use the following line instead: +# find "${DATAROOT}" -type d -mtime "+${purge_every_days}" -exec rm -rf {} \; +echo "Cleanup ${DATAROOT} completed!" + ############################################################### # Clean up previous cycles; various depths # PRIOR CYCLE: Leave the prior cycle alone @@ -67,7 +83,7 @@ for (( current_date=first_date; current_date <= last_date; \ # shellcheck disable=SC2312 if [[ $(tail -n 1 "${rocotolog}") =~ "This cycle is complete: Success" ]]; then YMD="${current_PDY}" HH="${current_cyc}" declare_from_tmpl \ - COMOUT_TOP:COM_TOP_TMPL + COMOUT_TOP:COM_TOP_TMPL if [[ -d "${COMOUT_TOP}" ]]; then IFS=", " read -r -a exclude_list <<< "${exclude_string:-}" remove_files "${COMOUT_TOP}" "${exclude_list[@]:-}" From 923039db372d746dc2ac91282fe87c49636499fa Mon Sep 17 00:00:00 2001 From: Rahul Mahajan Date: Tue, 25 Jun 2024 18:20:10 -0400 Subject: [PATCH 2/2] remove files and directories all the same --- scripts/exglobal_cleanup.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/exglobal_cleanup.sh b/scripts/exglobal_cleanup.sh index 2671b2a998..1150ca6d1d 100755 --- a/scripts/exglobal_cleanup.sh +++ b/scripts/exglobal_cleanup.sh @@ -2,7 +2,9 @@ source "${USHgfs}/preamble.sh" +############################################################### echo "Begin Cleanup ${DATAROOT}!" + # Remove DATAoutput from the forecast model run # TODO: Handle this better DATAfcst="${DATAROOT}/${RUN}fcst.${PDY:-}${cyc}" @@ -15,15 +17,13 @@ rm -rf "${DATAROOT}/${RUN}efcs"*"${PDY:-}${cyc}" purge_every_days=3 # Find and delete files older than ${purge_every_days} days -find "${DATAROOT}" -type f -mtime "+${purge_every_days}" -exec rm -f {} \; +find "${DATAROOT}/"* -type f -mtime "+${purge_every_days}" -exec rm -f {} \; # Find and delete directories older than ${purge_every_days} days -find "${DATAROOT}" -type d -mtime "+${purge_every_days}" -exec rmdir {} \; +find "${DATAROOT}/"* -type d -mtime "+${purge_every_days}" -exec rm -rf {} \; -# Note: The -exec rmdir {} \; will only remove empty directories -# If you want to force remove directories along with their contents, use the following line instead: -# find "${DATAROOT}" -type d -mtime "+${purge_every_days}" -exec rm -rf {} \; echo "Cleanup ${DATAROOT} completed!" +############################################################### ############################################################### # Clean up previous cycles; various depths