Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'develop'

  • Loading branch information...
commit 9ff307087dbda728696faa484dce99bc10b04ca4 2 parents 28221b3 + 34992a6
@meskyanichi meskyanichi authored
View
7 lib/backup.rb
@@ -33,6 +33,7 @@ module Backup
ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer')
+ EXCEPTION_PATH = File.join(LIBRARY_PATH, 'exception')
##
# Backup's Environment paths
@@ -159,6 +160,12 @@ module Notifier
end
##
+ # Autoload exception classes
+ module Exception
+ autoload :CommandNotFound, File.join(EXCEPTION_PATH, 'command_not_found')
+ end
+
+ ##
# Dynamically defines all the available database, storage, compressor, encryptor and notifier
# classes inside Backup::Finder to improve the DSL for the configuration file
(DATABASES + STORAGES + COMPRESSORS + ENCRYPTORS + NOTIFIERS + SYNCERS).each do |constant|
View
27 lib/backup/cli.rb
@@ -6,9 +6,21 @@ module CLI
##
# Wrapper method for %x[] to run CL commands
# through a ruby method. This helps with test coverage and
- # improves readability
+ # improves readability.
+ #
+ # Every time the Backup::CLI#run method is invoked, it'll invoke
+ # the Backup::CLI#raise_if_command_not_found method after running the
+ # requested command on the OS.
+ #
+ # Backup::CLI#raise_if_command_not_found takes a single argument, the utility name.
+ # the command.slice(0, command.index(/\s/)).split('/')[-1] line will extract only the utility
+ # name (e.g. mongodump, pgdump, etc) from a command like "/usr/local/bin/mongodump <options>"
+ # and pass that in to the Backup::CLI#raise_if_command_not_found
def run(command)
%x[#{command}]
+ raise_if_command_not_found!(
+ command.slice(0, command.index(/\s/)).split('/')[-1]
+ )
end
##
@@ -46,5 +58,18 @@ def utility(name)
name
end
+ ##
+ # If the command that was previously run via this Ruby process returned
+ # error code "32512", the invoked utility (e.g. mysqldump, pgdump, etc) could not be found.
+ # If this is the case then this method will throw an exception, informing the user of this problem.
+ #
+ # Since this raises an exception, it'll stop the entire backup process, clean up the temp files
+ # and notify the user via the built-in notifiers if these are set.
+ def raise_if_command_not_found!(utility)
+ if $?.to_i.eql?(32512)
+ raise Exception::CommandNotFound , "Could not find the utility \"#{utility}\" on \"#{RUBY_PLATFORM}\"."
+ end
+ end
+
end
end
View
8 lib/backup/exception/command_not_found.rb
@@ -0,0 +1,8 @@
+# encoding: utf-8
+
+module Backup
+ module Exception
+ class CommandNotFound < StandardError
+ end
+ end
+end
View
8 lib/backup/logger.rb
@@ -25,6 +25,14 @@ def self.warn(string)
end
##
+ # Outputs the data as if it were a regular 'puts' command,
+ # but also logs it to the backup.log
+ def self.normal(string)
+ puts string
+ to_file string
+ end
+
+ ##
# Silently logs data to the log file
def self.silent(string)
to_file loggify(:silent, string)
View
8 lib/backup/model.rb
@@ -225,7 +225,7 @@ def perform!
syncers.each { |s| s.perform! }
notifiers.each { |n| n.perform!(self) }
- rescue Exception => exception
+ rescue => exception
clean!
notifiers.each { |n| n.perform!(self, exception) }
show_exception!(exception)
@@ -263,9 +263,9 @@ def last_constant(constant)
##
# Formats an exception
def show_exception!(exception)
- puts ("=" * 75) + "\nException that got raised:\n#{exception}\n" + ("=" * 75) + "\n" + exception.backtrace.join("\n")
- puts ("=" * 75) + "\n\nYou are running Backup version \"#{Backup::Version.current}\" and Ruby version \"#{ENV['RUBY_VERSION']}\".\n"
- puts "If you've setup a \"Notification\" in your configuration file, the above error will have been sent."
+ Logger.normal "=" * 75 + "\nException that got raised:\n#{exception.class} - #{exception} \n" + "=" * 75 + "\n" + exception.backtrace.join("\n")
+ Logger.normal "=" * 75 + "\n\nYou are running Backup version \"#{Backup::Version.current}\" and Ruby version \"#{RUBY_VERSION} (patchlevel #{RUBY_PATCHLEVEL})\" on platform \"#{RUBY_PLATFORM}\".\n"
+ Logger.normal "If you've setup a \"Notification\" in your configuration file, the above error will have been sent."
end
end
View
6 lib/backup/notifier/templates/notify_failure.erb
@@ -3,7 +3,7 @@ There seemed to be a problem backing up <%= @model.label %> (<%= @model.trigger
===========================================================================
Exception that got raised:
-<%= @exception.to_s %>
+<%= @exception.class %> - <%= @exception.to_s %>
===========================================================================
<%= @exception.backtrace.join("\n") %>
===========================================================================
@@ -13,8 +13,10 @@ You are running Backup version:
<%= Backup::Version.current %>
You are running Ruby version:
-<%= ENV["RUBY_VERSION"] %>
+<%= RUBY_VERSION %> (patchlevel <%= RUBY_PATCHLEVEL %>)
+On platform:
+<%= RUBY_PLATFORM %>
---------------------------------------------------------------------------
View
6 lib/backup/storage/dropbox.rb
@@ -79,7 +79,11 @@ def transfer!
##
# Removes the transferred archive file from the Dropbox folder
def remove!
- connection.delete(File.join(remote_path, remote_file))
+ begin
+ connection.delete(File.join(remote_path, remote_file))
+ rescue ::Dropbox::FileNotFoundError
+ Logger.warn "File \"#{ File.join(remote_path, remote_file) }\" does not exist, skipping removal."
+ end
end
end
View
2  lib/backup/version.rb
@@ -13,7 +13,7 @@ class Version
# Defines the minor version
# PATCH:
# Defines the patch version
- MAJOR, MINOR, PATCH = 3, 0, 13
+ MAJOR, MINOR, PATCH = 3, 0, 14
##
# Returns the major version ( big release based off of multiple minor releases )
Please sign in to comment.
Something went wrong with that request. Please try again.