backup 2.4.5.1 → 3.0.0.build.0

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.
Files changed (168) hide show
  1. data/.gitignore +2 -0
  2. data/.infinity_test +7 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +17 -0
  5. data/Gemfile.lock +88 -0
  6. data/LICENSE.md +24 -0
  7. data/README.md +189 -75
  8. data/backup.gemspec +41 -0
  9. data/bin/backup +161 -90
  10. data/lib/backup.rb +133 -117
  11. data/lib/backup/archive.rb +54 -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 +7 -67
  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 +47 -17
  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/storage/base.rb +18 -0
  30. data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
  31. data/lib/backup/configuration/storage/dropbox.rb +25 -0
  32. data/lib/backup/configuration/storage/ftp.rb +25 -0
  33. data/lib/backup/configuration/storage/rsync.rb +25 -0
  34. data/lib/backup/configuration/storage/s3.rb +25 -0
  35. data/lib/backup/configuration/storage/scp.rb +25 -0
  36. data/lib/backup/configuration/storage/sftp.rb +25 -0
  37. data/lib/backup/database/base.rb +33 -0
  38. data/lib/backup/database/mongodb.rb +137 -0
  39. data/lib/backup/database/mysql.rb +104 -0
  40. data/lib/backup/database/postgresql.rb +111 -0
  41. data/lib/backup/database/redis.rb +105 -0
  42. data/lib/backup/encryptor/base.rb +17 -0
  43. data/lib/backup/encryptor/gpg.rb +78 -0
  44. data/lib/backup/encryptor/open_ssl.rb +67 -0
  45. data/lib/backup/finder.rb +39 -0
  46. data/lib/backup/logger.rb +80 -0
  47. data/lib/backup/model.rb +249 -0
  48. data/lib/backup/notifier/base.rb +29 -0
  49. data/lib/backup/notifier/binder.rb +32 -0
  50. data/lib/backup/notifier/mail.rb +141 -0
  51. data/lib/backup/notifier/templates/notify_failure.erb +31 -0
  52. data/lib/backup/notifier/templates/notify_success.erb +16 -0
  53. data/lib/backup/storage/base.rb +60 -3
  54. data/lib/backup/storage/cloudfiles.rb +85 -6
  55. data/lib/backup/storage/dropbox.rb +74 -4
  56. data/lib/backup/storage/ftp.rb +103 -27
  57. data/lib/backup/storage/object.rb +45 -0
  58. data/lib/backup/storage/rsync.rb +100 -0
  59. data/lib/backup/storage/s3.rb +100 -7
  60. data/lib/backup/storage/scp.rb +94 -19
  61. data/lib/backup/storage/sftp.rb +94 -19
  62. data/lib/backup/version.rb +70 -1
  63. data/lib/templates/archive +4 -0
  64. data/lib/templates/compressor/gzip +4 -0
  65. data/lib/templates/database/mongodb +10 -0
  66. data/lib/templates/database/mysql +11 -0
  67. data/lib/templates/database/postgresql +11 -0
  68. data/lib/templates/database/redis +10 -0
  69. data/lib/templates/encryptor/gpg +9 -0
  70. data/lib/templates/encryptor/openssl +5 -0
  71. data/lib/templates/notifier/mail +14 -0
  72. data/lib/templates/readme +15 -0
  73. data/lib/templates/storage/cloudfiles +7 -0
  74. data/lib/templates/storage/dropbox +8 -0
  75. data/lib/templates/storage/ftp +8 -0
  76. data/lib/templates/storage/rsync +7 -0
  77. data/lib/templates/storage/s3 +8 -0
  78. data/lib/templates/storage/scp +8 -0
  79. data/lib/templates/storage/sftp +8 -0
  80. data/spec/archive_spec.rb +53 -0
  81. data/spec/backup_spec.rb +11 -0
  82. data/spec/compressor/gzip_spec.rb +59 -0
  83. data/spec/configuration/base_spec.rb +35 -0
  84. data/spec/configuration/compressor/gzip_spec.rb +28 -0
  85. data/spec/configuration/database/base_spec.rb +16 -0
  86. data/spec/configuration/database/mongodb_spec.rb +30 -0
  87. data/spec/configuration/database/mysql_spec.rb +32 -0
  88. data/spec/configuration/database/postgresql_spec.rb +32 -0
  89. data/spec/configuration/database/redis_spec.rb +30 -0
  90. data/spec/configuration/encryptor/gpg_spec.rb +25 -0
  91. data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
  92. data/spec/configuration/notifier/mail_spec.rb +32 -0
  93. data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
  94. data/spec/configuration/storage/dropbox_spec.rb +40 -0
  95. data/spec/configuration/storage/ftp_spec.rb +40 -0
  96. data/spec/configuration/storage/rsync_spec.rb +37 -0
  97. data/spec/configuration/storage/s3_spec.rb +37 -0
  98. data/spec/configuration/storage/scp_spec.rb +40 -0
  99. data/spec/configuration/storage/sftp_spec.rb +40 -0
  100. data/spec/database/base_spec.rb +30 -0
  101. data/spec/database/mongodb_spec.rb +144 -0
  102. data/spec/database/mysql_spec.rb +150 -0
  103. data/spec/database/postgresql_spec.rb +164 -0
  104. data/spec/database/redis_spec.rb +122 -0
  105. data/spec/encryptor/gpg_spec.rb +57 -0
  106. data/spec/encryptor/open_ssl_spec.rb +102 -0
  107. data/spec/logger_spec.rb +37 -0
  108. data/spec/model_spec.rb +236 -0
  109. data/spec/notifier/mail_spec.rb +97 -0
  110. data/spec/spec_helper.rb +21 -0
  111. data/spec/storage/base_spec.rb +33 -0
  112. data/spec/storage/cloudfiles_spec.rb +102 -0
  113. data/spec/storage/dropbox_spec.rb +89 -0
  114. data/spec/storage/ftp_spec.rb +133 -0
  115. data/spec/storage/object_spec.rb +74 -0
  116. data/spec/storage/rsync_spec.rb +115 -0
  117. data/spec/storage/s3_spec.rb +110 -0
  118. data/spec/storage/scp_spec.rb +129 -0
  119. data/spec/storage/sftp_spec.rb +125 -0
  120. data/spec/version_spec.rb +32 -0
  121. metadata +139 -123
  122. data/CHANGELOG +0 -131
  123. data/LICENSE +0 -20
  124. data/generators/backup/backup_generator.rb +0 -69
  125. data/generators/backup/templates/backup.rake +0 -56
  126. data/generators/backup/templates/backup.rb +0 -253
  127. data/generators/backup/templates/create_backup_tables.rb +0 -18
  128. data/generators/backup_update/backup_update_generator.rb +0 -50
  129. data/generators/backup_update/templates/migrations/update_backup_tables.rb +0 -27
  130. data/lib/backup/adapters/archive.rb +0 -34
  131. data/lib/backup/adapters/base.rb +0 -167
  132. data/lib/backup/adapters/custom.rb +0 -41
  133. data/lib/backup/adapters/mongo_db.rb +0 -139
  134. data/lib/backup/adapters/mysql.rb +0 -60
  135. data/lib/backup/adapters/postgresql.rb +0 -60
  136. data/lib/backup/adapters/sqlite.rb +0 -25
  137. data/lib/backup/command_helper.rb +0 -14
  138. data/lib/backup/configuration/adapter.rb +0 -21
  139. data/lib/backup/configuration/adapter_options.rb +0 -8
  140. data/lib/backup/configuration/attributes.rb +0 -19
  141. data/lib/backup/configuration/mail.rb +0 -20
  142. data/lib/backup/configuration/smtp.rb +0 -8
  143. data/lib/backup/configuration/storage.rb +0 -8
  144. data/lib/backup/connection/cloudfiles.rb +0 -75
  145. data/lib/backup/connection/dropbox.rb +0 -63
  146. data/lib/backup/connection/s3.rb +0 -88
  147. data/lib/backup/core_ext/object.rb +0 -5
  148. data/lib/backup/environment/base.rb +0 -12
  149. data/lib/backup/environment/rails_configuration.rb +0 -15
  150. data/lib/backup/environment/unix_configuration.rb +0 -109
  151. data/lib/backup/mail/base.rb +0 -97
  152. data/lib/backup/mail/mail.txt +0 -7
  153. data/lib/backup/record/base.rb +0 -65
  154. data/lib/backup/record/cloudfiles.rb +0 -28
  155. data/lib/backup/record/dropbox.rb +0 -27
  156. data/lib/backup/record/ftp.rb +0 -39
  157. data/lib/backup/record/local.rb +0 -26
  158. data/lib/backup/record/s3.rb +0 -25
  159. data/lib/backup/record/scp.rb +0 -33
  160. data/lib/backup/record/sftp.rb +0 -38
  161. data/lib/backup/storage/local.rb +0 -22
  162. data/lib/generators/backup/USAGE +0 -10
  163. data/lib/generators/backup/backup_generator.rb +0 -47
  164. data/lib/generators/backup/templates/backup.rake +0 -56
  165. data/lib/generators/backup/templates/backup.rb +0 -236
  166. data/lib/generators/backup/templates/create_backup_tables.rb +0 -18
  167. data/setup/backup.rb +0 -257
  168. data/setup/backup.sqlite3 +0 -0
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/backup')
4
+
5
+ Gem::Specification.new do |gem|
6
+
7
+ ##
8
+ # General configuration / information
9
+ gem.name = 'backup'
10
+ gem.version = Backup::Version.gemspec
11
+ gem.platform = Gem::Platform::RUBY
12
+ gem.authors = 'Michael van Rooijen'
13
+ gem.email = 'meskyanichi@gmail.com'
14
+ gem.homepage = 'http://rubygems.org/gems/backup'
15
+ gem.summary = 'Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL.'
16
+ gem.description = 'Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL.
17
+ It supports various various databases (MySQL, PostgreSQL, MongoDB and Redis), it supports various storage locations
18
+ (Amazon S3, Rackspace Cloud Files, Dropbox, any remote server through FTP, SFTP, SCP and RSync), it can archive files and folders,
19
+ it can cycle backups, it can do incremental backups, it can compress backups, it can encrypt backups (OpenSSL or GPG),
20
+ it can notify you about successful and/or failed backups. It is very extensible and easy to add new functionality to. It\'s easy to use.'
21
+
22
+ ##
23
+ # Files and folder that need to be compiled in to the Ruby Gem
24
+ gem.files = %x[git ls-files].split("\n")
25
+ gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
26
+ gem.require_path = 'lib'
27
+
28
+ ##
29
+ # The Backup CLI executable
30
+ gem.executables = ['backup']
31
+
32
+ ##
33
+ # Production gem dependencies
34
+ gem.add_dependency 'thor', ['~> 0.14.6'] # CLI
35
+ gem.add_dependency 'fog', ['~> 0.5.3' ] # Amazon S3, Rackspace Cloud Files
36
+ gem.add_dependency 'dropbox', ['~> 1.2.3' ] # Dropbox
37
+ gem.add_dependency 'mail', ['~> 2.2.15'] # Mail
38
+ gem.add_dependency 'net-sftp', ['~> 2.0.5' ] # SFTP Protocol
39
+ gem.add_dependency 'net-scp', ['~> 1.0.4' ] # SCP Protocol
40
+
41
+ end
data/bin/backup CHANGED
@@ -1,108 +1,179 @@
1
- #!/usr/bin/env ruby
1
+ #! /usr/bin/env ruby
2
2
 
