X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fbackupninja.git;a=blobdiff_plain;f=backupninja;h=3943724d3449c0ef12b02eaaf9fd7553c2522ac1;hp=fb5437824c0f772fad63f9f570b8dd8cdb32e120;hb=c7e96acc455c3b5c74f97e812072e1a55664adce;hpb=22f728f7c57b4cdb3d01c9ce0d361e3c5845e4c4 diff --git a/backupninja b/backupninja index fb54378..3943724 100755 --- a/backupninja +++ b/backupninja @@ -31,7 +31,7 @@ function setupcolors() { } function colorize() { - if [ "$usecolor" == "yes" ]; then + if [ "$usecolors" == "yes" ]; then local typestr=`echo "$@" | sed 's/\(^[^:]*\).*$/\1/'` [ "$typestr" == "Debug" ] && type=0 [ "$typestr" == "Info" ] && type=1 @@ -58,7 +58,7 @@ function colorize() { # used to capture output from handlers echo_debug_msg=0 -usecolor=yes +usecolors=yes function printmsg() { [ ${#@} -gt 1 ] || return @@ -238,6 +238,7 @@ The following options are available: -t, --test Run in test mode, no actions are actually taken. -n, --now Perform actions now, instead of when they might be scheduled. + --run FILE Execute the specified action file and then exit. When using colored output, there are: EOF debug=1 @@ -266,6 +267,8 @@ function process_action() { getconf when "$defaultwhen" if [ "$processnow" == 1 ]; then info "running $file because of --now" + elif [ "$when" == "hourly" ]; then + debug "running $file because 'when = hourly'" else IFS=$'\t\n' for w in $when; do @@ -306,7 +309,7 @@ function process_action() { _fatals=`cat $bufferfile | grep "^Fatal: " | wc -l` ret=`grep "\(^Warning: \|^Error: \|^Fatal: \)" $bufferfile` - #rm $bufferfile + rm $bufferfile if [ $_fatals != 0 ]; then msg "*failed* -- $file" errormsg="$errormsg\n== failures from $file ==\n\n$ret\n" @@ -316,10 +319,12 @@ function process_action() { elif [ $_warnings != 0 ]; then msg "*warning* -- $file" errormsg="$errormsg\n== warnings from $file ==\n\n$ret\n" - elif [ $retcode == 0 ]; then - msg "success -- $file" else - msg "unknown -- $file" + msg "success -- $file" +# elif [ $retcode == 0 ]; then +# msg "success -- $file" +# else +# msg "unknown -- $file" fi let "fatals += _fatals" @@ -352,14 +357,31 @@ while [ $# -ge 1 ]; do # we shift here to avoid processing the file path shift ;; + --run) + debug=1 + if [ -f $2 ]; then + singlerun=$2 + processnow=1 + else + fatal "--run option must be fallowed by a backupninja action file" + usage + fi + shift + ;; *) + debug=1 fatal "Unknown option $1" usage + exit ;; esac shift done +#if [ $debug ]; then +# usercolors=yes +#fi + ## Load and confirm basic configuration values # bootstrap @@ -388,6 +410,7 @@ getconf GZIP /bin/gzip getconf RSYNC /usr/bin/rsync [ -d "$configdirectory" ] || fatal "Configuration directory '$configdirectory' not found." +[ -f "$logfile" ] || touch $logfile if [ "$UID" != "0" ]; then echo "$0 can only be run as root" @@ -406,8 +429,14 @@ warnings=0 actions_run=0 errormsg="" -for file in $configdirectory/*; do - [ -f $file ] || continue; +if [ "$singlerun" ]; then + files=$singlerun +else + files=`find $configdirectory -mindepth 1 | sort -n` +fi + +for file in $files; do + [ -f "$file" ] || continue check_perms $file suffix="${file##*.}"