]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Better error checking in the backup script.
authorSergey Poznyakoff <gray@gnu.org>
Sat, 12 Nov 2016 10:31:24 +0000 (12:31 +0200)
committerSergey Poznyakoff <gray@gnu.org>
Sat, 12 Nov 2016 10:31:24 +0000 (12:31 +0200)
* scripts/backup.in: Check exit code of MT_BEGIN
* scripts/backup.sh.in (backup_host): Return meaningful code
in case of remote execution.  See the comment, though.

scripts/backup.in
scripts/backup.sh.in

index 087ab2c183398bd77b5e1e5cc93ef20b4a08b75e..1093748a8c8f33ca8bae928be734c6e75d6bad7f 100644 (file)
@@ -155,7 +155,10 @@ message 20 "BACKUP_FILES=$BACKUP_FILES"
 # the exit value from various commands more easily.
 (
  message 1 "preparing tapes"
- $MT_BEGIN "${TAPE_FILE}"
+ if ! $MT_BEGIN "${TAPE_FILE}"; then
+    echo >&2 "$0: tape initialization failed"
+    exit 1
+ fi 
  rm -f "${VOLNO_FILE}"
 
  message 1 "processing backup directories"
@@ -191,7 +194,7 @@ message 20 "BACKUP_FILES=$BACKUP_FILES"
      # 'rsh' doesn't exit with the exit status of the remote command.  What
      # stupid lossage.  TODO: think of a reliable workaround.
      if [ $? -ne 0 ] ; then
-        echo "Backup of ${1} failed." 1>&2
+        echo "$0: backup of ${1} failed." 1>&2
          # I'm assuming that the tar will have written an empty
          # file to the tape, otherwise I should do a cat here.
      else
@@ -238,17 +241,17 @@ message 20 "BACKUP_FILES=$BACKUP_FILES"
  else
      echo "No miscellaneous files specified"
  fi
-
  message 1 "final cleanup"
 
  $MT_REWIND "${TAPE_FILE}"
  $MT_OFFLINE "${TAPE_FILE}"
  echo "."
 ) 2>&1 | tee -a "${LOGFILE}"
+RC=$?
 
 if test "${ADMINISTRATOR}" != NONE; then
      echo "Sending the dump log to ${ADMINISTRATOR}"
      mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
 fi
-
+exit $RC
 # EOF
index 4e739cd82a52fd52b9e7616ce3a6820b624bde3b..2c69ee933c98b8f502c3068167bd545c16007b72 100644 (file)
@@ -311,7 +311,9 @@ backup_host() {
         CMD="exec ${TAR_PART1} -f \"${TAPE_FILE}\" $@"
         message 10 "CMD: $CMD"
         sh -c "$CMD"
-        message 10 "RC: $?"
+        RC=$?
+        message 10 "RC: $RC"
+        return $RC
     fi
 }