26f6313a8b8d — Carsten Grohmann 10 months ago
Add redirecting output to a log file
2 files changed, 11 insertions(+), 1 deletions(-)

M README.md
M restic.sh
M README.md +4 -0
@@ 242,6 242,10 @@ Okt 16 22:15:19 saturn systemd[1]: resti
 
 ## Änderungsprotokoll
 
+## offen - Version 5
+
+* Umleitung der Ausgabe in eine Logdatei ist möglich
+
 ### 30. März 2024 - Version 4
 
 * Berechnung der Größe aller Buckets hinzufügt

          
M restic.sh +7 -1
@@ 5,7 5,7 @@ 
 # License: MIT (see LICENSE.txt)
 # THIS PROGRAM COMES WITH NO WARRANTY
 
-VERSION="4"
+VERSION="5"
 
 # Shellcheck disable "Check exit code directly with e.g. if mycmd;, not indirectly with $?."
 # shellcheck disable=SC2181

          
@@ 19,6 19,9 @@ else
   LAUNCHED_BY_SYSTEMD=""
 fi
 
+# Log file for output redirection
+#LOG_FILE="/tmp/$(basename $0).log"
+
 function error {
   if [ "$LAUNCHED_BY_SYSTEMD" ]; then
     echo "ERROR: $*"

          
@@ 99,6 102,9 @@ BACKUP_ACTIONS_NON_SYSTEMD=(CHECK BACKUP
 
 GIB_IN_BYTES=1073741824
 
+# Redirect output
+[[ "${LOG_FILE:-}" ]] && exec </dev/null >>$LOG_FILE 2>&1
+
 function do_backup {
   info "Start restic backup ..."
   $RESTIC_BIN backup "${RESTIC_BACKUP_OPTS[@]}"