3
- require 'optparse'
4
- require 'backup'
3
+ ##
4
+ # Load RubyGems for Ruby <= 1.8.7
5
+ require 'rubygems'
6
+ require 'tempfile'
7
+ require 'fileutils'
5
8
 
6
- Backup::System.boot!
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
+
26
+ TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)
27
+
28
+ ##
29
+ # [Perform]
30
+ # Performs the backup process. The only required option is the --trigger [-t].
31
+ # If the other options (--config_file, --data_path, --tmp_path) aren't specified
32
+ # it'll fallback to the (good) defaults
33
+ method_option :trigger, :type => :string, :aliases => '-t', :required => true
34
+ method_option :config_file, :type => :string, :aliases => '-c'
35
+ method_option :data_path, :type => :string, :aliases => '-d'
36
+ method_option :log_path, :type => :string, :aliases => '-l'
37
+ method_option :tmp_path, :type => :string
38
+ desc 'perform', 'Performs the backup for the specified trigger'
39
+ def perform
40
+
41
+ ##
42
+ # Defines the TRIGGER and TIME constants
43
+ Backup.send(:const_set, :TRIGGER, options[:trigger])
44
+ Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
45
+
46
+ ##
47
+ # Overwrites the CONFIG_FILE location, if --config-file was specified
48
+ if options[:config_file]
49
+ Backup.send(:remove_const, :CONFIG_FILE)
50
+ Backup.send(:const_set, :CONFIG_FILE, options[:config_file])
51
+ end
7
52
 
