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
@@ -1,60 +0,0 @@
1
- module Backup
2
- module Adapters
3
- class PostgreSQL < Backup::Adapters::Base
4
-
5
- attr_accessor :user, :password, :database, :skip_tables, :host, :port, :socket, :additional_options, :su_as_user
6
-
7
- private
8
-
9
- # Dumps and Compresses the PostgreSQL file
10
- def perform
11
- log system_messages[:pgdump]; log system_messages[:compressing]
12
- ENV['PGPASSWORD'] = password
13
- if su_as_user
14
- run "su #{su_as_user} -c \"#{pg_dump} -U #{user} #{options} #{additional_options} #{tables_to_skip} #{database} | gzip -f --best > #{File.join(tmp_path, compressed_file)}\""
15
- else
16
- run "#{pg_dump} -U #{user} #{options} #{additional_options} #{tables_to_skip} #{database} | gzip -f --best > #{File.join(tmp_path, compressed_file)}"
17
- end
18
- ENV['PGPASSWORD'] = nil
19
- end
20
-
21
- def pg_dump
22
- # try to determine the full path, and fall back to pg_dump if not found
23
- cmd = `which pg_dump`.chomp
24
- cmd = 'pg_dump' if cmd.empty?
25
- cmd
26
- end
27
-
28
- def performed_file_extension
29
- ".sql"
30
- end
31
-
32
- # Loads the initial settings
33
- def load_settings
34
- %w(user password database skip_tables additional_options su_as_user).each do |attribute|
35
- send(:"#{attribute}=", procedure.get_adapter_configuration.attributes[attribute])
36
- end
37
-
38
- %w(host port socket).each do |attribute|
39
- send(:"#{attribute}=", procedure.get_adapter_configuration.get_options.attributes[attribute])
40
- end
41
- end
42
-
43
- # Returns a list of options in PostgreSQL syntax
44
- def options
45
- options = String.new
46
- options += " --port='#{port}' " unless port.blank?
47
- options += " --host='#{host}' " unless host.blank?
48
- options += " --host='#{socket}' " unless socket.blank? unless options.include?('--host=')
49
- options
50
- end
51
-
52
- # Returns a list of tables to skip in PostgreSQL syntax
53
- def tables_to_skip
54
- return "" unless skip_tables
55
- [*skip_tables].map {|table| " -T \"#{table}\" "}
56
- end
57
-
58
- end
59
- end
60
- end
@@ -1,25 +0,0 @@
1
- module Backup
2
- module Adapters
3
- class SQLite < Base
4
-
5
- attr_accessor :database
6
-
7
- private
8
-
9
- # Compress the sqlite file
10
- def perform
11
- log system_messages[:sqlite]
12
- run "gzip -c --best #{database} > #{File.join(tmp_path, compressed_file)}"
13
- end
14
-
15
- def load_settings
16
- self.database = procedure.get_adapter_configuration.attributes['database']
17
- end
18
-
19
- def performed_file_extension
20
- ""
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,14 +0,0 @@
1
- module Backup
2
- module CommandHelper
3
- def run(command, opts={})
4
- opts[:exit_on_failure] ||= false
5
- output = `#{command}`
6
- exit 1 if opts[:exit_on_failure] && !$?.success?
7
- output
8
- end
9
-
10
- def log(command)
11
- puts "Backup (#{Time.now.strftime("%Y-%m-%d %H:%M:%S %Z")}) => #{command}"
12
- end
13
- end
14
- end
@@ -1,21 +0,0 @@
1
- module Backup
2
- module Configuration
3
- class Adapter
4
- extend Backup::Configuration::Attributes
5
- generate_attributes %w(files exclude user password database tables skip_tables commands additional_options backup_method)
6
-
7
- def initialize
8
- @options = Backup::Configuration::AdapterOptions.new
9
- end
10
-
11
- def options(&block)
12
- @options.instance_eval &block
13
- end
14
-
15
- def get_options
16
- @options
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,8 +0,0 @@
1
- module Backup
2
- module Configuration
3
- class AdapterOptions
4
- extend Backup::Configuration::Attributes
5
- generate_attributes %w(host port socket)
6
- end
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- module Backup
2
- module Configuration
3
- module Attributes
4
-
5
- def generate_attributes(*attrs)
6
- define_method :attributes do
7
- @attributes ||= {}
8
- end
9
-
10
- attrs.flatten.each do |att|
11
- define_method att do |value|
12
- self.attributes[att.to_s] = value
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
-
@@ -1,20 +0,0 @@
1
- module Backup
2
- module Configuration
3
- class Mail
4
- extend Backup::Configuration::Attributes
5
- generate_attributes %w(from to smtp)
6
-
7
- def initialize
8
- @smtp_configuration = Backup::Configuration::SMTP.new
9
- end
10
-
11
- def smtp(&block)
12
- @smtp_configuration.instance_eval &block
13
- end
14
-
15
- def get_smtp_configuration
16
- @smtp_configuration
17
- end
18
- end
19
- end
20
- end
@@ -1,8 +0,0 @@
1
- module Backup
2
- module Configuration
3
- class SMTP
4
- extend Backup::Configuration::Attributes
5
- generate_attributes %w(host port username password authentication domain tls)
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Backup
2
- module Configuration
3
- class Storage
4
- extend Backup::Configuration::Attributes
5
- generate_attributes %w(ip user password path access_key_id secret_access_key host use_ssl bucket username api_key container)
6
- end
7
- end
8
- end
@@ -1,75 +0,0 @@
1
- require 'cloudfiles'
2
-
3
- module Backup
4
- module Connection
5
- class CloudFiles
6
-
7
- attr_accessor :adapter, :procedure, :api_key, :username, :cf_container, :final_file, :tmp_path
8
-
9
- # Initializes the Cloud Files connection, setting the values using the
10
- # Cloud Files adapter
11
- def initialize(adapter = false)
12
- if adapter
13
- self.adapter = adapter
14
- self.procedure = adapter.procedure
15
- self.final_file = adapter.final_file
16
- self.tmp_path = adapter.tmp_path.gsub('\ ', ' ')
17
- load_storage_configuration_attributes
18
- end
19
- end
20
-
21
- # Sets values from a procedure, rather than from the adapter object
22
- def static_initialize(procedure)
23
- self.procedure = procedure
24
- load_storage_configuration_attributes(true)
25
- end
26
-
27
- # Establishes a connection with Rackspace Cloud Files using the
28
- # credentials provided by the user
29
- def connect
30
- connection
31
- end
32
-
33
- # Wrapper for the Connection object
34
- def connection
35
- ::CloudFiles::Connection.new(username, api_key)
36
- end
37
-
38
- # Wrapper for the Container object
39
- def container
40
- connection.container(cf_container)
41
- end
42
-
43
- # Initializes the file transfer to Rackspace Cloud Files
44
- # This can only run after a connection has been made using the #connect method
45
- def store
46
- object = container.create_object(final_file)
47
- object.write(open(File.join(tmp_path, final_file)))
48
- end
49
-
50
- # Destroys file from a bucket on Amazon S3
51
- def destroy(file, c)
52
- c = connection.container(c)
53
- c.delete_object(file)
54
- end
55
-
56
- private
57
-
58
- def load_storage_configuration_attributes(static = false)
59
- %w(api_key username).each do |attribute|
60
- if static
61
- send("#{attribute}=", procedure.get_storage_configuration.attributes[attribute])
62
- else
63
- send("#{attribute}=", adapter.procedure.get_storage_configuration.attributes[attribute])
64
- end
65
- end
66
-
67
- if static
68
- self.cf_container = procedure.get_storage_configuration.attributes['container']
69
- else
70
- self.cf_container = adapter.procedure.get_storage_configuration.attributes['container']
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,63 +0,0 @@
1
- require 'dropbox'
2
-
3
- module Backup
4
- module Connection
5
- class Dropbox
6
-
7
- attr_accessor :adapter, :procedure, :final_file, :tmp_path, :api_key, :secret_access_key, :username, :password, :path
8
-
9
- def initialize(adapter=false)
10
- if adapter
11
- self.adapter = adapter
12
- self.procedure = adapter.procedure
13
- self.final_file = adapter.final_file
14
- self.tmp_path = adapter.tmp_path.gsub('\ ', ' ')
15
-
16
- load_storage_configuration_attributes
17
- end
18
- end
19
-
20
- def static_initialize(procedure)
21
- self.procedure = procedure
22
- load_storage_configuration_attributes(true)
23
- end
24
-
25
- def session
26
- @session ||= ::Dropbox::Session.new(api_key, secret_access_key)
27
- unless @session.authorized?
28
- @session.authorizing_user = username
29
- @session.authorizing_password = password
30
- @session.authorize!
31
- end
32
-
33
- @session
34
- end
35
-
36
- def connect
37
- session
38
- end
39
-
40
- def path
41
- @path || "backups"
42
- end
43
-
44
- def store
45
- path_to_file = File.join(tmp_path, final_file)
46
- session.upload(path_to_file, path, :mode => :dropbox, :timeout => 360)
47
- end
48
-
49
- private
50
-
51
- def load_storage_configuration_attributes(static=false)
52
- %w(api_key secret_access_key username password path).each do |attribute|
53
- if static
54
- send("#{attribute}=", procedure.get_storage_configuration.attributes[attribute])
55
- else
56
- send("#{attribute}=", adapter.procedure.get_storage_configuration.attributes[attribute])
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
-
@@ -1,88 +0,0 @@
1
- require "fog"
2
-
3
- module Backup
4
- module Connection
5
- class S3
6
- include Backup::CommandHelper
7
-
8
- MAX_S3_FILE_SIZE = 5368709120 - 1
9
-
10
- attr_accessor :adapter, :procedure, :access_key_id, :secret_access_key, :host, :s3_bucket, :use_ssl, :final_file, :tmp_path
11
-
12
- # Initializes the S3 connection, setting the values using the S3 adapter
13
- def initialize(adapter = false)
14
- if adapter
15
- self.adapter = adapter
16
- self.procedure = adapter.procedure
17
- self.final_file = adapter.final_file
18
- self.tmp_path = adapter.tmp_path.gsub('\ ', ' ')
19
- load_storage_configuration_attributes
20
- end
21
- end
22
-
23
- # Sets values from a procedure, rather than from the adapter object
24
- def static_initialize(procedure)
25
- self.procedure = procedure
26
- load_storage_configuration_attributes(true)
27
- end
28
-
29
- # Establishes a connection with Amazon S3 using the credentials provided by the user
30
- def connection
31
- @_connection ||= Fog::AWS::Storage.new(
32
- :aws_access_key_id => access_key_id,
33
- :aws_secret_access_key => secret_access_key
34
- )
35
- end
36
-
37
- # Initializes the file transfer to Amazon S3
38
- # This can only run after a connection has been made using the #connect method
39
- def store
40
- #TODO: need to add logic like this to restore: `cat /mnt/backups/part.xx >>restore.tgz`
41
- tmp_file_path = File.join(tmp_path, final_file)
42
- store_files = []
43
- if File.stat(File.join(tmp_path, final_file)).size >= MAX_S3_FILE_SIZE
44
- #we need to split!
45
- `split -b #{MAX_S3_FILE_SIZE} #{tmp_file_path} #{tmp_file_path}.`
46
- store_files += `ls #{tmp_file_path}.*`.split
47
- log("Splitting '#{final_file}' into #{store_files.length} parts as it is too large for s3.")
48
- else
49
- store_files << tmp_file_path
50
- end
51
-
52
- #lets make sure it exists
53
- self.connection.put_bucket(s3_bucket)
54
-
55
- store_files.each do |tmp_file|
56
- file_name = File.basename(tmp_file)
57
- log("Saving '#{file_name}' to s3 bucket '#{s3_bucket}'")
58
- self.connection.put_object(s3_bucket, file_name, open(tmp_file))
59
- end
60
- end
61
-
62
- # Destroys file from a bucket on Amazon S3
63
- def destroy(file, bucket_as_string)
64
- self.connection.put_bucket(s3_bucket)
65
- connection.delete_object(s3_bucket, file)
66
- end
67
-
68
- private
69
-
70
- def load_storage_configuration_attributes(static = false)
71
- %w(access_key_id secret_access_key use_ssl host).each do |attribute|
72
- if static
73
- send("#{attribute}=", procedure.get_storage_configuration.attributes[attribute])
74
- else
75
- send("#{attribute}=", adapter.procedure.get_storage_configuration.attributes[attribute])
76
- end
77
- end
78
-
79
- if static
80
- self.s3_bucket = procedure.get_storage_configuration.attributes['bucket']
81
- else
82
- self.s3_bucket = adapter.procedure.get_storage_configuration.attributes['bucket']
83
- end
84
- end
85
-
86
- end
87
- end
88
- end
@@ -1,5 +0,0 @@
1
- class Object
2
- def blank?
3
- respond_to?(:empty?) ? empty? : !self
4
- end unless method_defined? :blank?
5
- end
@@ -1,12 +0,0 @@
1
- module Backup
2
- module Environment
3
- module Base
4
-
5
- def current_environment
6
- return :rails if defined?(Rails.root)
7
- return :unix
8
- end
9
-
10
- end
11
- end
12
- end