backup 3.0.20 → 3.0.21

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 (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -28,32 +28,57 @@ module Backup
28
28
  # Additional "mysqldump" options
29
29
  attr_accessor :additional_options
30
30
 
31
+ ##
32
+ # Path to mysqldump utility (optional)
33
+ attr_accessor :mysqldump_utility
34
+
31
35
  ##
32
36
  # Creates a new instance of the MySQL adapter object
33
- def initialize(&block)
34
- load_defaults!
37
+ def initialize(model, &block)
38
+ super(model)
35
39
 
36
40
  @skip_tables ||= Array.new
37
41
  @only_tables ||= Array.new
38
42
  @additional_options ||= Array.new
39
43
 
40
- instance_eval(&block)
44
+ instance_eval(&block) if block_given?
45
+
46
+ if @utility_path
47
+ Logger.warn "[DEPRECATED] " +
48
+ "Database::MySQL#utility_path has been deprecated.\n" +
49
+ " Use Database::MySQL#mysqldump_utility instead."
50
+ @mysqldump_utility ||= @utility_path
51
+ end
52
+ @mysqldump_utility ||= utility(:mysqldump)
41
53
  end
42
54
 
43
55
  ##
44
- # Builds the MySQL syntax for specifying which tables to skip
45
- # during the dumping of the database
46
- def tables_to_skip
47
- skip_tables.map do |table|
48
- "--ignore-table='#{name}.#{table}'"
49
- end.join("\s")
56
+ # Performs the mysqldump command and outputs the
57
+ # data to the specified path based on the 'trigger'
58
+ def perform!
59
+ super
60
+
61
+ dump_ext = 'sql'
62
+ dump_cmd = "#{ mysqldump }"
63
+
64
+ if @model.compressor
65
+ @model.compressor.compress_with do |command, ext|
66
+ dump_cmd << " | #{command}"
67
+ dump_ext << ext
68
+ end
69
+ end
70
+
71
+ dump_cmd << " > '#{ File.join(@dump_path, name) }.#{ dump_ext }'"
72
+ run(dump_cmd)
50
73
  end
51
74
 
75
+ private
76
+
52
77
  ##
53
- # Builds the MySQL syntax for specifying which tables to dump
54
- # during the dumping of the database
55
- def tables_to_dump
56
- only_tables.join("\s")
78
+ # Builds the full mysqldump string based on all attributes
79
+ def mysqldump
80
+ "#{ mysqldump_utility } #{ credential_options } #{ connectivity_options } " +
81
+ "#{ user_options } #{ name } #{ tables_to_dump } #{ tables_to_skip }"
57
82
  end
58
83
 
59
84
  ##
@@ -61,9 +86,9 @@ module Backup
61
86
  # to perform the database dumping process
62
87
  def credential_options
63
88
  %w[username password].map do |option|
64
- next if send(option).nil? or send(option).empty?
89
+ next if send(option).to_s.empty?
65
90
  "--#{option}='#{send(option)}'".gsub('--username', '--user')
66
- end.compact.join("\s")
91
+ end.compact.join(' ')
67
92
  end
68
93
 
69
94
  ##
@@ -71,32 +96,32 @@ module Backup
71
96
  # to perform the database dumping process
72
97
  def connectivity_options
73
98
  %w[host port socket].map do |option|
74
- next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?)
99
+ next if send(option).to_s.empty?
75
100
  "--#{option}='#{send(option)}'"
76
- end.compact.join("\s")
101
+ end.compact.join(' ')
77
102
  end
78
103
 
79
104
  ##
80
105
  # Builds a MySQL compatible string for the additional options
81
106
  # specified by the user
82
- def options
83
- additional_options.join("\s")
107
+ def user_options
108
+ additional_options.join(' ')
84
109
  end
85
110
 
86
111
  ##
87
- # Builds the full mysqldump string based on all attributes
88
- def mysqldump
89
- "#{ utility(:mysqldump) } #{ credential_options } #{ connectivity_options } " +
90
- "#{ options } #{ name } #{ tables_to_dump } #{ tables_to_skip }"
112
+ # Builds the MySQL syntax for specifying which tables to dump
113
+ # during the dumping of the database
114
+ def tables_to_dump
115
+ only_tables.join(' ')
91
116
  end
92
117
 
93
118
  ##
