interu-backup 3.0.16
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/.gitignore +2 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +117 -0
- data/Guardfile +17 -0
- data/LICENSE.md +24 -0
- data/README.md +332 -0
- data/backup.gemspec +31 -0
- data/bin/backup +267 -0
- data/lib/backup.rb +181 -0
- data/lib/backup/archive.rb +73 -0
- data/lib/backup/cli.rb +82 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/bzip2.rb +64 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/database/base.rb +18 -0
- data/lib/backup/configuration/database/mongodb.rb +41 -0
- data/lib/backup/configuration/database/mysql.rb +37 -0
- data/lib/backup/configuration/database/postgresql.rb +37 -0
- data/lib/backup/configuration/database/redis.rb +35 -0
- data/lib/backup/configuration/encryptor/base.rb +10 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
- data/lib/backup/configuration/helpers.rb +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
- data/lib/backup/configuration/storage/dropbox.rb +29 -0
- data/lib/backup/configuration/storage/ftp.rb +25 -0
- data/lib/backup/configuration/storage/rsync.rb +25 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/rsync.rb +45 -0
- data/lib/backup/configuration/syncer/s3.rb +33 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +179 -0
- data/lib/backup/database/mysql.rb +104 -0
- data/lib/backup/database/postgresql.rb +111 -0
- data/lib/backup/database/redis.rb +105 -0
- data/lib/backup/dependency.rb +96 -0
- data/lib/backup/encryptor/base.rb +17 -0
- data/lib/backup/encryptor/gpg.rb +78 -0
- data/lib/backup/encryptor/open_ssl.rb +67 -0
- data/lib/backup/exception/command_not_found.rb +8 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +102 -0
- data/lib/backup/model.rb +272 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/campfire.rb +194 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/presently.rb +105 -0
- data/lib/backup/notifier/templates/notify_failure.erb +33 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/notifier/twitter.rb +87 -0
- data/lib/backup/storage/base.rb +67 -0
- data/lib/backup/storage/cloudfiles.rb +95 -0
- data/lib/backup/storage/dropbox.rb +91 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +129 -0
- data/lib/backup/storage/s3.rb +180 -0
- data/lib/backup/storage/scp.rb +106 -0
- data/lib/backup/storage/sftp.rb +106 -0
- data/lib/backup/syncer/base.rb +10 -0
- data/lib/backup/syncer/rsync.rb +152 -0
- data/lib/backup/syncer/s3.rb +118 -0
- data/lib/backup/version.rb +43 -0
- data/lib/templates/archive +7 -0
- data/lib/templates/compressor/bzip2 +7 -0
- data/lib/templates/compressor/gzip +7 -0
- data/lib/templates/database/mongodb +14 -0
- data/lib/templates/database/mysql +14 -0
- data/lib/templates/database/postgresql +14 -0
- data/lib/templates/database/redis +13 -0
- data/lib/templates/encryptor/gpg +12 -0
- data/lib/templates/encryptor/openssl +8 -0
- data/lib/templates/notifier/campfire +11 -0
- data/lib/templates/notifier/mail +17 -0
- data/lib/templates/notifier/presently +12 -0
- data/lib/templates/notifier/twitter +12 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +10 -0
- data/lib/templates/storage/dropbox +12 -0
- data/lib/templates/storage/ftp +11 -0
- data/lib/templates/storage/rsync +10 -0
- data/lib/templates/storage/s3 +21 -0
- data/lib/templates/storage/scp +11 -0
- data/lib/templates/storage/sftp +11 -0
- data/lib/templates/syncer/rsync +17 -0
- data/lib/templates/syncer/s3 +15 -0
- data/spec/archive_spec.rb +90 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/bzip2_spec.rb +59 -0
- data/spec/compressor/gzip_spec.rb +59 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/gzip_spec.rb +28 -0
- data/spec/configuration/database/base_spec.rb +16 -0
- data/spec/configuration/database/mongodb_spec.rb +30 -0
- data/spec/configuration/database/mysql_spec.rb +32 -0
- data/spec/configuration/database/postgresql_spec.rb +32 -0
- data/spec/configuration/database/redis_spec.rb +30 -0
- data/spec/configuration/encryptor/gpg_spec.rb +25 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
- data/spec/configuration/notifier/campfire_spec.rb +20 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/notifier/twitter_spec.rb +22 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +43 -0
- data/spec/configuration/storage/ftp_spec.rb +40 -0
- data/spec/configuration/storage/rsync_spec.rb +37 -0
- data/spec/configuration/storage/s3_spec.rb +37 -0
- data/spec/configuration/storage/scp_spec.rb +40 -0
- data/spec/configuration/storage/sftp_spec.rb +40 -0
- data/spec/configuration/syncer/rsync_spec.rb +46 -0
- data/spec/configuration/syncer/s3_spec.rb +43 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +181 -0
- data/spec/database/mysql_spec.rb +150 -0
- data/spec/database/postgresql_spec.rb +164 -0
- data/spec/database/redis_spec.rb +122 -0
- data/spec/encryptor/gpg_spec.rb +57 -0
- data/spec/encryptor/open_ssl_spec.rb +102 -0
- data/spec/logger_spec.rb +58 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/campfire_spec.rb +96 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/notifier/presently_spec.rb +99 -0
- data/spec/notifier/twitter_spec.rb +86 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +105 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +131 -0
- data/spec/storage/s3_spec.rb +110 -0
- data/spec/storage/scp_spec.rb +129 -0
- data/spec/storage/sftp_spec.rb +125 -0
- data/spec/syncer/rsync_spec.rb +195 -0
- data/spec/syncer/s3_spec.rb +139 -0
- data/spec/version_spec.rb +21 -0
- metadata +231 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
class Finder
|
|
5
|
+
attr_accessor :trigger, :config
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Initializes a new Backup::Finder object
|
|
9
|
+
# and stores the path to the configuration file
|
|
10
|
+
def initialize(trigger, config)
|
|
11
|
+
@trigger = trigger.to_sym
|
|
12
|
+
@config = config
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# Tries to find and load the configuration file and return the proper
|
|
17
|
+
# backup model configuration (specified by the 'trigger')
|
|
18
|
+
def find
|
|
19
|
+
unless File.exist?(config)
|
|
20
|
+
puts "Could not find a configuration file in '#{config}'."; exit
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Loads the backup configuration file
|
|
25
|
+
instance_eval(File.read(config))
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Iterates through all the instantiated backup models and returns
|
|
29
|
+
# the one that matches the specified 'trigger'
|
|
30
|
+
Backup::Model.all.each do |model|
|
|
31
|
+
if model.trigger.eql?(trigger)
|
|
32
|
+
return Backup::Model.current = model
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
puts "Could not find trigger '#{trigger}' in '#{config}'."; exit
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
class Logger
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
# Outputs a messages to the console and writes it to the backup.log
|
|
8
|
+
def self.message(string)
|
|
9
|
+
puts loggify(:message, string, :green) unless quiet?
|
|
10
|
+
to_file loggify(:message, string)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# Outputs an error to the console and writes it to the backup.log
|
|
15
|
+
def self.error(string)
|
|
16
|
+
puts loggify(:error, string, :red) unless quiet?
|
|
17
|
+
to_file loggify(:error, string)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Outputs a notice to the console and writes it to the backup.log
|
|
22
|
+
def self.warn(string)
|
|
23
|
+
puts loggify(:warning, string, :yellow) unless quiet?
|
|
24
|
+
to_file loggify(:warning, string)
|
|
25
|
+
end
|
|
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 unless quiet?
|
|
32
|
+
to_file string
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
##
|
|
36
|
+
# Silently logs data to the log file
|
|
37
|
+
def self.silent(string)
|
|
38
|
+
to_file loggify(:silent, string)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Returns the time in [YYYY/MM/DD HH:MM:SS] format
|
|
43
|
+
def self.time
|
|
44
|
+
Time.now.strftime("%Y/%m/%d %H:%M:%S")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
# Builds the string in a log format with the date/time, the type (colorized)
|
|
49
|
+
# based on whether it's a message, notice or error, and the message itself.
|
|
50
|
+
# ANSI color codes are only used in the console, and are not written to the log
|
|
51
|
+
# since it doesn't do anything and just adds more unnecessary bloat to the log file
|
|
52
|
+
def self.loggify(type, string, color = false)
|
|
53
|
+
return "[#{time}][#{type}] #{string}" unless color
|
|
54
|
+
"[#{time}][#{send(color, type)}] #{string}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# Writes (appends) a string to the backup.log file
|
|
59
|
+
def self.to_file(string)
|
|
60
|
+
File.open(File.join(LOG_PATH, 'backup.log'), 'a') do |file|
|
|
61
|
+
file.write("#{string}\n")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# Invokes the #colorize method with the provided string
|
|
67
|
+
# and the color code "32" (for green)
|
|
68
|
+
def self.green(string)
|
|
69
|
+
colorize(string, 32)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# Invokes the #colorize method with the provided string
|
|
74
|
+
# and the color code "33" (for yellow)
|
|
75
|
+
def self.yellow(string)
|
|
76
|
+
colorize(string, 33)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
##
|
|
80
|
+
# Invokes the #colorize method the with provided string
|
|
81
|
+
# and the color code "31" (for red)
|
|
82
|
+
def self.red(string)
|
|
83
|
+
colorize(string, 31)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
# Wraps the provided string in colorizing tags to provide
|
|
88
|
+
# easier to view output to the client
|
|
89
|
+
def self.colorize(string, code)
|
|
90
|
+
"\e[#{code}m#{string}\e[0m"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
##
|
|
94
|
+
# Returns 'true' (boolean) if the QUIET constant is defined
|
|
95
|
+
# By default it isn't defined, only when initializing Backup using
|
|
96
|
+
# the '--quite' (or '-q') option in the CLI (e.g. backup perform -t my_backup --quiet)
|
|
97
|
+
def self.quiet?
|
|
98
|
+
const_defined?(:QUIET) && QUIET
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
end
|
data/lib/backup/model.rb
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
class Model
|
|
5
|
+
include Backup::CLI
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# The trigger is used as an identifier for
|
|
9
|
+
# initializing the backup process
|
|
10
|
+
attr_accessor :trigger
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# The label is used for a more friendly user output
|
|
14
|
+
attr_accessor :label
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# The databases attribute holds an array of database objects
|
|
18
|
+
attr_accessor :databases
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# The archives attr_accessor holds an array of archive objects
|
|
22
|
+
attr_accessor :archives
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# The encryptors attr_accessor holds an array of encryptor objects
|
|
26
|
+
attr_accessor :encryptors
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# The compressors attr_accessor holds an array of compressor objects
|
|
30
|
+
attr_accessor :compressors
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# The notifiers attr_accessor holds an array of notifier objects
|
|
34
|
+
attr_accessor :notifiers
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# The storages attribute holds an array of storage objects
|
|
38
|
+
attr_accessor :storages
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# The syncers attribute holds an array of syncer objects
|
|
42
|
+
attr_accessor :syncers
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# The time when the backup initiated (in format: 2011.02.20.03.29.59)
|
|
46
|
+
attr_accessor :time
|
|
47
|
+
|
|
48
|
+
class << self
|
|
49
|
+
##
|
|
50
|
+
# The Backup::Model.all class method keeps track of all the models
|
|
51
|
+
# that have been instantiated. It returns the @all class variable,
|
|
52
|
+
# which contains an array of all the models
|
|
53
|
+
attr_accessor :all
|
|
54
|
+
|
|
55
|
+
##
|
|
56
|
+
# Contains the current file extension (this changes from time to time after a file
|
|
57
|
+
# gets compressed or encrypted so we can keep track of the correct file when new
|
|
58
|
+
# extensions get appended to the current file name)
|
|
59
|
+
attr_accessor :extension
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Contains the currently-in-use model. This attribute should get set by Backup::Finder.
|
|
63
|
+
# Use Backup::Model.current to retrieve the actual data of the model
|
|
64
|
+
attr_accessor :current
|
|
65
|
+
|
|
66
|
+
##
|
|
67
|
+
# Returns the full path to the current file (including the current extension).
|
|
68
|
+
# To just return the filename and extension without the path, use File.basename(Backup::Model.file)
|
|
69
|
+
def file
|
|
70
|
+
File.join(TMP_PATH, "#{ TIME }.#{ TRIGGER }.#{ Backup::Model.extension }")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
##
|
|
74
|
+
# Returns the temporary trigger path of the current model
|
|
75
|
+
# e.g. /Users/Michael/tmp/backup/my_trigger
|
|
76
|
+
def tmp_path
|
|
77
|
+
File.join(TMP_PATH, TRIGGER)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
##
|
|
82
|
+
# Accessible through "Backup::Model.all", it stores an array of Backup::Model instances.
|
|
83
|
+
# Everytime a new Backup::Model gets instantiated it gets pushed into this array
|
|
84
|
+
@all = Array.new
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
# Contains the current file extension (should change after each compression or encryption)
|
|
88
|
+
@extension = 'tar'
|
|
89
|
+
|
|
90
|
+
##
|
|
91
|
+
# Takes a trigger, label and the configuration block and instantiates the model.
|
|
92
|
+
# The TIME (time of execution) gets stored in the @time attribute.
|
|
93
|
+
# After the instance has evaluated the configuration block and properly set the
|
|
94
|
+
# configuration for the model, it will append the newly created "model" instance
|
|
95
|
+
# to the @all class variable (Array) so it can be accessed by Backup::Finder
|
|
96
|
+
# and any other location
|
|
97
|
+
def initialize(trigger, label, &block)
|
|
98
|
+
@trigger = trigger
|
|
99
|
+
@label = label
|
|
100
|
+
@time = TIME
|
|
101
|
+
|
|
102
|
+
@databases = Array.new
|
|
103
|
+
@archives = Array.new
|
|
104
|
+
@encryptors = Array.new
|
|
105
|
+
@compressors = Array.new
|
|
106
|
+
@storages = Array.new
|
|
107
|
+
@notifiers = Array.new
|
|
108
|
+
@syncers = Array.new
|
|
109
|
+
|
|
110
|
+
instance_eval(&block)
|
|
111
|
+
Backup::Model.all << self
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
##
|
|
115
|
+
# Adds a database to the array of databases
|
|
116
|
+
# to dump during the backup process
|
|
117
|
+
def database(database, &block)
|
|
118
|
+
@databases << Backup::Database.const_get(
|
|
119
|
+
last_constant(database)
|
|
120
|
+
).new(&block)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
##
|
|
124
|
+
# Adds an archive to the array of archives
|
|
125
|
+
# to store during the backup process
|
|
126
|
+
def archive(name, &block)
|
|
127
|
+
@archives << Backup::Archive.new(name, &block)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
##
|
|
131
|
+
# Adds an encryptor to the array of encryptors
|
|
132
|
+
# to use during the backup process
|
|
133
|
+
def encrypt_with(name, &block)
|
|
134
|
+
@encryptors << Backup::Encryptor.const_get(
|
|
135
|
+
last_constant(name)
|
|
136
|
+
).new(&block)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
##
|
|
140
|
+
# Adds a compressor to the array of compressors
|
|
141
|
+
# to use during the backup process
|
|
142
|
+
def compress_with(name, &block)
|
|
143
|
+
@compressors << Backup::Compressor.const_get(
|
|
144
|
+
last_constant(name)
|
|
145
|
+
).new(&block)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
##
|
|
149
|
+
# Adds a notifier to the array of notifiers
|
|
150
|
+
# to use during the backup process
|
|
151
|
+
def notify_by(name, &block)
|
|
152
|
+
@notifiers << Backup::Notifier.const_get(
|
|
153
|
+
last_constant(name)
|
|
154
|
+
).new(&block)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
##
|
|
158
|
+
# Adds a storage method to the array of storage
|
|
159
|
+
# methods to use during the backup process
|
|
160
|
+
def store_with(storage, &block)
|
|
161
|
+
@storages << Backup::Storage.const_get(
|
|
162
|
+
last_constant(storage)
|
|
163
|
+
).new(&block)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
##
|
|
167
|
+
# Adds a syncer method to the array of syncer
|
|
168
|
+
# methods to use during the backup process
|
|
169
|
+
def sync_with(syncer, &block)
|
|
170
|
+
@syncers << Backup::Syncer.const_get(
|
|
171
|
+
last_constant(syncer)
|
|
172
|
+
).new(&block)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
##
|
|
176
|
+
# Performs the backup process
|
|
177
|
+
##
|
|
178
|
+
# [Databases]
|
|
179
|
+
# Runs all (if any) database objects to dump the databases
|
|
180
|
+
##
|
|
181
|
+
# [Archives]
|
|
182
|
+
# Runs all (if any) archive objects to package all their
|
|
183
|
+
# paths in to a single tar file and places it in the backup folder
|
|
184
|
+
##
|
|
185
|
+
# [Package]
|
|
186
|
+
# After all the database dumps and archives are placed inside
|
|
187
|
+
# the folder, it'll make a single .tar package (archive) out of it
|
|
188
|
+
##
|
|
189
|
+
# [Encryption]
|
|
190
|
+
# Optionally encrypts the packaged file with one or more encryptors
|
|
191
|
+
##
|
|
192
|
+
# [Compression]
|
|
193
|
+
# Optionally compresses the packaged file with one or more compressors
|
|
194
|
+
##
|
|
195
|
+
# [Storages]
|
|
196
|
+
# Runs all (if any) storage objects to store the backups to remote locations
|
|
197
|
+
# and (if configured) it'll cycle the files on the remote location to limit the
|
|
198
|
+
# amount of backups stored on each individual location
|
|
199
|
+
##
|
|
200
|
+
# [Syncers]
|
|
201
|
+
# Runs all (if any) sync objects to store the backups to remote locations.
|
|
202
|
+
# A Syncer does not go through the process of packaging, compressing, encrypting backups.
|
|
203
|
+
# A Syncer directly transfers data from the filesystem to the remote location
|
|
204
|
+
##
|
|
205
|
+
# [Notifiers]
|
|
206
|
+
# Runs all (if any) notifier objects when a backup proces finished with or without
|
|
207
|
+
# any errors.
|
|
208
|
+
##
|
|
209
|
+
# [Cleaning]
|
|
210
|
+
# After the whole backup process finishes, it'll go ahead and remove any temporary
|
|
211
|
+
# file that it produced. If an exception(error) is raised during this process which
|
|
212
|
+
# breaks the process, it'll always ensure it removes the temporary files regardless
|
|
213
|
+
# to avoid mass consumption of storage space on the machine
|
|
214
|
+
def perform!
|
|
215
|
+
begin
|
|
216
|
+
if databases.any? or archives.any?
|
|
217
|
+
databases.each { |d| d.perform! }
|
|
218
|
+
archives.each { |a| a.perform! }
|
|
219
|
+
package!
|
|
220
|
+
compressors.each { |c| c.perform! }
|
|
221
|
+
encryptors.each { |e| e.perform! }
|
|
222
|
+
storages.each { |s| s.perform! }
|
|
223
|
+
clean!
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
syncers.each { |s| s.perform! }
|
|
227
|
+
notifiers.each { |n| n.perform!(self) }
|
|
228
|
+
rescue => exception
|
|
229
|
+
clean!
|
|
230
|
+
notifiers.each { |n| n.perform!(self, exception) }
|
|
231
|
+
show_exception!(exception)
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
private
|
|
236
|
+
|
|
237
|
+
##
|
|
238
|
+
# After all the databases and archives have been dumped and sorted,
|
|
239
|
+
# these files will be bundled in to a .tar archive (uncompressed) so it
|
|
240
|
+
# becomes a single (transferrable) packaged file.
|
|
241
|
+
def package!
|
|
242
|
+
Logger.message "Backup started packaging everything to a single archive file."
|
|
243
|
+
run(%|#{ utility(:tar) } -c -f '#{ File.join(TMP_PATH, "#{TIME}.#{TRIGGER}.tar") }' -C '#{ TMP_PATH }' '#{ TRIGGER }'|)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
##
|
|
247
|
+
# Cleans up the temporary files that were created after the backup process finishes
|
|
248
|
+
def clean!
|
|
249
|
+
Logger.message "Backup started cleaning up the temporary files."
|
|
250
|
+
run("#{ utility(:rm) } -rf '#{ File.join(TMP_PATH, TRIGGER) }' '#{ File.join(TMP_PATH, "#{TIME}.#{TRIGGER}.#{Backup::Model.extension}") }'")
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
##
|
|
254
|
+
# Returns the string representation of the last value of a nested constant
|
|
255
|
+
# example:
|
|
256
|
+
# Backup::Model::MySQL
|
|
257
|
+
# becomes and returns:
|
|
258
|
+
# "MySQL"
|
|
259
|
+
def last_constant(constant)
|
|
260
|
+
constant.to_s.split("::").last
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
##
|
|
264
|
+
# Formats an exception
|
|
265
|
+
def show_exception!(exception)
|
|
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
|
+
end
|
|
270
|
+
|
|
271
|
+
end
|
|
272
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
module Notifier
|
|
5
|
+
class Base
|
|
6
|
+
include Backup::Configuration::Helpers
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# When set to true, the user will be notified by email
|
|
10
|
+
# when a backup process ends without raising any exceptions
|
|
11
|
+
attr_accessor :on_success
|
|
12
|
+
alias :notify_on_success? :on_success
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
# When set to true, the user will be notified by email
|
|
16
|
+
# when a backup process raises an exception before finishing
|
|
17
|
+
attr_accessor :on_failure
|
|
18
|
+
alias :notify_on_failure? :on_failure
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Logs a message to the console and log file to inform
|
|
22
|
+
# the client that Backup is notifying about the process
|
|
23
|
+
def log!
|
|
24
|
+
Logger.message "#{ self.class } started notifying about the process."
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|