From 4ad99413f408f7af8ee0062711efbb2b942df0c2 Mon Sep 17 00:00:00 2001 From: deajan Date: Wed, 6 Apr 2016 20:40:20 +0200 Subject: [PATCH] Added userland logging --- dev/debug_obackup.sh | 24 ++++++++++++++++++++---- dev/n_obackup.sh | 6 ++++-- obackup.sh | 24 ++++++++++++++++++++---- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/dev/debug_obackup.sh b/dev/debug_obackup.sh index c5d9c2f..bb76f68 100755 --- a/dev/debug_obackup.sh +++ b/dev/debug_obackup.sh @@ -5,10 +5,10 @@ PROGRAM="obackup" AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr" PROGRAM_VERSION=2.0-pre -PROGRAM_BUILD=2016033101 +PROGRAM_BUILD=2016040601 IS_STABLE=no -## FUNC_BUILD=2016040102 +## FUNC_BUILD=2016040602 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -64,6 +64,8 @@ LOCAL_HOST=$(hostname) ## Default log file until config file is loaded if [ -w /var/log ]; then LOG_FILE="/var/log/$PROGRAM.log" +elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then + LOG_FILE="$HOME/$PROGRAM.log" else LOG_FILE="./$PROGRAM.log" fi @@ -730,7 +732,7 @@ function CheckConnectivityRemoteHost { eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" & WaitForTaskCompletion $! 180 180 ${FUNCNAME[0]} if [ $? != 0 ]; then - Logger "Cannot ping $REMOTE_HOST" "CRITICAL" + Logger "Cannot ping $REMOTE_HOST" "ERROR" return 1 fi fi @@ -1023,8 +1025,10 @@ function InitLocalOSSettings { ## Stat command has different syntax on Linux and FreeBSD/MacOSX if [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BSD" ]; then STAT_CMD="stat -f \"%Sm\"" + STAT_CTIME_MTIME_CMD="stat -f %N;%c;%m" else STAT_CMD="stat --format %y" + STAT_CTIME_MTIME_CMD="stat -c %n;%Z;%Y" fi } @@ -1041,6 +1045,16 @@ function InitRemoteOSSettings { else REMOTE_FIND_CMD=find fi + + ## Stat command has different syntax on Linux and FreeBSD/MacOSX + if [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BSD" ]; then + REMOTE_STAT_CMD="stat -f \"%Sm\"" + REMOTE_STAT_CTIME_MTIME_CMD="stat -f \\\"%N;%c;%m\\\"" + else + REMOTE_STAT_CMD="stat --format %y" + REMOTE_STAT_CTIME_MTIME_CMD="stat -c \\\"%n;%Z;%Y\\\"" + fi + } ## END Generic functions @@ -2371,7 +2385,9 @@ GetCommandlineArguments "$@" LoadConfigFile "$1" if [ "$LOGFILE" == "" ]; then if [ -w /var/log ]; then - LOG_FILE=/var/log/$PROGRAM.$INSTANCE_ID.log + LOG_FILE="/var/log/$PROGRAM.$INSTANCE_ID.log" + elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then + LOG_FILE="$HOME/$PROGRAM.$INSTANCE_ID.log" else LOG_FILE=./$PROGRAM.$INSTANCE_ID.log fi diff --git a/dev/n_obackup.sh b/dev/n_obackup.sh index 4e460e3..e9df2ab 100755 --- a/dev/n_obackup.sh +++ b/dev/n_obackup.sh @@ -5,7 +5,7 @@ PROGRAM="obackup" AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr" PROGRAM_VERSION=2.0-pre -PROGRAM_BUILD=2016033101 +PROGRAM_BUILD=2016040601 IS_STABLE=no source "./ofunctions.sh" @@ -1336,7 +1336,9 @@ GetCommandlineArguments "$@" LoadConfigFile "$1" if [ "$LOGFILE" == "" ]; then if [ -w /var/log ]; then - LOG_FILE=/var/log/$PROGRAM.$INSTANCE_ID.log + LOG_FILE="/var/log/$PROGRAM.$INSTANCE_ID.log" + elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then + LOG_FILE="$HOME/$PROGRAM.$INSTANCE_ID.log" else LOG_FILE=./$PROGRAM.$INSTANCE_ID.log fi diff --git a/obackup.sh b/obackup.sh index f427c79..fdb8a67 100755 --- a/obackup.sh +++ b/obackup.sh @@ -5,10 +5,10 @@ PROGRAM="obackup" AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr" PROGRAM_VERSION=2.0-pre -PROGRAM_BUILD=2016033101 +PROGRAM_BUILD=2016040601 IS_STABLE=no -## FUNC_BUILD=2016040102 +## FUNC_BUILD=2016040602 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -60,6 +60,8 @@ LOCAL_HOST=$(hostname) ## Default log file until config file is loaded if [ -w /var/log ]; then LOG_FILE="/var/log/$PROGRAM.log" +elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then + LOG_FILE="$HOME/$PROGRAM.log" else LOG_FILE="./$PROGRAM.log" fi @@ -704,7 +706,7 @@ function CheckConnectivityRemoteHost { eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" & WaitForTaskCompletion $! 180 180 ${FUNCNAME[0]} if [ $? != 0 ]; then - Logger "Cannot ping $REMOTE_HOST" "CRITICAL" + Logger "Cannot ping $REMOTE_HOST" "ERROR" return 1 fi fi @@ -952,8 +954,10 @@ function InitLocalOSSettings { ## Stat command has different syntax on Linux and FreeBSD/MacOSX if [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BSD" ]; then STAT_CMD="stat -f \"%Sm\"" + STAT_CTIME_MTIME_CMD="stat -f %N;%c;%m" else STAT_CMD="stat --format %y" + STAT_CTIME_MTIME_CMD="stat -c %n;%Z;%Y" fi } @@ -969,6 +973,16 @@ function InitRemoteOSSettings { else REMOTE_FIND_CMD=find fi + + ## Stat command has different syntax on Linux and FreeBSD/MacOSX + if [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BSD" ]; then + REMOTE_STAT_CMD="stat -f \"%Sm\"" + REMOTE_STAT_CTIME_MTIME_CMD="stat -f \\\"%N;%c;%m\\\"" + else + REMOTE_STAT_CMD="stat --format %y" + REMOTE_STAT_CTIME_MTIME_CMD="stat -c \\\"%n;%Z;%Y\\\"" + fi + } ## END Generic functions @@ -2261,7 +2275,9 @@ GetCommandlineArguments "$@" LoadConfigFile "$1" if [ "$LOGFILE" == "" ]; then if [ -w /var/log ]; then - LOG_FILE=/var/log/$PROGRAM.$INSTANCE_ID.log + LOG_FILE="/var/log/$PROGRAM.$INSTANCE_ID.log" + elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then + LOG_FILE="$HOME/$PROGRAM.$INSTANCE_ID.log" else LOG_FILE=./$PROGRAM.$INSTANCE_ID.log fi