Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions ush/bash_utils/check_for_preexist_dir_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
#
#-----------------------------------------------------------------------
Expand Down Expand Up @@ -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}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to indent line 138 to align with line 139,140

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.
#
Expand Down
6 changes: 6 additions & 0 deletions ush/bash_utils/filesys_cmds_vrfy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" "$@"
Expand Down
2 changes: 1 addition & 1 deletion ush/config.sh.RRFS_ens
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
6 changes: 5 additions & 1 deletion ush/config_defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ush/source_util_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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").
#
#-----------------------------------------------------------------------
#
Expand Down
2 changes: 1 addition & 1 deletion ush/valid_param_vals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down