backup 3.0.13 → 3.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/backup.rb +7 -0
- data/lib/backup/cli.rb +26 -1
- data/lib/backup/exception/command_not_found.rb +8 -0
- data/lib/backup/logger.rb +8 -0
- data/lib/backup/model.rb +4 -4
- data/lib/backup/notifier/templates/notify_failure.erb +4 -2
- data/lib/backup/storage/dropbox.rb +5 -1
- data/lib/backup/version.rb +1 -1
- metadata +3 -18
data/lib/backup.rb
CHANGED
@@ -33,6 +33,7 @@ module Backup
|
|
33
33
|
ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
|
34
34
|
NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
|
35
35
|
SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer')
|
36
|
+
EXCEPTION_PATH = File.join(LIBRARY_PATH, 'exception')
|
36
37
|
|
37
38
|
##
|
38
39
|
# Backup's Environment paths
|
@@ -158,6 +159,12 @@ module Backup
|
|
158
159
|
autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire')
|
159
160
|
end
|
160
161
|
|
162
|
+
##
|
163
|
+
# Autoload exception classes
|
164
|
+
module Exception
|
165
|
+
autoload :CommandNotFound, File.join(EXCEPTION_PATH, 'command_not_found')
|
166
|
+
end
|
167
|
+
|
161
168
|
##
|
162
169
|
# Dynamically defines all the available database, storage, compressor, encryptor and notifier
|
163
170
|
# classes inside Backup::Finder to improve the DSL for the configuration file
|
data/lib/backup/cli.rb
CHANGED
@@ -6,9 +6,21 @@ module Backup
|
|
6
6
|
##
|
7
7
|
# Wrapper method for %x[] to run CL commands
|
8
8
|
# through a ruby method. This helps with test coverage and
|
9
|
-
# improves readability
|
9
|
+
# improves readability.
|
10
|
+
#
|
11
|
+
# Every time the Backup::CLI#run method is invoked, it'll invoke
|
12
|
+
# the Backup::CLI#raise_if_command_not_found method after running the
|
13
|
+
# requested command on the OS.
|
14
|
+
#
|
15
|
+
# Backup::CLI#raise_if_command_not_found takes a single argument, the utility name.
|
16
|
+
# the command.slice(0, command.index(/\s/)).split('/')[-1] line will extract only the utility
|
17
|
+
# name (e.g. mongodump, pgdump, etc) from a command like "/usr/local/bin/mongodump <options>"
|
18
|
+
# and pass that in to the Backup::CLI#raise_if_command_not_found
|
10
19
|
def run(command)
|
11
20
|
%x[#{command}]
|
21
|
+
raise_if_command_not_found!(
|
22
|
+
command.slice(0, command.index(/\s/)).split('/')[-1]
|
23
|
+
)
|
12
24
|
end
|
13
25
|
|
14
26
|
##
|
@@ -46,5 +58,18 @@ module Backup
|
|
46
58
|
name
|
47
59
|
end
|
48
60
|
|
61
|
+
##
|
62
|
+
# If the command that was previously run via this Ruby process returned
|
63
|
+
# error code "32512", the invoked utility (e.g. mysqldump, pgdump, etc) could not be found.
|
64
|
+
# If this is the case then this method will throw an exception, informing the user of this problem.
|
65
|
+
#
|
66
|
+
# Since this raises an exception, it'll stop the entire backup process, clean up the temp files
|
67
|
+
# and notify the user via the built-in notifiers if these are set.
|
68
|
+
def raise_if_command_not_found!(utility)
|
69
|
+
if $?.to_i.eql?(32512)
|
70
|
+
raise Exception::CommandNotFound , "Could not find the utility \"#{utility}\" on \"#{RUBY_PLATFORM}\"."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
49
74
|
end
|
50
75
|
end
|
data/lib/backup/logger.rb
CHANGED
@@ -24,6 +24,14 @@ module Backup
|
|
24
24
|
to_file loggify(:warning, string)
|
25
25
|
end
|
26
26
|
|
27
|
+
##
|
28
|
+
# Outputs the data as if it were a regular 'puts' command,
|
29
|
+
# but also logs it to the backup.log
|
30
|
+
def self.normal(string)
|
31
|
+
puts string
|
32
|
+
to_file string
|
33
|
+
end
|
34
|
+
|
27
35
|
##
|
28
36
|
# Silently logs data to the log file
|
29
37
|
def self.silent(string)
|
data/lib/backup/model.rb
CHANGED
@@ -225,7 +225,7 @@ module Backup
|
|
225
225
|
|
226
226
|
syncers.each { |s| s.perform! }
|
227
227
|
notifiers.each { |n| n.perform!(self) }
|
228
|
-
rescue
|
228
|
+
rescue => exception
|
229
229
|
clean!
|
230
230
|
notifiers.each { |n| n.perform!(self, exception) }
|
231
231
|
show_exception!(exception)
|
@@ -263,9 +263,9 @@ module Backup
|
|
263
263
|
##
|
264
264
|
# Formats an exception
|
265
265
|
def show_exception!(exception)
|
266
|
-
|
267
|
-
|
268
|
-
|
266
|
+
Logger.normal "=" * 75 + "\nException that got raised:\n#{exception.class} - #{exception} \n" + "=" * 75 + "\n" + exception.backtrace.join("\n")
|
267
|
+
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"
|
268
|
+
Logger.normal "If you've setup a \"Notification\" in your configuration file, the above error will have been sent."
|
269
269
|
end
|
270
270
|
|
271
271
|
end
|
@@ -3,7 +3,7 @@ There seemed to be a problem backing up <%= @model.label %> (<%= @model.trigger
|
|
3
3
|
|
4
4
|
===========================================================================
|
5
5
|
Exception that got raised:
|
6
|
-
<%= @exception.to_s %>
|
6
|
+
<%= @exception.class %> - <%= @exception.to_s %>
|
7
7
|
===========================================================================
|
8
8
|
<%= @exception.backtrace.join("\n") %>
|
9
9
|
===========================================================================
|
@@ -13,8 +13,10 @@ You are running Backup version:
|
|
13
13
|
<%= Backup::Version.current %>
|
14
14
|
|
15
15
|
You are running Ruby version:
|
16
|
-
<%=
|
16
|
+
<%= RUBY_VERSION %> (patchlevel <%= RUBY_PATCHLEVEL %>)
|
17
17
|
|
18
|
+
On platform:
|
19
|
+
<%= RUBY_PLATFORM %>
|
18
20
|
|
19
21
|
---------------------------------------------------------------------------
|
20
22
|
|
@@ -79,7 +79,11 @@ module Backup
|
|
79
79
|
##
|
80
80
|
# Removes the transferred archive file from the Dropbox folder
|
81
81
|
def remove!
|
82
|
-
|
82
|
+
begin
|
83
|
+
connection.delete(File.join(remote_path, remote_file))
|
84
|
+
rescue ::Dropbox::FileNotFoundError
|
85
|
+
Logger.warn "File \"#{ File.join(remote_path, remote_file) }\" does not exist, skipping removal."
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
end
|
data/lib/backup/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 29
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 3
|
8
|
-
- 0
|
9
|
-
- 13
|
10
|
-
version: 3.0.13
|
5
|
+
version: 3.0.14
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Michael van Rooijen
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-04-02 00:00:00 +02:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ~>
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 43
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 14
|
33
|
-
- 6
|
34
24
|
version: 0.14.6
|
35
25
|
type: :runtime
|
36
26
|
version_requirements: *id001
|
@@ -92,6 +82,7 @@ files:
|
|
92
82
|
- lib/backup/encryptor/base.rb
|
93
83
|
- lib/backup/encryptor/gpg.rb
|
94
84
|
- lib/backup/encryptor/open_ssl.rb
|
85
|
+
- lib/backup/exception/command_not_found.rb
|
95
86
|
- lib/backup/finder.rb
|
96
87
|
- lib/backup/logger.rb
|
97
88
|
- lib/backup/model.rb
|
@@ -199,18 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
190
|
requirements:
|
200
191
|
- - ">="
|
201
192
|
- !ruby/object:Gem::Version
|
202
|
-
hash: 3
|
203
|
-
segments:
|
204
|
-
- 0
|
205
193
|
version: "0"
|
206
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
195
|
none: false
|
208
196
|
requirements:
|
209
197
|
- - ">="
|
210
198
|
- !ruby/object:Gem::Version
|
211
|
-
hash: 3
|
212
|
-
segments:
|
213
|
-
- 0
|
214
199
|
version: "0"
|
215
200
|
requirements: []
|
216
201
|
|