94
- # Performs the mysqldump command and outputs the
95
- # data to the specified path based on the 'trigger'
96
- def perform!
97
- super
98
-
99
- run("#{mysqldump} > '#{File.join(dump_path, name)}.sql'")
119
+ # Builds the MySQL syntax for specifying which tables to skip
120
+ # during the dumping of the database
121
+ def tables_to_skip
122
+ skip_tables.map do |table|
123
+ "--ignore-table='#{name}.#{table}'"
124
+ end.join(' ')
100
125
  end
101
126
 
102
127
  end
@@ -28,53 +28,72 @@ module Backup
28
28
  # Additional "pg_dump" options
29
29
  attr_accessor :additional_options
30
30
 
31
+ ##
32
+ # Path to pg_dump utility (optional)
33
+ attr_accessor :pg_dump_utility
34
+
31
35
  ##
32
36
  # Creates a new instance of the PostgreSQL adapter object
33
37
  # Sets the PGPASSWORD environment variable to the password
34
38
  # so it doesn't prompt and hang in the process
35
- def initialize(&block)
36
- load_defaults!
39
+ def initialize(model, &block)
40
+ super(model)
37
41
 
38
42
  @skip_tables ||= Array.new
39
43
  @only_tables ||= Array.new
40
44
  @additional_options ||= Array.new
41
45
 
42
- instance_eval(&block)
43
- ENV['PGPASSWORD'] = password
44
- end
46
+ instance_eval(&block) if block_given?
45
47
 
46
- ##
47
- # Builds the PostgreSQL syntax for specifying which tables to skip
48
- # during the dumping of the database
49
- def tables_to_skip
50
- skip_tables.map do |table|
51
- "--exclude-table='#{table}'"
52
- end.join("\s")
48
+ if @utility_path
49
+ Logger.warn "[DEPRECATED] " +
50
+ "Database::PostgreSQL#utility_path has been deprecated.\n" +
51
+ " Use Database::PostgreSQL#pg_dump_utility instead."
52
+ @pg_dump_utility ||= @utility_path
53
+ end
54
+ @pg_dump_utility ||= utility(:pg_dump)
53
55
  end
54
56
 
55
57
  ##
56
- # Builds the PostgreSQL syntax for specifying which tables to dump
57
- # during the dumping of the database
58
- def tables_to_dump
59
- only_tables.map do |table|
60
- "--table='#{table}'"
61
- end.join("\s")
58
+ # Performs the pgdump command and outputs the
59
+ # data to the specified path based on the 'trigger'
60
+ def perform!
61
+ super
62
+
63
+ dump_ext = 'sql'
64
+ dump_cmd = "#{ pgdump }"
65
+
66
+ if @model.compressor
67
+ @model.compressor.compress_with do |command, ext|
68
+ dump_cmd << " | #{command}"
69
+ dump_ext << ext
70
+ end
71
+ end
72
+
73
+ dump_cmd << " > '#{ File.join(@dump_path, name) }.#{ dump_ext }'"
74
+ run(dump_cmd)
62
75
  end
63
76
 
64
77
  ##
65
- # Builds the credentials PostgreSQL syntax to authenticate the user
66
- # to perform the database dumping process
67
- def username_options
68
- return '' unless username.is_a?(String) and not username.empty?
69
- "--username='#{username}'"
78
+ # Builds the full pgdump string based on all attributes
79
+ def pgdump
80
+ "#{password_options}" +
81
+ "#{ pg_dump_utility } #{ username_options } #{ connectivity_options } " +
82
+ "#{ user_options } #{ tables_to_dump } #{ tables_to_skip } #{ name }"
70
83
  end
71
84
 
72
85
  ##
73
86
  # Builds the password syntax PostgreSQL uses to authenticate the user
74
87
  # to perform database dumping
75
88
  def password_options
76
- return '' unless password.is_a?(String) and not username.empty?
77
- "PGPASSWORD='#{password}'"
89
+ password.to_s.empty? ? '' : "PGPASSWORD='#{password}' "
90
+ end
91
+
92
+ ##
93
+ # Builds the credentials PostgreSQL syntax to authenticate the user
94
+ # to perform the database dumping process
95
+ def username_options
96
+ username.to_s.empty? ? '' : "--username='#{username}'"
78
97
  end
79
98
 
80
99
  ##
@@ -84,35 +103,34 @@ module Backup
84
103
  # both the host and the socket are specified, the socket will take priority over the host
85
104
  def connectivity_options
86
105
  %w[host port socket].map do |option|
87
- next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?)
106
+ next if send(option).to_s.empty?
88
107
  "--#{option}='#{send(option)}'".gsub('--socket=', '--host=')