8
- include Backup::Environment::UnixConfiguration::Commands
9
- include Backup::Environment::UnixConfiguration::Helpers
53
+ ##
54
+ # Overwrites the DATA_PATH location, if --data-path was specified
55
+ if options[:data_path]
56
+ Backup.send(:remove_const, :DATA_PATH)
57
+ Backup.send(:const_set, :DATA_PATH, options[:data_path])
58
+ end
10
59
 
11
- options = {}
60
+ ##
61
+ # Overwrites the LOG_PATH location, if --log-path was specified
62
+ if options[:log_path]
63
+ Backup.send(:remove_const, :LOG_PATH)
64
+ Backup.send(:const_set, :LOG_PATH, options[:log_path])
65
+ end
12
66
 
13
- optparse = OptionParser.new do |opts|
14
-
15
- opts.banner = "\nUsage: backup [options]\n "
16
-
17
- opts.on('-r', '--run [trigger]', "Runs backup process by trigger") do |trigger|
18
- confirm_configuration_file_existence
19
- puts "Running: #{trigger}."
20
- Backup::Setup.new(trigger, @backup_procedures).initialize_adapter
67
+ ##
68
+ # Overwrites the TMP_PATH location, if --tmp-path was specified
69
+ if options[:tmp_path]
70
+ Backup.send(:remove_const, :TMP_PATH)
71
+ Backup.send(:const_set, :TMP_PATH, options[:tmp_path])
72
+ end
73
+
74
+ ##
75
+ # Ensure the TMP_PATH, LOG_PATH, DATA_PATH and DATA_PATH/TRIGGER
76
+ # are created if they do not yet exist
77
+ Array.new([
78
+ Backup::TMP_PATH,
79
+ Backup::LOG_PATH,
80
+ File.join(Backup::DATA_PATH, Backup::TRIGGER)
81
+ ]).each do |path|
82
+ FileUtils.mkdir_p(path)
83
+ end
84
+
85
+ ##
86
+ # Parses the backup configuration file and returns the model instance by trigger
87
+ model = Backup::Finder.new(Backup::TRIGGER, Backup::CONFIG_FILE).find
88
+
89
+ ##
90
+ # Runs the returned model
91
+ Backup::Logger.message "Performing backup for #{model.label}!"
92
+ model.perform!
21
93
  end
