chef_backup 0.0.1.dev.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/lib/chef_backup.rb +8 -8
  3. data/lib/chef_backup/config.rb +22 -12
  4. data/lib/chef_backup/data_map.rb +23 -9
  5. data/lib/chef_backup/deep_merge.rb +145 -0
  6. data/lib/chef_backup/helpers.rb +169 -27
  7. data/lib/chef_backup/logger.rb +2 -2
  8. data/lib/chef_backup/mash.rb +226 -0
  9. data/lib/chef_backup/runner.rb +19 -14
  10. data/lib/chef_backup/strategy.rb +10 -10
  11. data/lib/chef_backup/strategy/backup/custom.rb +1 -2
  12. data/lib/chef_backup/strategy/backup/ebs.rb +3 -6
  13. data/lib/chef_backup/strategy/backup/lvm.rb +2 -4
  14. data/lib/chef_backup/strategy/backup/object.rb +2 -4
  15. data/lib/chef_backup/strategy/backup/tar.rb +116 -35
  16. data/lib/chef_backup/strategy/restore/tar.rb +103 -38
  17. data/lib/chef_backup/version.rb +1 -1
  18. metadata +22 -170
  19. data/.gitignore +0 -23
  20. data/.kitchen.yml +0 -30
  21. data/.rubocop.yml +0 -17
  22. data/.travis.yml +0 -6
  23. data/Gemfile +0 -4
  24. data/Guardfile +0 -22
  25. data/README.md +0 -21
  26. data/Rakefile +0 -44
  27. data/chef_backup.gemspec +0 -33
  28. data/spec/fixtures/chef-server-running.json +0 -584
  29. data/spec/spec_helper.rb +0 -103
  30. data/spec/unit/data_map_spec.rb +0 -59
  31. data/spec/unit/helpers_spec.rb +0 -88
  32. data/spec/unit/runner_spec.rb +0 -185
  33. data/spec/unit/shared_examples/helpers.rb +0 -20
  34. data/spec/unit/strategy/backup/lvm_spec.rb +0 -0
  35. data/spec/unit/strategy/backup/shared_examples/backup.rb +0 -74
  36. data/spec/unit/strategy/backup/tar_spec.rb +0 -294
  37. data/spec/unit/strategy/restore/lvm_spec.rb +0 -0
  38. data/spec/unit/strategy/restore/shared_examples/restore.rb +0 -84
  39. data/spec/unit/strategy/restore/tar_spec.rb +0 -238
  40. data/spec/unit/strategy_spec.rb +0 -36
@@ -1,7 +1,7 @@
1
- require 'fileutils'
2
- require 'pathname'
3
- require 'forwardable'
4
- require 'chef/mixin/deep_merge'
1
+ require "fileutils"
2
+ require "pathname"
3
+ require "forwardable"
4
+ require "chef_backup/deep_merge"
5
5
 
6
6
  # rubocop:disable IndentationWidth
7
7
  module ChefBackup
@@ -11,87 +11,98 @@ class TarRestore
11
11
  # rubocop:enable IndentationWidth
12
12
  include ChefBackup::Helpers
13
13
  include ChefBackup::Exceptions
14
- include Chef::Mixin::DeepMerge
14
+ include ChefBackup::Mixin::DeepMerge
15
15
  extend Forwardable
16
16
 
17
17
  attr_accessor :tarball_path
18
+ attr_writer :manifest
18
19
 
19
20
  def_delegators :@log, :log
20
21
 
21
22
  def initialize(path)
22
23
  @tarball_path = path
23
- @log = ChefBackup::Logger.logger(private_chef['backup']['logfile'] || nil)
24
+ @log = ChefBackup::Logger.logger(service_config["backup"]["logfile"] || nil)
24
25
  end
25
26
 
26
27
  def restore
27
- log 'Restoring Chef Server from backup'
28
- cleanse_chef_server(config['agree_to_cleanse'])
28
+ log "Restoring Chef Server from backup"
29
+ return unless check_manifest_version
30
+
31
+ cleanse_chef_server(config["agree_to_cleanse"])
32
+ if ha?
33
+ log "Performing HA restore - please ensure that keepalived is not running on the standby host"
34
+ fix_ha_plugins
35
+ check_ha_volume
36
+ touch_drbd_ready
37
+ end
29
38
  restore_configs
30
39
  restore_services unless frontend?
31
40
  touch_sentinel
41
+ reconfigure_marketplace if marketplace?
32
42
  reconfigure_server
33
43
  update_config
34
44
  import_db if restore_db_dump?
35
45
  start_chef_server
