alg-backup 3.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/.gitignore +2 -0
  2. data/.infinity_test +7 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +25 -0
  5. data/Gemfile.lock +101 -0
  6. data/LICENSE.md +24 -0
  7. data/README.md +276 -0
  8. data/backup.gemspec +39 -0
  9. data/bin/backup +260 -0
  10. data/lib/backup.rb +168 -0
  11. data/lib/backup/archive.rb +73 -0
  12. data/lib/backup/cli.rb +50 -0
  13. data/lib/backup/compressor/base.rb +17 -0
  14. data/lib/backup/compressor/gzip.rb +61 -0
  15. data/lib/backup/configuration/base.rb +15 -0
  16. data/lib/backup/configuration/compressor/base.rb +10 -0
  17. data/lib/backup/configuration/compressor/gzip.rb +23 -0
  18. data/lib/backup/configuration/database/base.rb +18 -0
  19. data/lib/backup/configuration/database/mongodb.rb +37 -0
  20. data/lib/backup/configuration/database/mysql.rb +37 -0
  21. data/lib/backup/configuration/database/postgresql.rb +37 -0
  22. data/lib/backup/configuration/database/redis.rb +35 -0
  23. data/lib/backup/configuration/encryptor/base.rb +10 -0
  24. data/lib/backup/configuration/encryptor/gpg.rb +17 -0
  25. data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
  26. data/lib/backup/configuration/helpers.rb +54 -0
  27. data/lib/backup/configuration/notifier/base.rb +39 -0
  28. data/lib/backup/configuration/notifier/mail.rb +52 -0
  29. data/lib/backup/configuration/notifier/twitter.rb +21 -0
  30. data/lib/backup/configuration/storage/base.rb +18 -0
  31. data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
  32. data/lib/backup/configuration/storage/dropbox.rb +29 -0
  33. data/lib/backup/configuration/storage/ftp.rb +25 -0
  34. data/lib/backup/configuration/storage/rsync.rb +25 -0
  35. data/lib/backup/configuration/storage/s3.rb +25 -0
  36. data/lib/backup/configuration/storage/scp.rb +25 -0
  37. data/lib/backup/configuration/storage/sftp.rb +25 -0
  38. data/lib/backup/configuration/syncer/rsync.rb +45 -0
  39. data/lib/backup/configuration/syncer/s3.rb +33 -0
  40. data/lib/backup/database/base.rb +33 -0
  41. data/lib/backup/database/mongodb.rb +137 -0
  42. data/lib/backup/database/mysql.rb +104 -0
  43. data/lib/backup/database/postgresql.rb +111 -0
  44. data/lib/backup/database/redis.rb +105 -0
  45. data/lib/backup/dependency.rb +84 -0
  46. data/lib/backup/encryptor/base.rb +17 -0
  47. data/lib/backup/encryptor/gpg.rb +78 -0
  48. data/lib/backup/encryptor/open_ssl.rb +67 -0
  49. data/lib/backup/finder.rb +39 -0
  50. data/lib/backup/logger.rb +86 -0
  51. data/lib/backup/model.rb +272 -0
  52. data/lib/backup/notifier/base.rb +29 -0
  53. data/lib/backup/notifier/binder.rb +32 -0
  54. data/lib/backup/notifier/mail.rb +141 -0
  55. data/lib/backup/notifier/templates/notify_failure.erb +31 -0
  56. data/lib/backup/notifier/templates/notify_success.erb +16 -0
  57. data/lib/backup/notifier/twitter.rb +87 -0
  58. data/lib/backup/storage/base.rb +67 -0
  59. data/lib/backup/storage/cloudfiles.rb +95 -0
  60. data/lib/backup/storage/dropbox.rb +87 -0
  61. data/lib/backup/storage/ftp.rb +114 -0
  62. data/lib/backup/storage/object.rb +45 -0
  63. data/lib/backup/storage/rsync.rb +99 -0
  64. data/lib/backup/storage/s3.rb +108 -0
  65. data/lib/backup/storage/scp.rb +106 -0
  66. data/lib/backup/storage/sftp.rb +106 -0
  67. data/lib/backup/syncer/base.rb +10 -0
  68. data/lib/backup/syncer/rsync.rb +117 -0
  69. data/lib/backup/syncer/s3.rb +116 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/lib/templates/archive +4 -0
  72. data/lib/templates/compressor/gzip +4 -0
  73. data/lib/templates/database/mongodb +10 -0
  74. data/lib/templates/database/mysql +11 -0
  75. data/lib/templates/database/postgresql +11 -0
  76. data/lib/templates/database/redis +10 -0
  77. data/lib/templates/encryptor/gpg +9 -0
  78. data/lib/templates/encryptor/openssl +5 -0
  79. data/lib/templates/notifier/mail +14 -0
  80. data/lib/templates/notifier/twitter +9 -0
  81. data/lib/templates/readme +15 -0
  82. data/lib/templates/storage/cloudfiles +7 -0
  83. data/lib/templates/storage/dropbox +9 -0
  84. data/lib/templates/storage/ftp +8 -0
  85. data/lib/templates/storage/rsync +7 -0
  86. data/lib/templates/storage/s3 +8 -0
  87. data/lib/templates/storage/scp +8 -0
  88. data/lib/templates/storage/sftp +8 -0
  89. data/lib/templates/syncer/rsync +14 -0
  90. data/lib/templates/syncer/s3 +12 -0
  91. data/spec/archive_spec.rb +90 -0
  92. data/spec/backup_spec.rb +11 -0
  93. data/spec/compressor/gzip_spec.rb +59 -0
  94. data/spec/configuration/base_spec.rb +35 -0
  95. data/spec/configuration/compressor/gzip_spec.rb +28 -0
  96. data/spec/configuration/database/base_spec.rb +16 -0
  97. data/spec/configuration/database/mongodb_spec.rb +30 -0
  98. data/spec/configuration/database/mysql_spec.rb +32 -0
  99. data/spec/configuration/database/postgresql_spec.rb +32 -0
  100. data/spec/configuration/database/redis_spec.rb +30 -0
  101. data/spec/configuration/encryptor/gpg_spec.rb +25 -0
  102. data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
  103. data/spec/configuration/notifier/mail_spec.rb +32 -0
  104. data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
  105. data/spec/configuration/storage/dropbox_spec.rb +43 -0
  106. data/spec/configuration/storage/ftp_spec.rb +40 -0
  107. data/spec/configuration/storage/rsync_spec.rb +37 -0
  108. data/spec/configuration/storage/s3_spec.rb +37 -0
  109. data/spec/configuration/storage/scp_spec.rb +40 -0
  110. data/spec/configuration/storage/sftp_spec.rb +40 -0
  111. data/spec/configuration/syncer/rsync_spec.rb +46 -0
  112. data/spec/configuration/syncer/s3_spec.rb +43 -0
  113. data/spec/database/base_spec.rb +30 -0
  114. data/spec/database/mongodb_spec.rb +144 -0
  115. data/spec/database/mysql_spec.rb +150 -0
  116. data/spec/database/postgresql_spec.rb +164 -0
  117. data/spec/database/redis_spec.rb +122 -0
  118. data/spec/encryptor/gpg_spec.rb +57 -0
  119. data/spec/encryptor/open_ssl_spec.rb +102 -0
  120. data/spec/logger_spec.rb +46 -0
  121. data/spec/model_spec.rb +236 -0
  122. data/spec/notifier/mail_spec.rb +97 -0
  123. data/spec/notifier/twitter_spec.rb +86 -0
  124. data/spec/spec_helper.rb +21 -0
  125. data/spec/storage/base_spec.rb +33 -0
  126. data/spec/storage/cloudfiles_spec.rb +102 -0
  127. data/spec/storage/dropbox_spec.rb +105 -0
  128. data/spec/storage/ftp_spec.rb +133 -0
  129. data/spec/storage/object_spec.rb +74 -0
  130. data/spec/storage/rsync_spec.rb +115 -0
  131. data/spec/storage/s3_spec.rb +110 -0
  132. data/spec/storage/scp_spec.rb +129 -0
  133. data/spec/storage/sftp_spec.rb +125 -0
  134. data/spec/syncer/rsync_spec.rb +156 -0
  135. data/spec/syncer/s3_spec.rb +139 -0
  136. data/spec/version_spec.rb +21 -0
  137. metadata +217 -0