22
-
23
- opts.on('-f', '--find [trigger]', "Finds backup records by trigger") do |trigger|
24
- confirm_configuration_file_existence
25
- puts "Finding backup records with trigger: #{trigger}."
26
- backup = Backup::Setup.new(trigger, @backup_procedures)
27
- records = backup.procedure.record_class.all( :conditions => {:trigger => trigger} )
28
-
29
- if options[:table]
30
- puts Hirb::Helpers::AutoTable.render(records)
94
+
95
+ ##
96
+ # [Generate]
97
+ # Generates a configuration file based on the arguments passed in.
98
+ # For example, running $ backup generate --databases='mongodb' will generate a pre-populated
99
+ # configuration file with a base MongoDB setup
100
+ desc 'generate', 'Generates configuration blocks based on the arguments you pass in'
101
+ method_option :path, :type => :string
102
+ method_option :databases, :type => :string
103
+ method_option :storages, :type => :string
104
+ method_option :encryptors, :type => :string
105
+ method_option :compressors, :type => :string
106
+ method_option :notifiers, :type => :string
107
+ method_option :archives, :type => :boolean
108
+ def generate
109
+ temp_file = Tempfile.new('backup.rb')
110
+ temp_file << File.read( File.join(TEMPLATE_DIR, 'readme') )
111
+ temp_file << "Backup::Model.new(:my_backup, 'My Backup') do\n\n"
112
+
113
+ if options[:archives]
114
+ temp_file << File.read( File.join(TEMPLATE_DIR, 'archive') ) + "\n\n"
115
+ end
116
+
117
+ [:databases, :storages, :encryptors, :compressors, :notifiers].each do |item|
118
+ if options[item]
119
+ options[item].split(',').map(&:strip).uniq.each do |entry|
120
+ if File.exist?( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) )
121
+ temp_file << File.read( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) ) + "\n\n"
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ temp_file << "end\n\n"
128
+ temp_file.close
129
+ if options[:path]
130
+ FileUtils.mkdir_p(options[:path])
131
+ File.open(File.join(options[:path], 'config.rb'), 'w') do |file|
132
+ file.write( File.read(temp_file.path) )
133
+ puts "Generated configuration file in '#{File.join(options[:path], 'config.rb')}'"
134
+ end
31
135
  else
