Permalink
Browse files

Added collecting anything sent to stderr from rsync or the snapshot and

including it in the email.
  • Loading branch information...
1 parent b921970 commit 0a93288ee092adb5c382e0384854a0b29619d539 @jdinkel committed May 21, 2012
Showing with 16 additions and 9 deletions.
  1. +2 −2 libs/rbrsyncwrapper.rb
  2. +7 −7 rbRsyncWrapper.rb
  3. +7 −0 templates/email_notification.markdown.erb
View
4 libs/rbrsyncwrapper.rb
@@ -39,13 +39,13 @@ def create_email(params)
# params = :name (send_to_name), :address (send_to_address), :rsync_result,
# :email_server (email_server), :sender_name (send_from_name),
# :sender_address (send_from_address), :backup_start_time
- # :snapshot_result
+ # :snapshot_result, :rsync_error, :snapshot_error
email_subject = 'Disk-to-disk backup results'
email_template = File.read(EMAIL_TEMPLATE_LOCATION)
email_eruby = Erubis::FastEruby.new(email_template)
- erb_binding = { :rsync_result => params[:rsync_result], :snapshot_result => params[:snapshot_result], :backup_time => determine_time(params[:backup_start_time]) }
+ erb_binding = { :rsync_result => params[:rsync_result], :snapshot_result => params[:snapshot_result], :backup_time => determine_time(params[:backup_start_time]), :rsync_error => params[:rsync_error], :snapshot_error => params[:snapshot_error]}
email_markdown = Markdown.new(email_eruby.result(erb_binding))
# return this object
View
14 rbRsyncWrapper.rb
@@ -37,21 +37,19 @@
/mnt/btr_pool/files_share_backup/ \
--sockopts=SO_SNDBUF=4194304,SO_RCVBUF=4194304"
-stdin, rsync_result, stderr = Open3.popen3(rsync_command)
-rsync_result = rsync_result.read.split.join(" \n")
-
-puts rsync_result
+stdin, rsync_result, rsync_error = Open3.popen3(rsync_command)
+rsync_result = rsync_result.read.split($/).join(" #{$/}")
+rsync_error = rsync_error.read
# do the snapshot
snapshot_command = "/sbin/btrfs subvolume snapshot \
/mnt/btr_pool/files_share_backup /mnt/btr_pool/\
files_share_backup-snap-#{backup_start.strftime("%Y.%m.%d-%H.%M.%S")}"
-stdin, snapshot_result, stderr = Open3.popen3(snapshot_command)
+stdin, snapshot_result, snapshot_error = Open3.popen3(snapshot_command)
snapshot_result = snapshot_result.read
-
-puts snapshot_result
+snapshot_error = snapshot_error.read
# Send the email
@@ -61,7 +59,9 @@
:sender_address => config['send_from'],
:sender_name => config['send_from_name'],
:rsync_result => rsync_result,
+ :rsync_error => rsync_error,
:snapshot_result => snapshot_result,
+ :snapshot_error => snapshot_error,
:backup_start_time => backup_start
}
View
7 templates/email_notification.markdown.erb
@@ -3,3 +3,10 @@
<%= snapshot_result %>
The backup took <%= backup_time %>.
+
+Errors (if any)
+------------------------------------------------------------------------------
+
+<%= rsync_errors %>
+
+<%= snapshot_errors %>

0 comments on commit 0a93288

Please sign in to comment.