46
+ reconfigure_add_ons
47
+ restart_add_ons
36
48
  cleanup
37
- log 'Restoration Completed!'
49
+ log "Restoration Completed!"
38
50
  end
39
51
 
40
52
  def manifest
41
53
  @manifest ||= begin
42
- manifest = File.expand_path(File.join(ChefBackup::Config['restore_dir'],
43
- 'manifest.json'))
54
+ manifest = File.expand_path(File.join(ChefBackup::Config["restore_dir"],
55
+ "manifest.json"))
44
56
  ensure_file!(manifest, InvalidManifest, "#{manifest} not found")
45
57
  JSON.parse(File.read(manifest))
46
58
  end
47
59
  end
48
60
 
49
61
  def restore_db_dump?
50
- manifest['services']['postgresql']['pg_dump_success'] && !frontend?
62
+ manifest["services"]["postgresql"]["pg_dump_success"] && !frontend?
51
63
  rescue NoMethodError
52
64
  false
53
65
  end
54
66
 
55
67
  def import_db
56
- start_service('postgresql')
57
- sql_file = File.join(ChefBackup::Config['restore_dir'],
58
- "chef_backup-#{manifest['backup_time']}.sql")
68
+ start_service("postgresql")
69
+ sql_file = File.join(ChefBackup::Config["restore_dir"],
70
+ "chef_backup-#{manifest["backup_time"]}.sql")
59
71
  ensure_file!(sql_file, InvalidDatabaseDump, "#{sql_file} not found")
60
72
 
61
- cmd = ['/opt/opscode/embedded/bin/chpst',
62
- "-u #{manifest['services']['postgresql']['username']}",
63
- '/opt/opscode/embedded/bin/psql',
64
- "-U #{manifest['services']['postgresql']['username']}",
65
- '-d opscode_chef',
66
- "< #{sql_file}"
67
- ].join(' ')
68
- log 'Importing Database dump'
69
- shell_out!(cmd)
73
+ cmd = [chpst,
74
+ "-u #{manifest["services"]["postgresql"]["username"]}",
75
+ pgsql,
76
+ "-U #{manifest["services"]["postgresql"]["username"]}",
77
+ "-d #{database_name}",
78
+ "< #{sql_file}"].join(" ")
79
+ log "Importing Database dump"
80
+ shell_out!(cmd, env: ["PGOPTIONS=#{pg_options}"])
70
81
  end
71
82
 
72
83
  def restore_services
73
- manifest.key?('services') && manifest['services'].keys.each do |service|
84
+ manifest.key?("services") && manifest["services"].keys.each do |service|
74
85
  restore_data(:services, service)
75
86
  end
76
87
  end
77
88
 
78
89
  def restore_configs
79
- manifest.key?('configs') && manifest['configs'].keys.each do |config|
90
+ manifest.key?("configs") && manifest["configs"].keys.each do |config|
80
91
  restore_data(:configs, config)
81
92
  end
82
93
  end
83
94
 
84
95
  def touch_sentinel
85
- dir = '/var/opt/opscode'
86
- sentinel = File.join(dir, 'bootstrapped')
96
+ dir = "/var/opt/opscode"
97
+ sentinel = File.join(dir, "bootstrapped")
87
98
  FileUtils.mkdir_p(dir) unless File.directory?(dir)
88
- File.open(sentinel, 'w') { |file| file.write 'bootstrapped!' }
99
+ File.open(sentinel, "w") { |file| file.write "bootstrapped!" }
89
100
  end
90
101
 
91
102
  def restore_data(type, name)
92
- source = File.expand_path(File.join(config['restore_dir'],
93
- manifest[type.to_s][name]['data_dir']))
94
- destination = manifest[type.to_s][name]['data_dir']
103
+ source = File.expand_path(File.join(config["restore_dir"],
104
+ manifest[type.to_s][name]["data_dir"]))
105
+ destination = manifest[type.to_s][name]["data_dir"]
95
106
  FileUtils.mkdir_p(destination) unless File.directory?(destination)
96
107
  cmd = "rsync -chaz --delete #{source}/ #{destination}"
97
108
  log "Restoring the #{name} data"
@@ -99,22 +110,76 @@ class TarRestore
99
110
  end
100
111
 
101
112
  def backup_name
