diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b030a0f06dc9a4b72c09eb75104fd375b84b3f..48510f57c40df627175aa06021ade7c755125e97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [core] silence exit code message unless --debug is used - [core] backup halt should trigger email report if enabled - [core] wrap report email body to 1000 characters by default (DEBBUG-871793) +- [core] improve error handling around reporthost feature ## [1.2.0] - 2021-01-21 diff --git a/src/backupninja.in b/src/backupninja.in index 635d12749c050e79f1d71d20a1fbc424a5dea21b..a8afc54fd4676010c3e6d1b0c62268e08a106cb9 100755 --- a/src/backupninja.in +++ b/src/backupninja.in @@ -652,8 +652,24 @@ if [ $actions_run != 0 ]; then fi if [ -n "$reporthost" ]; then - debug "send $logfile to $reportuser@$reporthost:$reportdirectory" - rsync -qt $logfile $reportuser@$reporthost:$reportdirectory + if [ -z "$reportuser" ] || [ -z "$reportdirectory" ]; then + error "Unable to send report, reportuser and reportdirectory must be specified." + let "errors += 1" + elif [ ! -x "$(which rsync 2>/dev/null)" ]; then + error "Unable to locate rsync executable, report could not be sent to ${reporthost}." + let "errors += 1" + else + info "Sending $logfile to $reportuser@$reporthost:$reportdirectory" + execstr="rsync -qt $logfile $reportuser@$reporthost:$reportdirectory" + debug $execstr + output=$(eval $execstr 2>&1) + ret=$? + if [ $ret -ne 0 ]; then + error $output + error "An error was encountered attempting to send report to ${reporthost}." + let "errors += 1" + fi + fi fi # return exit code