89
- end.compact.join("\s")
108
+ end.compact.join(' ')
90
109
  end
91
110
 
92
111
  ##
93
112
  # Builds a PostgreSQL compatible string for the additional options
94
113
  # specified by the user
95
- def options
96
- additional_options.join("\s")
114
+ def user_options
115
+ additional_options.join(' ')
97
116
  end
98
117
 
99
118
  ##
100
- # Builds the full pgdump string based on all attributes
101
- def pgdump
102
- ("#{password_options} " +
103
- "#{ utility(:pg_dump) } #{ username_options } #{ connectivity_options } " +
104
- "#{ options } #{ tables_to_dump } #{ tables_to_skip } #{ name }").strip
119
+ # Builds the PostgreSQL syntax for specifying which tables to dump
120
+ # during the dumping of the database
121
+ def tables_to_dump
122
+ only_tables.map do |table|
123
+ "--table='#{table}'"
124
+ end.join(' ')
105
125
  end
106
126
 
107
127
  ##
108
- # Performs the pgdump command and outputs the
109
- # data to the specified path based on the 'trigger'
110
- # and resets the 'PGPASSWORD' environment variable to nil
111
- def perform!
112
- super
113
-
114
- run("#{pgdump} > '#{File.join(dump_path, name)}.sql'")
115
- ENV['PGPASSWORD'] = nil
128
+ # Builds the PostgreSQL syntax for specifying which tables to skip
129
+ # during the dumping of the database
130
+ def tables_to_skip
131
+ skip_tables.map do |table|
132
+ "--exclude-table='#{table}'"
133
+ end.join(' ')
116
134
  end
117
135
 
118
136
  end
@@ -26,43 +26,28 @@ module Backup
26
26
  # Additional "redis-cli" options
27
27
  attr_accessor :additional_options
28
28
 
29
+ ##
30
+ # Path to the redis-cli utility (optional)
31
+ attr_accessor :redis_cli_utility
32
+
29
33
  ##
30
34
  # Creates a new instance of the Redis database object
31
- def initialize(&block)
32
- load_defaults!
35
+ def initialize(model, &block)
36
+ super(model)
33
37
 
34
38
  @additional_options ||= Array.new
35
39
 
36
- instance_eval(&block)
37
- end
38
-
39
- ##
40
- # Builds the Redis credentials syntax to authenticate the user
41
- # to perform the database dumping process
42
- def credential_options
43
- return "-a '#{password}'" if password; String.new
44
- end
45
-
46
- ##
47
- # Builds the Redis connectivity options syntax to connect the user
48
- # to perform the database dumping process
49
- def connectivity_options
50
- %w[host port socket].map do |option|
51
- next if send(option).nil?; "-#{option[0,1]} '#{send(option)}'"
52
- end.compact.join("\s")
53
- end
40
+ instance_eval(&block) if block_given?
54
41
 
55
- ##
56
- # Builds a Redis compatible string for the
57
- # additional options specified by the user
58
- def additional_options
59
- @additional_options.join("\s")
60
- end
42
+ @name ||= 'dump'
61
43
 
62
- ##
63
- # Returns the Redis database file name
64
- def database
65
- "#{ name }.rdb"
44
+ if @utility_path
45
+ Logger.warn "[DEPRECATED] " +
46
+ "Database::Redis#utility_path has been deprecated.\n" +
47
+ " Use Database::Redis#redis_cli_utility instead."
48
+ @redis_cli_utility ||= @utility_path
49
+ end
50
+ @redis_cli_utility ||= utility('redis-cli')
66
51
  end
67
52
 
68
53
  ##
@@ -78,12 +63,14 @@ module Backup
78
63
  copy!
79
64
  end
80
65
 
66
+ private
67
+
81
68
  ##
82
69
  # Tells Redis to persist the current state of the
83
70
  # in-memory database to the persisted dump file
84
71
  def invoke_save!
85
- response = run("#{ utility('redis-cli') } #{ credential_options } " +
86
- "#{ connectivity_options } #{ additional_options } SAVE")
72
+ response = run("#{ redis_cli_utility } #{ credential_options } " +
73
+ "#{ connectivity_options } #{ user_options } SAVE")
87
74
  unless response =~ /OK/
88
75
  raise Errors::Database::Redis::CommandError, <<-EOS
89
76
  Could not invoke the Redis SAVE command.
@@ -99,19 +86,54 @@ module Backup
99
86
  ##
100
87
  # Performs the copy command to copy over the Redis dump file to the Backup archive
