contrib: cron: btrbk-mail: append rsync stats to mail body

pull/57/head
Axel Burri 2015-10-23 20:34:19 +02:00
parent cb1b4d146d
commit 5c8d3f94f3
1 changed files with 20 additions and 9 deletions

View File

@ -44,6 +44,7 @@ loglevel=2
##### end config section ##### ##### end config section #####
mail_body=""
die() die()
{ {
@ -83,12 +84,20 @@ for key in $rsync_enable; do
[ -n "${rsync_key[$key]}" ] || die "rsync_key is not set for \"$key\"" [ -n "${rsync_key[$key]}" ] || die "rsync_key is not set for \"$key\""
[ -n "${rsync_opt[$key]}" ] || die "rsync_opt is not set for \"$key\"" [ -n "${rsync_opt[$key]}" ] || die "rsync_opt is not set for \"$key\""
rsync_header="### rsync ${rsync_opt[$key]} ${rsync_src[$key]} ${rsync_dst[$key]}"
if [ -d ${rsync_dst[$key]} ]; then if [ -d ${rsync_dst[$key]} ]; then
/bin/echo "### rsync ${rsync_opt[$key]} ${rsync_src[$key]} ${rsync_dst[$key]}" >> ${rsync_log[$key]} /bin/echo "$rsync_header" >> ${rsync_log[$key]}
/usr/bin/rsync ${rsync_opt[$key]} --log-file=${rsync_log[$key]} -e "/usr/bin/ssh -i ${rsync_key[$key]}" ${rsync_src[$key]} ${rsync_dst[$key]} ret=$(/usr/bin/rsync ${rsync_opt[$key]} --info=STATS --log-file=${rsync_log[$key]} -e "/usr/bin/ssh -i ${rsync_key[$key]}" ${rsync_src[$key]} ${rsync_dst[$key]})
[ $? = 0 ] || log_error "rsync failed: $key" if [ $? != 0 ]; then
log_error "rsync failed: $key"
ret+="\nERROR: rsync failed with exit code $?\n"
fi
mail_body+="$rsync_header$ret\n\n"
else else
log_error "rsync destination directory not found for \"$key\", skipping: ${rsync_dst[$key]}" ret="rsync destination directory not found for \"$key\", skipping: ${rsync_dst[$key]}"
mail_body+="$rsync_header\n$ret\n\n"
log_error "$ret"
fi fi
done done
@ -108,15 +117,17 @@ case $exitcode in
;; ;;
esac esac
# filter "At subvol ..." messages from "btrfs send" and "btrfs receive" (see issue #33). mail_body+=$ret
ret=$(/bin/echo "$ret" | grep -v '^At subvol ')
if [ "${skip_empty_mail:-no}" = "yes" ] && [ -z "$ret" ] && [ $exitcode -eq 0 ]; then if [ "${skip_empty_mail:-no}" = "yes" ] && [ -z "$mail_body" ] && [ $exitcode -eq 0 ]; then
: # skip email sending if skip_empty_mail=yes : # skip email sending if skip_empty_mail=yes
else else
# send email # send email
/bin/echo "$ret" | /bin/mail -s "$mail_subject_prefix - $status" $mailto /bin/echo -e "$mail_body" | /bin/mail -s "$mail_subject_prefix - $status" $mailto
[ $? = 0 ] || die "failed to send btrbk mail to \"$mailto\"" if [ $? != 0 ]; then
log_error "failed to send btrbk mail to \"$mailto\", dumping mail body:"
/bin/echo -e "$mail_body" 1>&2
fi
fi fi