diff --git a/ush/bash_utils/check_for_preexist_dir_file.sh b/ush/bash_utils/check_for_preexist_dir_file.sh index 7b9b59772..61d6a494a 100644 --- a/ush/bash_utils/check_for_preexist_dir_file.sh +++ b/ush/bash_utils/check_for_preexist_dir_file.sh @@ -63,7 +63,7 @@ where the arguments are defined as follows: method: String specifying the action to take if a preexisting version of - dir_or_file is found. Valid values are \"delete\", \"rename\", and \"quit\". + dir_or_file is found. Valid values are \"delete\", \"upgrade\", \"rename\", and \"quit\". " fi @@ -84,7 +84,7 @@ where the arguments are defined as follows: # #----------------------------------------------------------------------- # - local valid_vals_method=( "delete" "rename" "quit" ) + local valid_vals_method=( "delete" "upgrade" "rename" "quit" ) check_var_valid_value "method" "valid_vals_method" # #----------------------------------------------------------------------- @@ -112,6 +112,46 @@ where the arguments are defined as follows: # #----------------------------------------------------------------------- # +# If method is set to "upgrade", +# keep preexisting directory intact except that +# when preexisting directory is $EXPDIR, do the following: +# save all old files to a subdirecotry oldxxx/ and then +# populate new files into the $EXPDIR directory +# This is useful to keep ongoing runs uninterrupted: +# rocotoco *db files and previous cycles will stay and hence +# 1. no need to manually cp/mv *db files and previous cycles back +# 2. no need to manually restart related rocoto tasks failed during +# the workflow generation process +# This may best suit for incremental system upgrades. +# +# Alternatively, one can always elect to use the "rename" option +# and then manually do the above aftermath +# +#----------------------------------------------------------------------- +# + "upgrade") + if [[ "${dir_or_file}" == "${EXPTDIR}" ]]; then + local i=1 + local old_indx=$( printf "%03d" "$i" ) + local old_dir_or_file="${dir_or_file}/old${old_indx}" + while [ -d "${old_dir_or_file}" ]; do + i=$[$i+1] + old_indx=$( printf "%03d" "$i" ) + old_dir_or_file="${dir_or_file}/old${old_indx}" + done + + print_info_msg "$VERBOSE" " + Specified directory or file (dir_or_file) already exists: + dir_or_file = \"${dir_or_file}\" + Moving (renaming) preexisting directory or file to: + old_dir_or_file = \"${old_dir_or_file}\"" + + rsync_vrfy -a --exclude "old*" "${dir_or_file}/" "${old_dir_or_file}" + fi + ;; +# +#----------------------------------------------------------------------- +# # If method is set to "rename", we move (rename) the preexisting directory # or file. # diff --git a/ush/bash_utils/filesys_cmds_vrfy.sh b/ush/bash_utils/filesys_cmds_vrfy.sh index d11ec4720..e5d856372 100644 --- a/ush/bash_utils/filesys_cmds_vrfy.sh +++ b/ush/bash_utils/filesys_cmds_vrfy.sh @@ -234,6 +234,12 @@ function cp_vrfy() { { restore_shell_opts; } > /dev/null 2>&1 } +function rsync_vrfy() { + { save_shell_opts; set -u +x; } > /dev/null 2>&1 + filesys_cmd_vrfy "rsync" "$@" + { restore_shell_opts; } > /dev/null 2>&1 + } + function mv_vrfy() { { save_shell_opts; set -u +x; } > /dev/null 2>&1 filesys_cmd_vrfy "mv" "$@" diff --git a/ush/config.sh.RRFS_ens b/ush/config.sh.RRFS_ens index bb34be263..defe3f66e 100644 --- a/ush/config.sh.RRFS_ens +++ b/ush/config.sh.RRFS_ens @@ -15,7 +15,7 @@ VERBOSE="TRUE" RUN_REALTIME=TRUE RUN_ENVIR="nco" -PREEXISTING_DIR_METHOD="rename" +PREEXISTING_DIR_METHOD="upgrade" PREDEF_GRID_NAME=RRFS_CONUS_3km ADDNL_OUTPUT_GRIDS=( "clue" "hrrr" ) diff --git a/ush/config_defaults.sh b/ush/config_defaults.sh index 715933b32..305f798b2 100644 --- a/ush/config_defaults.sh +++ b/ush/config_defaults.sh @@ -978,13 +978,17 @@ PREDEF_GRID_NAME="" # use to deal with preexisting directories [e.g ones generated by previous # calls to the experiment generation script using the same experiment name # (EXPT_SUBDIR) as the current experiment]. This variable must be set to -# one of "delete", "rename", and "quit". The resulting behavior for each +# one of "delete", "upgrade", "rename", and "quit". The resulting behavior for each # of these values is as follows: # # * "delete": # The preexisting directory is deleted and a new directory (having the # same name as the original preexisting directory) is created. # +# * "upgrade": +# save a copy and then upgrade the preexisting $EXPDIR directory +# keep intact for other preexisting directories + # * "rename": # The preexisting directory is renamed and a new directory (having the # same name as the original preexisting directory) is created. The new diff --git a/ush/source_util_funcs.sh b/ush/source_util_funcs.sh index 1ebe07aff..65bfe90de 100644 --- a/ush/source_util_funcs.sh +++ b/ush/source_util_funcs.sh @@ -76,7 +76,7 @@ function source_util_funcs() { # # Source the file containing the function that checks for preexisting # directories or files and handles them according to a specified method -# (which can be one of "delete", "rename", and "quit"). +# (which can be one of "delete", "rename", "upgrade" and "quit"). # #----------------------------------------------------------------------- # diff --git a/ush/valid_param_vals.sh b/ush/valid_param_vals.sh index 8b5769766..784ef59ec 100644 --- a/ush/valid_param_vals.sh +++ b/ush/valid_param_vals.sh @@ -42,7 +42,7 @@ valid_vals_FV3GFS_FILE_FMT_LBCS=("nemsio" "grib2") valid_vals_GEFS_FILE_FMT_ICS=("grib2") valid_vals_GEFS_FILE_FMT_LBCS=("grib2") valid_vals_GRID_GEN_METHOD=("GFDLgrid" "ESGgrid") -valid_vals_PREEXISTING_DIR_METHOD=("delete" "rename" "quit") +valid_vals_PREEXISTING_DIR_METHOD=("delete" "upgrade" "rename" "quit") valid_vals_GTYPE=("regional") valid_vals_WRTCMP_output_grid=("rotated_latlon" "lambert_conformal" "regional_latlon") valid_vals_RUN_TASK_MAKE_GRID=("TRUE" "true" "YES" "yes" "FALSE" "false" "NO" "no")