102
- @backup_name ||= Pathname.new(tarball_path).basename.sub_ext('').to_s
113
+ @backup_name ||= Pathname.new(tarball_path).basename.sub_ext("").to_s
114
+ end
115
+
116
+ def check_manifest_version
117
+ unless manifest["versions"]
118
+ log "no version information in manifest"
119
+ return true
120
+ end
121
+
122
+ manifest["versions"].each_pair do |name, data|
123
+ installed = version_from_manifest_file(data["path"])
124
+
125
+ if installed == :no_version
126
+ log "Warning: #{name} @ #{data["version"]} not installed"
127
+ elsif installed["version"] != data["version"]
128
+ log "package #{name} #{installed["version"]} installed, but backup was"\
129
+ " from #{data["version"]}. Please install correct version, restore, then upgrade."
130
+ return false
131
+ end
132
+ end
133
+ true
134
+ end
135
+
136
+ def fix_ha_plugins
137
+ log "Fixing HA plugins directory (https://github.com/chef/chef-server/issues/115)"
138
+ plugins_dir = "/var/opt/opscode/plugins"
139
+ drbd_plugin = File.join(plugins_dir, "chef-ha-drbd.rb")
140
+
141
+ FileUtils.mkdir_p(plugins_dir) unless Dir.exist?(plugins_dir)
142
+ FileUtils.ln_sf("/opt/opscode/chef-server-plugin.rb", drbd_plugin) unless
143
+ File.exist?(drbd_plugin)
144
+ end
145
+
146
+ def check_ha_volume
147
+ log "Checking that the HA storage volume is mounted"
148
+ ha_data_dir = manifest["ha"]["path"]
149
+
150
+ unless ha_data_dir_mounted?(ha_data_dir)
151
+ raise "Please mount the data directory #{ha_data_dir} and perform any DRBD configuration before continuing"
152
+ end
153
+ end
154
+
155
+ def ha_data_dir_mounted?(ha_data_dir)
156
+ File.read("/proc/mounts").split("\n").grep(/#{ha_data_dir}/).count > 0
157
+ end
158
+
159
+ def touch_drbd_ready
160
+ log "Touching drbd_ready file"
161
+ FileUtils.touch("/var/opt/opscode/drbd/drbd_ready") unless
162
+ File.exist?("/var/opt/opscode/drbd/drbd_ready")
103
163
  end
104
164
 
105
165
  def reconfigure_server
106
- log 'Reconfiguring the Chef Server'
107
- shell_out('chef-server-ctl reconfigure')
166
+ log "Reconfiguring the Chef Server"
167
+ shell_out("#{ctl_command} reconfigure")
108
168
  end
109
169
 
110
170
  def cleanse_chef_server(agree)
111
- log 'Cleaning up any old files'
112
- shell_out!("chef-server-ctl cleanse #{agree || ''}")
171
+ log "Cleaning up any old files"
172
+ # The chef-server-ctl cleanse command deliberately waits 60 seconds to give
173
+ # you an option to cancel it. Therefore, don't count it in the timeout that
174
+ # the user provided. If the user has eagerly dismissed that wait period,
175
+ # then don't elongate the timeout. The user can do this with the -c flag.
176
+ timeout = shell_timeout + (agree ? 0 : 60) if shell_timeout
177
+ shell_out!("#{ctl_command} cleanse #{agree || ""}", "timeout" => timeout)
113
178
  end
114
179
 
115
180
  def running_config
116
181
  @running_config ||=
117
- JSON.parse(File.read('/etc/opscode/chef-server-running.json')) || {}
182
+ JSON.parse(File.read(running_filepath)) || {}
118
183
  end
119
184
 
120
185
  def update_config
@@ -1,4 +1,4 @@
1
1
  # ChefBackup module
2
2
  module ChefBackup
3
- VERSION = '0.0.1.dev.2'
3
+ VERSION = "0.1.1".freeze
4
4
  end
metadata CHANGED
@@ -1,192 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.dev.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Ryan Cragun
7
+ - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2019-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: di-ruby-lvm
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: mixlib-shellout
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
19
+ version: '2.0'
20
+ - - "<"
39
21
  - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: highline
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
22
+ version: '4.0'
48
23
  type: :runtime
49
24
  prerelease: false
50
25
  version_requirements: !ruby/object:Gem::Requirement
51
26
  requirements:
52
27
  - - ">="
53
28
  - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: chef
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
29
+ version: '2.0'
30
+ - - "<"
67
31
  - !ruby/object:Gem::Version
68
- version: '0'
32
+ version: '4.0'
69
33
  - !ruby/object:Gem::Dependency
70
- name: bundler
34
+ name: highline
71
35
  requirement: !ruby/object:Gem::Requirement
72
36
  requirements:
73
37
  - - "~>"
74
38
  - !ruby/object:Gem::Version
75
39
  version: '1.6'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.6'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
40
  - - ">="
95
41
  - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.0'
104
- type: :development
42
+ version: 1.6.9
43
+ type: :runtime
105
44
  prerelease: false
106
45
  version_requirements: !ruby/object:Gem::Requirement
107
46
  requirements:
108
47
  - - "~>"
109
48
  - !ruby/object:Gem::Version
110
- version: '3.0'
111
- - !ruby/object:Gem::Dependency
112
- name: guard-rspec
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: pry-rescue
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - '='
144
- - !ruby/object:Gem::Version
145
- version: '0.28'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - '='
151
- - !ruby/object:Gem::Version
152
- version: '0.28'
153
- - !ruby/object:Gem::Dependency
154
- name: simplecov
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
49
+ version: '1.6'
164
50
  - - ">="
165
51
  - !ruby/object:Gem::Version
166
- version: '0'
52
+ version: 1.6.9
167
53
  description: A library to backup a Chef Server
168
54
  email:
169
- - me@ryan.ec
55
+ - oss@chef.io
170
56
  executables: []
171
57
  extensions: []
172
58
  extra_rdoc_files: []
173
59
  files:
174
- - ".gitignore"
175
- - ".kitchen.yml"
176
- - ".rubocop.yml"
177
- - ".travis.yml"
178
- - Gemfile
179
- - Guardfile
180
60
  - LICENSE
181
- - README.md
182
- - Rakefile
183
- - chef_backup.gemspec
184
61
  - lib/chef_backup.rb
185
62
  - lib/chef_backup/config.rb
186
63
  - lib/chef_backup/data_map.rb
64
+ - lib/chef_backup/deep_merge.rb
187
65
  - lib/chef_backup/exceptions.rb
188
66
  - lib/chef_backup/helpers.rb
189
67
  - lib/chef_backup/logger.rb
68
+ - lib/chef_backup/mash.rb
190
69
  - lib/chef_backup/runner.rb
191
70
  - lib/chef_backup/strategy.rb
192
71
  - lib/chef_backup/strategy/backup/custom.rb
@@ -200,22 +79,9 @@ files:
200
79
  - lib/chef_backup/strategy/restore/object.rb
201
80
  - lib/chef_backup/strategy/restore/tar.rb
202
81
  - lib/chef_backup/version.rb
203
- - spec/fixtures/chef-server-running.json
204
- - spec/spec_helper.rb
205
- - spec/unit/data_map_spec.rb
206
- - spec/unit/helpers_spec.rb
207
- - spec/unit/runner_spec.rb
208
- - spec/unit/shared_examples/helpers.rb
209
- - spec/unit/strategy/backup/lvm_spec.rb
210
- - spec/unit/strategy/backup/shared_examples/backup.rb
211
- - spec/unit/strategy/backup/tar_spec.rb
212
- - spec/unit/strategy/restore/lvm_spec.rb
213
- - spec/unit/strategy/restore/shared_examples/restore.rb
214
- - spec/unit/strategy/restore/tar_spec.rb
215
- - spec/unit/strategy_spec.rb
216
82
  homepage: https://github.com/chef/chef_backup
217
83
  licenses:
218
- - Apachev2
84
+ - Apache-2.0
219
85
  metadata: {}
220
86
  post_install_message:
221
87
  rdoc_options: []
@@ -228,26 +94,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
94
  version: '0'
229
95
  required_rubygems_version: !ruby/object:Gem::Requirement
230
96
  requirements:
231
- - - ">"
97
+ - - ">="
232
98
  - !ruby/object:Gem::Version
233
- version: 1.3.1
99
+ version: '0'
234
100
  requirements: []
235
- rubyforge_project:
236
- rubygems_version: 2.2.2
101
+ rubygems_version: 3.0.3
237
102
  signing_key:
238
103
  specification_version: 4
239
104
  summary: A library to backup a Chef Server
240
- test_files:
241
- - spec/fixtures/chef-server-running.json
242
- - spec/spec_helper.rb
243
- - spec/unit/data_map_spec.rb
244
- - spec/unit/helpers_spec.rb
245
- - spec/unit/runner_spec.rb
246
- - spec/unit/shared_examples/helpers.rb
247
- - spec/unit/strategy/backup/lvm_spec.rb
248
- - spec/unit/strategy/backup/shared_examples/backup.rb
249
- - spec/unit/strategy/backup/tar_spec.rb
250
- - spec/unit/strategy/restore/lvm_spec.rb
251
- - spec/unit/strategy/restore/shared_examples/restore.rb
252
- - spec/unit/strategy/restore/tar_spec.rb
253
- - spec/unit/strategy_spec.rb
105
+ test_files: []