Permalink
Browse files

fixed a couple bugs with calculating snapshots

  • Loading branch information...
1 parent f71413b commit a7312052c592034ddc25c2c56786c1581db1886d @jdinkel committed May 22, 2012
Showing with 17 additions and 8 deletions.
  1. +6 −5 libs/rbrsyncwrapper.rb
  2. +7 −3 rbRsyncWrapper.rb
  3. +4 −0 templates/email_notification.markdown.erb
View
@@ -2,12 +2,12 @@
require 'erubis'
require 'redcarpet/compat'
-def all_snaps
- Dir.glob '/mnt/btr_pool/files02_share_backup-snap-*'
+def all_snaps(location)
+ Dir.glob "#{location}-snap-*"
end
-def oldest_snap_time
- x = all_snaps[-1].split('-')[-2..-1].join('.').split('.')
+def oldest_snap_time(location)
+ x = all_snaps(location).sort[0].split('-')[-2..-1].join('.').split('.')
Time.new(x[0].to_i, x[1].to_i, x[2].to_i, x[3].to_i, x[4].to_i, x[5].to_i)
end
@@ -49,12 +49,13 @@ def create_email(params)
# :email_server (email_server), :sender_name (send_from_name),
# :sender_address (send_from_address), :backup_start_time
# :snapshot_result, :rsync_error, :snapshot_error
+ # :backup_destination
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]), :rsync_errors => params[:rsync_error], :snapshot_errors => params[:snapshot_error], :number_backups => all_snaps.count, :oldest_backup_time => oldest_snap_time }
+ erb_binding = { :rsync_result => params[:rsync_result], :snapshot_result => params[:snapshot_result], :backup_time => determine_time(params[:backup_start_time]), :rsync_errors => params[:rsync_error], :snapshot_errors => params[:snapshot_error], :number_backups => all_snaps(params[:backup_destination]).count, :oldest_backup_time => oldest_snap_time(params[:backup_destination) }
email_markdown = Markdown.new(email_eruby.result(erb_binding))
# return this object
View
@@ -22,6 +22,8 @@
puts "Error reading the configuration file."
exit(false)
end
+config['backup_destination'] = config['backup_destination'][0...-1] if config['backup_destination'][-1] == '/'
+
# Just making sure the password file is secure
`chown root.adm #{password_file}`
@@ -34,7 +36,7 @@
rsync_command = "/usr/bin/rsync -hrtz --inplace --no-p --no-g \
--chmod=ugo=rwX --delete --stats --password-file=#{password_file} \
#{config['rsync_username']}@#{config['backup_source_computer']}::\
-Share-Backup_Snap #{config['backup_destination']} \
+Share-Backup_Snap #{config['backup_destination']}/ \
--sockopts=SO_SNDBUF=4194304,SO_RCVBUF=4194304"
stdin, rsync_result, rsync_error = Open3.popen3(rsync_command)
@@ -44,8 +46,9 @@
# 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")}"
+#{config['backup_destination']} \
+#{config['backup_destination']}-snap-\
+#{backup_start.strftime("%Y.%m.%d-%H.%M.%S")}"
stdin, snapshot_result, snapshot_error = Open3.popen3(snapshot_command)
snapshot_result = snapshot_result.read
@@ -63,6 +66,7 @@
:snapshot_result => snapshot_result,
:snapshot_error => snapshot_error,
:backup_start_time => backup_start
+ :backup_destination => config['backup_destination']
}
email = create_email(email_params)
@@ -10,6 +10,10 @@ There are <%= number_backups %> days worth of snapshots, going back to
Errors (if any)
------------------------------------------------------------------------------
+rsync:
+
<%= rsync_errors %>
+snapshot:
+
<%= snapshot_errors %>

0 comments on commit a731205

Please sign in to comment.