32
- records.each do |record|
33
- puts record.to_yaml
136
+ FileUtils.mkdir_p(Backup::PATH)
137
+ File.open(File.join(Backup::PATH, 'config.rb'), 'w') do |file|
138
+ file.write( File.read(temp_file.path) )
139
+ puts "Generated configuration file in '#{File.join(Backup::PATH, 'config.rb')}'"
34
140
  end
35
141
  end
36
- end
37
-
38
- opts.on('-t', '--truncate [trigger]', "Truncates backup records for specified trigger") do |trigger|
39
- puts "Truncating backup records with trigger: #{trigger}."
40
- Backup::Record::Base.destroy_all :trigger => trigger
41
- end
42
-
43
- opts.on('-d', '--destroy [trigger]', "Destroys backup records and files for specified trigger") do |trigger|
44
- confirm_configuration_file_existence
45
- puts "Destroying backup records with trigger: #{trigger}."
46
- backup = Backup::Setup.new(trigger, @backup_procedures)
47
- backup.procedure.record_class.destroy_all_backups( backup.procedure, trigger )
48
- end
49
-
50
- opts.on('--truncate-all', "Truncates all backup records") do
51
- puts "Truncating all backup records."
52
- Backup::Record::Base.destroy_all
142
+ temp_file.unlink
53
143
  end
54
144
 