@@ -0,0 +1,260 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ ##
4
+ # Load RubyGems for Ruby <= 1.8.7
5
+ require 'rubygems'
6
+ require 'tempfile'
7
+ require 'fileutils'
8
+
9
+ ##
10
+ # Load Thor for the Command Line Interface
11
+ begin
12
+ require 'thor'
13
+ rescue LoadError
14
+ puts 'Backup uses Thor as CLI (Command Line Interface).'
15
+ puts 'Please install Thor first: `gem install thor`'
16
+ end
17
+
18
+ ##
19
+ # Load the Backup source
20
+ require File.expand_path("../../lib/backup", __FILE__)
21
+
22
+ ##
23
+ # Build the Backup Command Line Interface using Thor
24
+ class BackupCLI < Thor
25
+ include Thor::Actions
26
+
27
+ TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)
28
+
29
+ ##
30
+ # [Perform]
31
+ # Performs the backup process. The only required option is the --trigger [-t].
32
+ # If the other options (--config_file, --data_path, --tmp_path) aren't specified
33
+ # it'll fallback to the (good) defaults
34
+ method_option :trigger, :type => :string, :aliases => ['-t', '--triggers'], :required => true
35
+ method_option :config_file, :type => :string, :aliases => '-c'
36
+ method_option :data_path, :type => :string, :aliases => '-d'
37
+ method_option :log_path, :type => :string, :aliases => '-l'
38
+ method_option :tmp_path, :type => :string
39
+ desc 'perform', "Performs the backup for the specified trigger.\n" +
40
+ "You may perform multiple backups by providing multiple triggers, separated by commas.\n\n" +
41
+ "Example:\n\s\s$ backup perform --triggers backup1,backup2,backup3,backup4\n\n" +
42
+ "This will invoke 4 backups, and they will run in the order specified (not asynchronous)."
43
+ def perform
44
+
45
+ ##
46
+ # Overwrites the CONFIG_FILE location, if --config-file was specified
47
+ if options[:config_file]
48
+ Backup.send(:remove_const, :CONFIG_FILE)
49
+ Backup.send(:const_set, :CONFIG_FILE, options[:config_file])
50
+ end
51
+
52
+ ##
53
+ # Overwrites the DATA_PATH location, if --data-path was specified
54
+ if options[:data_path]
55
+ Backup.send(:remove_const, :DATA_PATH)
56
+ Backup.send(:const_set, :DATA_PATH, options[:data_path])
57
+ end
58
+
59
+ ##
60
+ # Overwrites the LOG_PATH location, if --log-path was specified
61
+ if options[:log_path]
62
+ Backup.send(:remove_const, :LOG_PATH)
63
+ Backup.send(:const_set, :LOG_PATH, options[:log_path])
64
+ end
65
+
66
+ ##
67
+ # Overwrites the TMP_PATH location, if --tmp-path was specified
68
+ if options[:tmp_path]
69
+ Backup.send(:remove_const, :TMP_PATH)
70
+ Backup.send(:const_set, :TMP_PATH, options[:tmp_path])
71
+ end
72
+
73
+ ##
74
+ # Ensure the TMP_PATH and LOG_PATH are created if they do not yet exist
75
+ Array.new([Backup::TMP_PATH, Backup::LOG_PATH]).each do |path|
76
+ FileUtils.mkdir_p(path)
77
+ end
78
+
79
+ ##
80
+ # Process each trigger
81
+ options[:trigger].split(",").map { |t| t.strip }.each do |trigger|
82
+
83
+ ##
84
+ # Defines the TRIGGER constant
85
+ Backup.send(:const_set, :TRIGGER, trigger)
86
+
87
+ ##
88
+ # Define the TIME constants
89
+ Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
90
+
91
+ ##
92
+ # Ensure DATA_PATH and DATA_PATH/TRIGGER are created if they do not yet exist
93
+ FileUtils.mkdir_p(File.join(Backup::DATA_PATH, Backup::TRIGGER))
94
+
95
+ ##
96
+ # Parses the backup configuration file and returns the model instance by trigger
97
+ model = Backup::Finder.new(trigger, Backup::CONFIG_FILE).find
98
+
99
+ ##
100
+ # Runs the returned model
101
+ Backup::Logger.message "Performing backup for #{model.label}!"
102
+ model.perform!
103
+
104
+ ##
105
+ # Removes the TRIGGER constant
106
+ Backup.send(:remove_const, :TRIGGER) if defined? Backup::TRIGGER
107
+
108
+ ##
109
+ # Removes the TIME constant
110
+ Backup.send(:remove_const, :TIME) if defined? Backup::TIME
111
+
112
+ ##
113
+ # Reset the Backup::Model.current to nil for the next potential run
114
+ Backup::Model.current = nil
115
+
116
+ ##
117
+ # Reset the Backup::Model.all to an empty array since this will be
118
+ # re-filled during the next Backup::Finder.new(arg1, arg2).find
119
+ Backup::Model.all = Array.new
120
+
121
+ ##
122
+ # Reset the Backup::Model.extension to 'tar' so it's at it's
123
+ # initial state when the next Backup::Model initializes
124
+ Backup::Model.extension = 'tar'
125
+ end
126
+ end
127
+
128
+ ##
129
+ # [Generate]
130
+ # Generates a configuration file based on the arguments passed in.
131
+ # For example, running $ backup generate --databases='mongodb' will generate a pre-populated
132
+ # configuration file with a base MongoDB setup
133
+ desc 'generate', 'Generates configuration blocks based on the arguments you pass in'
134
+ method_option :path, :type => :string
135
+ method_option :databases, :type => :string
136
+ method_option :storages, :type => :string
137
+ method_option :syncers, :type => :string
138
+ method_option :encryptors, :type => :string
139
+ method_option :compressors, :type => :string
140
+ method_option :notifiers, :type => :string
141
+ method_option :archives, :type => :boolean
142
+ def generate
143
+ temp_file = Tempfile.new('backup.rb')
144
+ temp_file << File.read( File.join(TEMPLATE_DIR, 'readme') )
145
+ temp_file << "Backup::Model.new(:my_backup, 'My Backup') do\n\n"
146
+
147
+ if options[:archives]
148
+ temp_file << File.read( File.join(TEMPLATE_DIR, 'archive') ) + "\n\n"
149
+ end
150
+
151
+ [:databases, :storages, :syncers, :encryptors, :compressors, :notifiers].each do |item|
152
+ if options[item]
153
+ options[item].split(',').map { |i| i.strip }.uniq.each do |entry|
154
+ if File.exist?( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) )
155
+ temp_file << File.read( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) ) + "\n\n"
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ temp_file << "end\n\n"
162
+ temp_file.close
163
+
164
+ path = options[:path] || Backup::PATH
165
+ config = File.join(path, 'config.rb')
166
+
167
+ if overwrite?(config)
168
+ FileUtils.mkdir_p(path)
169
+ File.open(config, 'w') do |file|
170
+ file.write( File.read(temp_file.path) )
171
+ puts "Generated configuration file in '#{ config }'"
172
+ end
173
+ end
174
+ temp_file.unlink
175
+ end
176
+
177
+ ##
178
+ # [Decrypt]
179
+ # Shorthand for decrypting encrypted files
180
+ desc 'decrypt', 'Decrypts encrypted files'
181
+ method_option :encryptor, :type => :string, :required => true
182
+ method_option :in, :type => :string, :required => true
183
+ method_option :out, :type => :string, :required => true
184
+ method_option :base64, :type => :boolean, :default => false
185
+ def decrypt
186
+ case options[:encryptor].downcase
187
+ when 'openssl'
188
+ base64 = options[:base64] ? '-base64' : ''
189
+ %x[openssl aes-256-cbc -d #{base64} -in '#{options[:in]}' -out '#{options[:out]}']
190
+ when 'gpg'
191
+ %x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
192
+ else
193
+ puts "Unknown encryptor: #{options[:encryptor]}"
194
+ puts "Use either 'openssl' or 'gpg'"
195
+ end
196
+ end
197
+
198
+ ##
199
+ # [Dependencies]
200
+ # Returns a list of Backup's dependencies
201
+ desc 'dependencies', 'Display the list of dependencies for Backup, or install them through Backup.'
202
+ method_option :install, :type => :string
203
+ method_option :list, :type => :boolean
204
+ def dependencies
205
+ unless options.any?
206
+ puts
207
+ puts "To display a list of available dependencies, run:\n\n"
208
+ puts " backup dependencies --list"
209
+ puts
210
+ puts "To install one of these dependencies (with the correct version), run:\n\n"
211
+ puts " backup dependencies --install <name>"
212
+ exit
213
+ end
214
+
215
+ if options[:list]
216
+ Backup::Dependency.all.each do |name, gemspec|
217
+ puts
218
+ puts name
219
+ puts "--------------------------------------------------"
220
+ puts "version: #{gemspec[:version]}"
221
+ puts "lib required: #{gemspec[:require]}"
222
+ puts "used for: #{gemspec[:for]}"
223
+ end
224
+ end
225
+
226
+ if options[:install]
227
+ puts
228
+ puts "Installing \"#{options[:install]}\" version \"#{Backup::Dependency.all[options[:install]][:version]}\".."
229
+ puts "If this doesn't work, please issue the following command yourself:\n\n"
230
+ puts " gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}'\n\n"
231
+ puts "Please wait..\n\n"
232
+ puts %x[gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}']
233
+ end
234
+ end
235
+
236
+ ##
237
+ # [Version]
238
+ # Returns the current version of the Backup gem
239
+ map '-v' => :version
240
+ desc 'version', 'Display installed Backup version'
241
+ def version
242
+ puts "Backup #{Backup::Version.current}"
243
+ end
244
+
245
+ private
246
+
247
+ ##
248
+ # Helper method for asking the user if he/she wants to overwrite the file
249
+ def overwrite?(path)
250
+ if File.exist?(path)
251
+ return yes? "A configuration file already exists in #{ path }. Do you want to overwrite? [y/n]"
252
+ end
253
+ true
254
+ end
255
+
256
+ end
257
+
258
+ ##
259
+ # Enable the CLI for the Backup binary
260
+ BackupCLI.start
@@ -0,0 +1,168 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fileutils'
4
+ require 'yaml'
5
+
6
+ ##
7
+ # The Backup Ruby Gem
8
+ module Backup
9
+
10
+ ##
11
+ # List the available database, storage, compressor, encryptor and notifier constants.
12
+ # These are used to dynamically define these constants as classes inside Backup::Finder
13
+ # to provide a nicer configuration file DSL syntax to the users. Adding existing constants
14
+ # to the arrays below will enable the user to use a constant instead of a string.
15
+ # Example, instead of:
16
+ # database "MySQL" do |mysql|
17
+ # You can do:
18
+ # database MySQL do |mysql|
19
+ DATABASES = ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis']
20
+ STORAGES = ['S3', 'CloudFiles', 'Dropbox', 'FTP', 'SFTP', 'SCP', 'RSync']
21
+ COMPRESSORS = ['Gzip']
22
+ ENCRYPTORS = ['OpenSSL', 'GPG']
23
+ SYNCERS = ['RSync', 'S3']
24
+ NOTIFIERS = ['Mail', 'Twitter']
25
+
26
+ ##
27
+ # Backup's internal paths
28
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
29
+ CONFIGURATION_PATH = File.join(LIBRARY_PATH, 'configuration')
30
+ STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
31
+ DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
32
+ COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
33
+ ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
34
+ NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
35
+ SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer')
36
+
37
+ ##
38
+ # Backup's Environment paths
39
+ PATH = File.join(ENV['HOME'], 'Backup')
40
+ DATA_PATH = File.join(ENV['HOME'], 'Backup', 'data')
41
+ CONFIG_FILE = File.join(ENV['HOME'], 'Backup', 'config.rb')
42
+ LOG_PATH = File.join(ENV['HOME'], 'Backup', 'log')
43
+ TMP_PATH = File.join(ENV['HOME'], 'Backup', '.tmp')
44
+
45
+ ##
46
+ # Autoload Backup base files
47
+ autoload :Model, File.join(LIBRARY_PATH, 'model')
48
+ autoload :Archive, File.join(LIBRARY_PATH, 'archive')
49
+ autoload :CLI, File.join(LIBRARY_PATH, 'cli')
50
+ autoload :Finder, File.join(LIBRARY_PATH, 'finder')
51
+ autoload :Dependency, File.join(LIBRARY_PATH, 'dependency')
52
+ autoload :Logger, File.join(LIBRARY_PATH, 'logger')
53
+ autoload :Version, File.join(LIBRARY_PATH, 'version')
54
+
55
+ ##
56
+ # Autoload Backup configuration files
57
+ module Configuration
58
+ autoload :Base, File.join(CONFIGURATION_PATH, 'base')
59
+ autoload :Helpers, File.join(CONFIGURATION_PATH, 'helpers')
60
+
61
+ module Notifier
62
+ autoload :Base, File.join(CONFIGURATION_PATH, 'notifier', 'base')
63
+ autoload :Mail, File.join(CONFIGURATION_PATH, 'notifier', 'mail')
64
+ autoload :Twitter, File.join(CONFIGURATION_PATH, 'notifier', 'twitter')
65
+ end
66
+
67
+ module Encryptor
68
+ autoload :Base, File.join(CONFIGURATION_PATH, 'encryptor', 'base')
69
+ autoload :OpenSSL, File.join(CONFIGURATION_PATH, 'encryptor', 'open_ssl')
70
+ autoload :GPG, File.join(CONFIGURATION_PATH, 'encryptor', 'gpg')
71
+ end
72
+
73
+ module Compressor
74
+ autoload :Base, File.join(CONFIGURATION_PATH, 'compressor', 'base')
75
+ autoload :Gzip, File.join(CONFIGURATION_PATH, 'compressor', 'gzip')
76
+ end
77
+
78
+ module Storage
79
+ autoload :Base, File.join(CONFIGURATION_PATH, 'storage', 'base')
80
+ autoload :S3, File.join(CONFIGURATION_PATH, 'storage', 's3')
81
+ autoload :CloudFiles, File.join(CONFIGURATION_PATH, 'storage', 'cloudfiles')
82
+ autoload :Dropbox, File.join(CONFIGURATION_PATH, 'storage', 'dropbox')
83
+ autoload :FTP, File.join(CONFIGURATION_PATH, 'storage', 'ftp')
84
+ autoload :SFTP, File.join(CONFIGURATION_PATH, 'storage', 'sftp')
85
+ autoload :SCP, File.join(CONFIGURATION_PATH, 'storage', 'scp')
86
+ autoload :RSync, File.join(CONFIGURATION_PATH, 'storage', 'rsync')
87
+ end
88
+
89
+ module Syncer
90
+ autoload :RSync, File.join(CONFIGURATION_PATH, 'syncer', 'rsync')
91
+ autoload :S3, File.join(CONFIGURATION_PATH, 'syncer', 's3')
92
+ end
93
+
94
+ module Database
95
+ autoload :Base, File.join(CONFIGURATION_PATH, 'database', 'base')
96
+ autoload :MySQL, File.join(CONFIGURATION_PATH, 'database', 'mysql')
97
+ autoload :PostgreSQL, File.join(CONFIGURATION_PATH, 'database', 'postgresql')
98
+ autoload :MongoDB, File.join(CONFIGURATION_PATH, 'database', 'mongodb')
99
+ autoload :Redis, File.join(CONFIGURATION_PATH, 'database', 'redis')
100
+ end
101
+ end
102
+
103
+ ##
104
+ # Autoload Backup storage files
105
+ module Storage
106
+ autoload :Base, File.join(STORAGE_PATH, 'base')
107
+ autoload :Object, File.join(STORAGE_PATH, 'object')
108
+ autoload :S3, File.join(STORAGE_PATH, 's3')
109
+ autoload :CloudFiles, File.join(STORAGE_PATH, 'cloudfiles')
110
+ autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
111
+ autoload :FTP, File.join(STORAGE_PATH, 'ftp')
112
+ autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
113
+ autoload :SCP, File.join(STORAGE_PATH, 'scp')
114
+ autoload :RSync, File.join(STORAGE_PATH, 'rsync')
115
+ end
116
+
117
+ ##
118
+ # Autoload Backup syncer files
119
+ module Syncer
120
+ autoload :Base, File.join(SYNCER_PATH, 'base')
121
+ autoload :RSync, File.join(SYNCER_PATH, 'rsync')
122
+ autoload :S3, File.join(SYNCER_PATH, 's3')
123
+ end
124
+
125
+ ##
126
+ # Autoload Backup database files
127
+ module Database
128
+ autoload :Base, File.join(DATABASE_PATH, 'base')
129
+ autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
130
+ autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
131
+ autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
132
+ autoload :Redis, File.join(DATABASE_PATH, 'redis')
133
+ end
134
+
135
+ ##
136
+ # Autoload compressor files
137
+ module Compressor
138
+ autoload :Base, File.join(COMPRESSOR_PATH, 'base')
139
+ autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
140
+ end
141
+
142
+ ##
143
+ # Autoload encryptor files
144
+ module Encryptor
145
+ autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
146
+ autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
147
+ autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
148
+ end
149
+
150
+ ##
151
+ # Autoload notification files
152
+ module Notifier
153
+ autoload :Base, File.join(NOTIFIER_PATH, 'base')
154
+ autoload :Binder, File.join(NOTIFIER_PATH, 'binder')
155
+ autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
156
+ autoload :Twitter, File.join(NOTIFIER_PATH, 'twitter')
157
+ end
158
+
159
+ ##
160
+ # Dynamically defines all the available database, storage, compressor, encryptor and notifier
161
+ # classes inside Backup::Finder to improve the DSL for the configuration file
162
+ (DATABASES + STORAGES + COMPRESSORS + ENCRYPTORS + NOTIFIERS + SYNCERS).each do |constant|
163
+ unless Backup::Finder.const_defined?(constant)
164
+ Backup::Finder.const_set(constant, Class.new)
165
+ end
166
+ end
167
+
168
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ class Archive
5
+ include Backup::CLI
6
+
7
+ ##
8
+ # Stores the name of the archive
9
+ attr_accessor :name
10
+
11
+ ##
12
+ # Stores an array of different paths/files to store
13
+ attr_accessor :paths
14
+
15
+ ##
16
+ # Stores an array of different paths/files to exclude
17
+ attr_accessor :excludes
18
+
19
+ ##
20
+ # Stores the path to the archive directory
21
+ attr_accessor :archive_path
22
+
23
+ ##
24
+ # Takes the name of the archive and the configuration block
25
+ def initialize(name, &block)
26
+ @name = name.to_sym
27
+ @paths = Array.new
28
+ @excludes = Array.new
29
+ @archive_path = File.join(TMP_PATH, TRIGGER, 'archive')
30
+
31
+ instance_eval(&block)
32
+ end
33
+
34
+ ##
35
+ # Adds new paths to the @paths instance variable array
36
+ def add(path)
37
+ @paths << path
38
+ end
39
+
40
+ ##
41
+ # Adds new paths to the @excludes instance variable array
42
+ def exclude(path)
43
+ @excludes << path
44
+ end
45
+
46
+ ##
47
+ # Archives all the provided paths in to a single .tar file
48
+ # and places that .tar file in the folder which later will be packaged
49
+ def perform!
50
+ mkdir(archive_path)
51
+ Logger.message("#{ self.class } started packaging and archiving #{ paths.map { |path| "\"#{path}\""}.join(", ") }.")
52
+ run("#{ utility(:tar) } -c #{ paths_to_exclude } #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
53
+ end
54
+
55
+ private
56
+
57
+ ##
58
+ # Returns a "tar-ready" string of all the specified paths combined
59
+ def paths_to_package
60
+ paths.map do |path|
61
+ "'#{path}'"
62
+ end.join("\s")
63
+ end
64
+
65
+ ##
66
+ # Returns a "tar-ready" string of all the specified excludes combined
67
+ def paths_to_exclude
68
+ if excludes.any?
69
+ "--exclude={" + excludes.map{ |e| "'#{e}'" }.join(",") + "}"
70
+ end
71
+ end
72
+ end
73
+ end