From 0e05aaf6d3a44573040598e2c7d0e1239d174ef0 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Wed, 2 Jun 2021 14:42:14 +0200
Subject: [PATCH] skip file backup if config is missing

---
 .gitignore   |  1 +
 jobhelper.sh | 27 ++++++++++-----------------
 transfer.sh  |  7 +++++--
 3 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6b5ad9a..5596aec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 # ignored configs
 # ----------------------------------------------------------------------
 jobs/*.job
+keys/*
 logs/auto-*
 logs/full-*
 logs/inc-*
diff --git a/jobhelper.sh b/jobhelper.sh
index 9c13a06..0870035 100755
--- a/jobhelper.sh
+++ b/jobhelper.sh
@@ -53,30 +53,23 @@ function j_init(){
 
   j_banner
 
+  if [ ! -d ${DIR_LOGS} ]; then
+    mkdir -p ${DIR_LOGS} && echo "INFO: dir created ${DIR_LOGS}"
+  fi
+
   if [ ! -d ${DIR_JOBS} ]; then
     # mkdir -p ${DIR_JOBS} && echo "INFO: dir created ${DIR_JOBS}"
     echo "ERROR: missing jobs directory. Aborting."
     exit 1
   fi
 
-  # if transfer.sh exists, then a transfer.job must exist too
-  if [ -x "${DIR_SELF}/transfer.sh" ]; then
-    ls ${STORAGEFILE} >/dev/null
-    if [ $? -ne 0 ]; then
-      echo "ERROR: missing a config file in ${DIR_JOBS}"
-      exit 1
+  for myfile in ${JOBFILE} ${DIRFILE} ${STORAGEFILE}
+  do
+    if [ ! -f "${myfile}" ]; then
+      echo "WARNING: missing a config file: $myfile"
+      # exit 1
     fi
-  fi
-
-  if [ ! -d ${DIR_LOGS} ]; then
-    mkdir -p ${DIR_LOGS} && echo "INFO: dir created ${DIR_LOGS}"
-  fi
-
-  ls ${JOBFILE} ${DIRFILE} >/dev/null
-  if [ $? -ne 0 ]; then
-    echo "ERROR: missing a config file in ${DIR_JOBS}"
-    exit 1
-  fi
+  done
 
   # for date definitions like weekdays
   JOBDEF_LANG=`_j_getvar ${JOBFILE} "lang"`
diff --git a/transfer.sh b/transfer.sh
index 7ea65e0..e76de8d 100755
--- a/transfer.sh
+++ b/transfer.sh
@@ -38,7 +38,10 @@
   . `dirname $0`/jobhelper.sh
   . `dirname $0`/inc_bash.sh
 
-  typeset -i rc=0
+  typeset -i rc=0  
+  if [ ! -r "${DIRFILE}" -o ! -r "${STORAGEFILE}" ]; then
+    echo "SKIP backup of local files - one of the files is not readable (no error): ${DIRFILE} | ${STORAGEFILE}"
+  fi
 
   STORAGE_BIN=`_j_getvar ${STORAGEFILE} "bin"`
   STORAGE_BASEDIR=`_j_getvar ${STORAGEFILE} "storage"`
@@ -266,7 +269,7 @@
         # --- backup
         h3 "`date` Backup ${mydir}"
 
-        sCmd="$( t_backupDirGetCmdBackup)"
+        sCmd="$( t_backupDirGetCmdBackup )"
         echo "what:    ${mydir}"
         echo "target:  ${sTarget}"
         echo "command: $sCmd"
-- 
GitLab