55
- opts.on('--destroy-all', "Destroys all backup records and files") do
56
- confirm_configuration_file_existence
57
- puts "Destroying all backup records."
58
- backup = Backup::Setup.new(false, @backup_procedures)
59
- backup.procedures.each do |backup_procedure|
60
- backup_procedure.record_class.destroy_all_backups( backup_procedure, backup_procedure.trigger )
145
+ ##
146
+ # [Decrypt]
147
+ # Shorthand for decrypting encrypted files
148
+ desc 'decrypt', 'Decrypts encrypted files'
149
+ method_option :encryptor, :type => :string, :required => true
150
+ method_option :in, :type => :string, :required => true
151
+ method_option :out, :type => :string, :required => true
152
+ method_option :base64, :type => :boolean, :default => false
153
+ def decrypt
154
+ case options[:encryptor].downcase
155
+ when 'openssl'
156
+ base64 = options[:base64] ? '-base64' : ''
157
+ %x[openssl aes-256-cbc -d #{base64} -in '#{options[:in]}' -out '#{options[:out]}']
158
+ when 'gpg'
159
+ %x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
160
+ else
161
+ puts "Unknown encryptor: #{options[:encryptor]}"
162
+ puts "Use either 'openssl' or 'gpg'"
61
163
  end
62
164
  end
63
165
 
64
- opts.on('--decrypt [file]', "Decrypts a \"Backup\" encrypted file") do |file|
65
- puts "Attempting to decrypt: #{file}."
66
- %x{ openssl enc -des-cbc -d -in #{file} -out #{file.gsub('.enc', '')} }
67
- end
68
-
69
- options[:table] = false
70
- opts.on('--table', "Shows records in table format") do |format|
71
- options[:table] = true
166
+ ##
167
+ # [Version]
168
+ # Returns the current version of the Backup gem
169
+ map '-v' => :version
170
+ desc 'version', 'Display installed Backup version'
171
+ def version
172
+ puts "Backup #{Backup::Version.current}"
72
173
  end
73
174
 
74
- opts.on('--setup', "Sets up Backup") do
75
- setup
76
- end
77
-
78
- opts.on('--reset', "Reinstalls Backup (This will remove ALL current settings!)") do
79
- reset
80
- end
81
-
82
- opts.on('--remove', "Removes Backup (This will remove ALL current settings!)") do
83
- remove
84
- end
85
-
86
- opts.on('-v', '--version', 'Displays installed Backup version') do
87
- File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) do |file|
88
- puts "Backup version #{file.read}"
89
- end
90
- exit
91
- end
92
-
93
- opts.on('-h', '--help', 'Display help screen') do
94
- puts opts
95
- puts "\n "
96
- exit
97
- end
98
-
99
175
  end
100
176
 
101
- begin
102
- optparse.parse!
103
- rescue OptionParser::InvalidOption
104
- puts "\nInvalid Option. See the list of available options below.\n"
105
- puts optparse
106
- puts "\n "
107
- exit
108
- end
177
+ ##
178
+ # Enable the CLI for the Backup binary
179
+ BackupCLI.start
@@ -1,132 +1,148 @@
1
- BACKUP_SYSTEM = Proc.new do
2
- # Load Gems
3
- require 'hirb'
4
-
5
- # Load Extensions
6
- require 'backup/core_ext/object'
7
-
8
- # Load Environments
9
- require 'backup/environment/base'
10
- require 'backup/environment/unix_configuration'
11
- require 'backup/environment/rails_configuration'
12
-
13
- # Load Configuration
14
- require 'backup/configuration/attributes'
15
- require 'backup/configuration/base'
16
- require 'backup/configuration/adapter'
17
- require 'backup/configuration/adapter_options'
18
- require 'backup/configuration/storage'
19
- require 'backup/configuration/mail'
20
- require 'backup/configuration/smtp'
21
- require 'backup/configuration/helpers'
22
-
23
- require 'backup/command_helper'
24
-
25
- # Include the Configuration and Environment Helpers
26
- include Backup::Configuration::Helpers
27
- include Backup::Environment::Base
28
-
29
- # Load either UNIX or RAILS environment configuration
30
- case current_environment
31
- when :unix then include Backup::Environment::UnixConfiguration
32
- when :rails then include Backup::Environment::RailsConfiguration
33
- end
1
+ # encoding: utf-8
34
2
 
35
- # Load configuration
36
- if File.exist?(File.join(BACKUP_PATH, 'config', 'backup.rb'))
37
- require File.join(BACKUP_PATH, 'config', 'backup.rb')
38
- end
3
+ require 'fileutils'
4
+ require 'yaml'
39
5
 
40
- # Load Mail Notifier
41
- require 'backup/mail/base'
6
+ ##
7
+ # The Backup Ruby Gem
8
+ module Backup
42
9
 
43
- # Set Mail Configuration (extracted from the backup.rb configuration file) inside the Mail Class
44
- Backup::Mail::Base.setup(@mail_configuration)
45
- end
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
+ NOTIFIERS = ['Mail']
46
24
 
47
- # Backup Module
48
- module Backup
49
-
50
- class System
51
- def self.boot!
52
- BACKUP_SYSTEM.call
53
- true
25
+ ##
26
+ # Backup's internal paths
27
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
28
+ CONFIGURATION_PATH = File.join(LIBRARY_PATH, 'configuration')
29
+ STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
30
+ DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
31
+ COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
32
+ ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
33
+ NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
34
+
35
+ ##
36
+ # Backup's Environment paths
37
+ PATH = File.join(ENV['HOME'], 'Backup')
38
+ DATA_PATH = File.join(ENV['HOME'], 'Backup', 'data')
39
+ CONFIG_FILE = File.join(ENV['HOME'], 'Backup', 'config.rb')
40
+ LOG_PATH = File.join(ENV['HOME'], 'Backup', 'log')
41
+ TMP_PATH = File.join(ENV['HOME'], 'Backup', '.tmp')
42
+
43
+ ##
44
+ # Autoload Backup base files
45
+ autoload :Model, File.join(LIBRARY_PATH, 'model')
46
+ autoload :Archive, File.join(LIBRARY_PATH, 'archive')
47
+ autoload :CLI, File.join(LIBRARY_PATH, 'cli')
48
+ autoload :Finder, File.join(LIBRARY_PATH, 'finder')
49
+ autoload :Logger, File.join(LIBRARY_PATH, 'logger')
50
+ autoload :Version, File.join(LIBRARY_PATH, 'version')
51
+
52
+ ##
53
+ # Autoload Backup configuration files
54
+ module Configuration
55
+ autoload :Base, File.join(CONFIGURATION_PATH, 'base')
56
+ autoload :Helpers, File.join(CONFIGURATION_PATH, 'helpers')
57
+
58
+ module Notifier
59
+ autoload :Base, File.join(CONFIGURATION_PATH, 'notifier', 'base')
60
+ autoload :Mail, File.join(CONFIGURATION_PATH, 'notifier', 'mail')
61
+ end
62
+
63
+ module Encryptor
64
+ autoload :Base, File.join(CONFIGURATION_PATH, 'encryptor', 'base')
65
+ autoload :OpenSSL, File.join(CONFIGURATION_PATH, 'encryptor', 'open_ssl')
66
+ autoload :GPG, File.join(CONFIGURATION_PATH, 'encryptor', 'gpg')
67
+ end
68
+
69
+ module Compressor
70
+ autoload :Base, File.join(CONFIGURATION_PATH, 'compressor', 'base')
71
+ autoload :Gzip, File.join(CONFIGURATION_PATH, 'compressor', 'gzip')
72
+ end
73
+
74
+ module Storage
75
+ autoload :Base, File.join(CONFIGURATION_PATH, 'storage', 'base')
76
+ autoload :S3, File.join(CONFIGURATION_PATH, 'storage', 's3')
77
+ autoload :CloudFiles, File.join(CONFIGURATION_PATH, 'storage', 'cloudfiles')
78
+ autoload :Dropbox, File.join(CONFIGURATION_PATH, 'storage', 'dropbox')
79
+ autoload :FTP, File.join(CONFIGURATION_PATH, 'storage', 'ftp')
80
+ autoload :SFTP, File.join(CONFIGURATION_PATH, 'storage', 'sftp')
81
+ autoload :SCP, File.join(CONFIGURATION_PATH, 'storage', 'scp')
82
+ autoload :RSync, File.join(CONFIGURATION_PATH, 'storage', 'rsync')
83
+ end
84
+
85
+ module Database
86
+ autoload :Base, File.join(CONFIGURATION_PATH, 'database', 'base')
87
+ autoload :MySQL, File.join(CONFIGURATION_PATH, 'database', 'mysql')
88
+ autoload :PostgreSQL, File.join(CONFIGURATION_PATH, 'database', 'postgresql')
89
+ autoload :MongoDB, File.join(CONFIGURATION_PATH, 'database', 'mongodb')
90
+ autoload :Redis, File.join(CONFIGURATION_PATH, 'database', 'redis')
54
91
  end
55
- end
56
-
57
- module Adapters
58
- autoload :Base, 'backup/adapters/base'
59
- autoload :MySQL, 'backup/adapters/mysql'
60
- autoload :MongoDB, 'backup/adapters/mongo_db'
61
- autoload :SQLite, 'backup/adapters/sqlite'
62
- autoload :PostgreSQL, 'backup/adapters/postgresql'
63
- autoload :Archive, 'backup/adapters/archive'
64
- autoload :Custom, 'backup/adapters/custom'
65
92
  end
66
93
 
94
+ ##
95
+ # Autoload Backup storage files
67
96
  module Storage
68
- autoload :Base, 'backup/storage/base'
69
- autoload :CloudFiles, 'backup/storage/cloudfiles'
70
- autoload :S3, 'backup/storage/s3'
71
- autoload :SCP, 'backup/storage/scp'
72
- autoload :FTP, 'backup/storage/ftp'
73
- autoload :SFTP, 'backup/storage/sftp'
74
- autoload :Local, 'backup/storage/local'
75
- autoload :Dropbox, 'backup/storage/dropbox'
97
+ autoload :Base, File.join(STORAGE_PATH, 'base')
98
+ autoload :Object, File.join(STORAGE_PATH, 'object')
99
+ autoload :S3, File.join(STORAGE_PATH, 's3')
100
+ autoload :CloudFiles, File.join(STORAGE_PATH, 'cloudfiles')
101
+ autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
102
+ autoload :FTP, File.join(STORAGE_PATH, 'ftp')
103
+ autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
104
+ autoload :SCP, File.join(STORAGE_PATH, 'scp')
105
+ autoload :RSync, File.join(STORAGE_PATH, 'rsync')
76
106
  end
77
107
 
78
- module Record
79
- autoload :Base, 'backup/record/base'
80
- autoload :CloudFiles, 'backup/record/cloudfiles'
81
- autoload :S3, 'backup/record/s3'
82
- autoload :SCP, 'backup/record/scp'
83
- autoload :FTP, 'backup/record/ftp'
84
- autoload :SFTP, 'backup/record/sftp'
85
- autoload :Local, 'backup/record/local'
86
- autoload :Dropbox, 'backup/record/dropbox'
108
+ ##
109
+ # Autoload Backup database files
110
+ module Database
111
+ autoload :Base, File.join(DATABASE_PATH, 'base')
112
+ autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
113
+ autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
114
+ autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
115
+ autoload :Redis, File.join(DATABASE_PATH, 'redis')
87
116
  end
88
117
 
89
- class Setup
90
-
91
- attr_accessor :trigger, :procedures, :procedure
92
-
93
- # Sets the Trigger and All Available Procedures.
94
- # Will not find a specific procedure if the "trigger" argument is set to false.
95
- def initialize(trigger, procedures)
96
- self.trigger = trigger
97
- self.procedures = procedures
98
- self.procedure = find_triggered_procedure unless trigger.eql?(false)
99
- end
100
-
101
- # Initializes one of the few adapters and start the backup process
102
- def initialize_adapter
103
- case procedure.adapter_name.to_sym
104
- when :mongo then Backup::Adapters::MongoDB.new trigger, procedure
105
- when :mysql then Backup::Adapters::MySQL.new trigger, procedure
106
- when :sqlite then Backup::Adapters::SQLite.new trigger, procedure
107
- when :postgresql then Backup::Adapters::PostgreSQL.new trigger, procedure
108
- when :archive then Backup::Adapters::Archive.new trigger, procedure
109
- when :custom then Backup::Adapters::Custom.new trigger, procedure
110
- else
111
- puts "Unknown Adapter: \"#{procedure.adapter_name}\"."
112
- exit
113
- end
114
- end
115
-
116
- # Scans through all the backup settings and returns the backup setting
117
- # that was specified in the "trigger" argument.
118
- # If an non-existing trigger is specified, it will raise an error and display
119
- # all the available triggers.
120
- def find_triggered_procedure
121
- procedures.each do |procedure|
122
- if procedure.trigger.eql?(trigger)
123
- return procedure
124
- end
125
- end
126
- available_triggers = procedures.map {|procedure| "- #{procedure.trigger}\n" }
127
- puts "Could not find a backup procedure with the trigger \"#{trigger}\". \nHere's a list of available triggers:\n#{available_triggers}"
128
- exit
129
- end
118
+ ##
119
+ # Autoload compressor files
120
+ module Compressor
121
+ autoload :Base, File.join(COMPRESSOR_PATH, 'base')
122
+ autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
123
+ end
124
+
125
+ ##
126
+ # Autoload encryptor files
127
+ module Encryptor
128
+ autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
129
+ autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
130
+ autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
131
+ end
130
132
 
133
+ ##
134
+ # Autoload notification files
135
+ module Notifier
136
+ autoload :Base, File.join(NOTIFIER_PATH, 'base')
137
+ autoload :Binder, File.join(NOTIFIER_PATH, 'binder')
138
+ autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
131
139
  end
140
+
141
+ ##
142
+ # Dynamically defines all the available database, storage, compressor, encryptor and notifier
143
+ # classes inside Backup::Finder to improve the DSL for the configuration file
144
+ (DATABASES + STORAGES + COMPRESSORS + ENCRYPTORS + NOTIFIERS).each do |constant|
145
+ Backup::Finder.const_set(constant, Class.new)
146
+ end
147
+
132
148
  end