Reuse backup function

This commit is contained in:
2024-07-31 21:35:23 -04:00
parent f8ee1e09c1
commit 458dbed560

View File

@@ -270,7 +270,7 @@ random_words() {
backup() {
debug "Running: ${FUNCNAME[0]}" "$@"
for f in "$@"; do
[[ -f $f ]] || continue
[[ -e $f ]] || continue
count=1
while [[ -f $f.bk.$count ]]; do
count=$((count+1))
@@ -1410,16 +1410,7 @@ choose_easy_results_dir() {
# Always backup existing output
# This would happen if you ran the same experiment twice in one day, for instance
if [[ -d $EASY_RESULTS_DIR ]] ; then
backup_dir="$EASY_RESULTS_DIR"
count=1
while [[ -d $backup_dir ]]; do
backup_dir="$backup_dir.$((count++))"
done
echo "Backing up existing output from $EASY_RESULTS_DIR to $backup_dir"
debug "rsync -a $EASY_RESULTS_DIR $backup_dir"
rsync -a "$EASY_RESULTS_DIR" "$backup_dir" || return 1
fi
[[ -d $EASY_RESULTS_DIR ]] && backup "$EASY_RESULTS_DIR"
if [[ ! -d $EASY_RESULTS_DIR ]]; then
debug "mkdir $EASY_RESULTS_DIR"