101
88
  def copy!
102
- unless File.exist?(File.join(path, database))
89
+ src_path = File.join(path, database)
90
+ unless File.exist?(src_path)
103
91
  raise Errors::Database::Redis::NotFoundError, <<-EOS
104
92
  Redis database dump not found
105
- File path was #{ File.join(path, database) }
93
+ File path was #{ src_path }
106
94
  EOS
107
95
  end
108
96
 
109
- # Temporarily remove a custom `utility_path` setting so that the system
110
- # `cp` utility can be found, then restore the old value just in case.
111
- old_path, self.utility_path = self.utility_path, nil
112
- run("#{ utility(:cp) } '#{ File.join(path, database) }' '#{ File.join(dump_path, database) }'")
113
- self.utility_path = old_path
97
+ dst_path = File.join(@dump_path, database)
98
+ if @model.compressor
99
+ @model.compressor.compress_with do |command, ext|
100
+ run("#{ command } -c #{ src_path } > #{ dst_path + ext }")
101
+ end
102
+ else
103
+ FileUtils.cp(src_path, dst_path)
104
+ end
105
+ end
106
+
107
+ ##
108
+ # Returns the Redis database file name
109
+ def database
110
+ "#{ name }.rdb"
111
+ end
112
+
113
+ ##
114
+ # Builds the Redis credentials syntax to authenticate the user
115
+ # to perform the database dumping process
116
+ def credential_options
117
+ password.to_s.empty? ? '' : "-a '#{password}'"
114
118
  end
119
+
120
+ ##
121
+ # Builds the Redis connectivity options syntax to connect the user
122
+ # to perform the database dumping process
123
+ def connectivity_options
124
+ %w[host port socket].map do |option|
125
+ next if send(option).to_s.empty?
126
+ "-#{option[0,1]} '#{send(option)}'"
127
+ end.compact.join(' ')
128
+ end
129
+
130
+ ##
131
+ # Builds a Redis compatible string for the
132
+ # additional options specified by the user
133
+ def user_options
134
+ @additional_options.join(' ')
135
+ end
136
+
115
137
  end
116
138
  end
117
139
  end
@@ -16,18 +16,24 @@ module Backup
16
16
  # Cookie is the Erlang cookie/shared secret used to connect to the node.
17
17
  attr_accessor :cookie
18
18
 
19
+ ##
20
+ # Path to riak-admin utility (optional)
21
+ attr_accessor :riak_admin_utility
22
+
19
23
  ##
20
24
  # Creates a new instance of the Riak adapter object
21
- def initialize(&block)
22
- load_defaults!
25
+ def initialize(model, &block)
26
+ super(model)
23
27
 
24
- instance_eval(&block)
25
- end
28
+ instance_eval(&block) if block_given?
26
29
 
27
- ##
28
- # Builds the full riak-admin string based on all attributes
29
- def riakadmin
30
- "riak-admin backup #{node} #{cookie}"
30
+ if @utility_path
31
+ Logger.warn "[DEPRECATED] " +
32
+ "Database::Riak#utility_path has been deprecated.\n" +
33
+ " Use Database::Riak#riak_admin_utility instead."
34
+ @riak_admin_utility ||= @utility_path
35
+ end
36
+ @riak_admin_utility ||= utility('riak-admin')
31
37
  end
32
38
 
33
39
  ##
@@ -35,9 +41,27 @@ module Backup
35
41
  # data to the specified path based on the 'trigger'
36
42
  def perform!
37
43
  super
38
- # have to make riak the owner since the riak-admin tool runs as the riak user in a default setup.
39
- run("chown -R riak.riak #{dump_path}")
40
- run("#{riakadmin} #{File.join(dump_path, name)} node")
44
+ # have to make riak the owner since the riak-admin tool runs
45
+ # as the riak user in a default setup.
46
+ FileUtils.chown_R('riak', 'riak', @dump_path)
47
+
48
+ backup_file = File.join(@dump_path, name)
49
+ run("#{ riakadmin } #{ backup_file } node")
50
+
51
+ if @model.compressor
52
+ @model.compressor.compress_with do |command, ext|
53
+ run("#{ command } -c #{ backup_file } > #{ backup_file + ext }")
54
+ FileUtils.rm_f(backup_file)
55
+ end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ ##
62
+ # Builds the full riak-admin string based on all attributes
63
+ def riakadmin
64
+ "#{ riak_admin_utility } backup #{ node } #{ cookie }"
41
65
  end
42
66
 
43
67
  end