From 376cb9e0b36ecfcdacdf6cc805486f53b945dd0b Mon Sep 17 00:00:00 2001 From: deajan Date: Wed, 17 Jul 2013 11:31:21 +0200 Subject: [PATCH] Fixed cleanup launches even if DEBUG=yes --- obackup.sh | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/obackup.sh b/obackup.sh index d0b8799..dc5a1bd 100755 --- a/obackup.sh +++ b/obackup.sh @@ -3,7 +3,7 @@ ###### Remote (or local) backup script for files & databases ###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr) OBACKUP_VERSION=1.84RC1 -OBACKUP_BUILD=1607201301 +OBACKUP_BUILD=1707201301 DEBUG=no SCRIPT_PID=$$ @@ -65,13 +65,23 @@ function TrapError function TrapStop { LogError " /!\ WARNING: Manual exit of backup script. Backups may be in inconsistent state." - if [ "$DEBUG" == "no" ] - then - CleanUp - fi + CleanUp exit 1 } +function TrapQuit +{ + if [ $error_alert -ne 0 ] + then + SendAlert + LogError "Backup script finished with errors." + exit 1 + else + Log "Backup script finshed." + exit 0 + fi +} + function Spinner { if [ $silent -eq 1 ] @@ -124,15 +134,18 @@ function EscapeSpaces function CleanUp { - rm -f /dev/shm/obackup_dblist_$SCRIPT_PID - rm -f /dev/shm/obackup_local_sql_storage_$SCRIPT_PID - rm -f /dev/shm/obackup_local_file_storage_$SCRIPT_PID - rm -f /dev/shm/obackup_dirs_recurse_list_$SCRIPT_PID - rm -f /dev/shm/obackup_fsize_$SCRIPT_PID - rm -f /dev/shm/obackup_rsync_output_$SCRIPT_PID - rm -f /dev/shm/obackup_config_$SCRIPT_PID - rm -f /dev/shm/obackup_run_local_$SCRIPT_PID - rm -f /dev/shm/obackup_run_remote_$SCRIPT_PID + if [ "$DEBUG" != "yes" ] + then + rm -f /dev/shm/obackup_dblist_$SCRIPT_PID + rm -f /dev/shm/obackup_local_sql_storage_$SCRIPT_PID + rm -f /dev/shm/obackup_local_file_storage_$SCRIPT_PID + rm -f /dev/shm/obackup_dirs_recurse_list_$SCRIPT_PID + rm -f /dev/shm/obackup_fsize_$SCRIPT_PID + rm -f /dev/shm/obackup_rsync_output_$SCRIPT_PID + rm -f /dev/shm/obackup_config_$SCRIPT_PID + rm -f /dev/shm/obackup_run_local_$SCRIPT_PID + rm -f /dev/shm/obackup_run_remote_$SCRIPT_PID + fi } function SendAlert @@ -923,7 +936,8 @@ function Init set -o pipefail set -o errtrace - trap TrapStop SIGINT SIGQUIT + trap TrapStop SIGINT SIGQUIT SIGKILL SIGTERM SIGHUP + trap TrapQuit EXIT if [ "$DEBUG" == "yes" ] then trap 'TrapError ${LINENO} $?' ERR @@ -1073,13 +1087,3 @@ then else LogError "Environment not suitable to run obackup." fi - -if [ $error_alert -ne 0 ] -then - SendAlert - LogError "Backup script finished with errors." - exit 1 -else - Log "Backup script finshed." - exit 0 -fi