knife-backup 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 918be2fa6d1491b4927ecf0da398fbe091996932
4
- data.tar.gz: d5020e9bee1536d0972bcaa54237705d4d352c72
3
+ metadata.gz: e3b74fdf9a67ae00a32a68e1b37201dd7d27e318
4
+ data.tar.gz: 0cfa2a717cc5223e068424beab952813c250805a
5
5
  SHA512:
6
- metadata.gz: 85dad02bd0ec4235da0f74814a1397083aaca2c63647862c7c1610e77908208e52998c5694d9488b9ae5b55c709a52565805833b9786c3f65d19f4ab10d19474
7
- data.tar.gz: f15c5518f7844177800a3dc27b0c7e377ec06df850a969da78391dce7b4d557f3077294b456ddd483283020b0af45ae06901f7596737ca56150dc78d523db148
6
+ metadata.gz: 766023ac2102bc799dd8eb27af1bf53b3175ecb601007722411ca2ff88609c463ea390adf0f2df22a89e262e88699fc1e7ac9a99824a1e83ccadee8811548ef9
7
+ data.tar.gz: 2bd111ebe9cb9a58526293976d30a33ad92ca915ae69c7adbd164d9bb085fa49e13876945dafbbcbd4f406983263345cfd05a72585d0135396e4a31832dc2ae7
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
+ .chef
3
4
  Gemfile.lock
4
5
  pkg/*
6
+ bin/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in knife-backup.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -4,7 +4,7 @@ Knife-Backup
4
4
  Knife-Backup is a [Knife](http://wiki.opscode.com/display/chef/Knife) plugin that can help you backup and restore a chef server. It is based on the great work of [Steven Danna][stevendanna] and [Joshua Timberman][jtimberman] on the [BackupExport][backup_export] and [BackupRestore][backup_restore] plugins. Currently knife-backup has support for the following objects:
5
5
 
6
6
  * clients
7
- * users (chef >= 11)
7
+ * users (chef 11 - Open Source)
8
8
  * nodes
9
9
  * roles
10
10
  * environments
@@ -41,6 +41,11 @@ knife backup export cookbooks roles environments -D ~/my_chef_backup
41
41
  - `-N`, `--latest` only download the latest version of a cookbook
42
42
  - `-I`, `--ignore-permissions` ignore any permission errors during export
43
43
 
44
+ #### Optional Switches for restore
45
+
46
+ - `-I`, `--ignore-metadata-errors` Ignore json metadata errors when restoring cookbooks
47
+
48
+
44
49
  For more information on commands:
45
50
 
46
51
  ```bash
@@ -19,7 +19,8 @@
19
19
 
20
20
  require 'chef/node'
21
21
  require 'chef/api_client'
22
- if Chef::VERSION =~ /^1[1-9]\./
22
+
23
+ if Chef::VERSION =~ /^11\./
23
24
  require 'chef/user'
24
25
  end
25
26
  require 'chef/knife/cookbook_download'
@@ -79,10 +80,10 @@ module ServerBackup
79
80
  end
80
81
 
81
82
  def users
82
- if Chef::VERSION =~ /^1[1-9]\./
83
+ if Chef::VERSION =~ /^1[1]\./
83
84
  backup_standard("users", Chef::User)
84
85
  else
85
- ui.warn "users export only supported on chef >= 11"
86
+ ui.warn "users export only supported on chef == 11"
86
87
  end
87
88
  end
88
89
 
@@ -117,7 +118,7 @@ module ServerBackup
117
118
  klass.list.each do |component_name, url|
118
119
  next if component == "environments" && component_name == "_default"
119
120
  ui.msg "Backing up #{component} #{component_name}"
120
- component_obj = load_object(klass, component_name)
121
+ component_obj = load_object(klass, component_name).to_hash
121
122
  unless component_obj
122
123
  ui.error "Could not load #{klass} #{component_name}."
123
124
  next
@@ -44,6 +44,13 @@ module ServerBackup
44
44
  :description => "Restore backup data from DIR.",
45
45
  :default => Chef::Config[:knife][:chef_server_backup_dir] ? Chef::Config[:knife][:chef_server_backup_dir] : File.join(".chef", "chef_server_backup")
46
46
 
47
+ option :ignore_metadata_errors,
48
+ :short => "-I",
49
+ :long => "--ignore-metadata-errors",
50
+ :description => "Ignore json metadata errors when restoring cookbooks",
51
+ :boolean => true,
52
+ :default => Chef::Config[:knife][:ignore_metadata_errors] ? Chef::Config[:knife][:ignore_metadata_errors] : false
53
+
47
54
  def run
48
55
  ui.warn "This will overwrite existing data!"
49
56
  ui.warn "Backup is at least 1 day old" if (Time.now - File.atime(config[:backup_dir])) > 86400
@@ -118,6 +125,7 @@ module ServerBackup
118
125
  ui.info "=== Restoring clients ==="
119
126
  clients = Dir.glob(File.join(config[:backup_dir], "clients", "*.json"))
120
127
  clients.each do |file|
128
+ ui.info "Restoring clients from #{file}"
121
129
  client = JSON.parse(IO.read(file))
122
130
  begin
123
131
  rest.post_rest("clients", {
@@ -136,8 +144,8 @@ module ServerBackup
136
144
  JSON.create_id = "no_thanks"
137
145
  ui.info "=== Restoring users ==="
138
146
  users = Dir.glob(File.join(config[:backup_dir], "users", "*.json"))
139
- if !users.empty? and Chef::VERSION !~ /^1[1-9]\./
140
- ui.warn "users restore only supported on chef >= 11"
147
+ if !users.empty? and Chef::VERSION !~ /^11\./
148
+ ui.warn "users restore only supported on chef == 11"
141
149
  return
142
150
  end
143
151
  users.each do |file|
@@ -158,18 +166,28 @@ module ServerBackup
158
166
  end
159
167
 
160
168
  def cookbooks
169
+ count = 0
161
170
  ui.info "=== Restoring cookbooks ==="
162
171
  cookbooks = Dir.glob(File.join(config[:backup_dir], "cookbooks", '*'))
163
172
  #Make tmp dir
164
- cookbooks.each do |cb|
165
- FileUtils.rm_rf(config[:backup_dir] + "/tmp")
166
- Dir.mkdir config[:backup_dir] + "/tmp"
173
+ FileUtils.rm_rf(config[:backup_dir] + "/tmp")
174
+ Dir.mkdir config[:backup_dir] + "/tmp"
175
+ cookbooks.each do |cb|
167
176
  full_cb = File.expand_path(cb)
168
177
  cb_name = File.basename(cb)
169
178
  cookbook = cb_name.reverse.split('-',2).last.reverse
170
- full_path = File.join(config[:backup_dir] + "/tmp", cookbook)
179
+ full_path = File.join(config[:backup_dir] + "/tmp", cookbook)
171
180
  begin
172
- File.symlink(full_cb, full_path)
181
+ count += 1
182
+ if Chef::Platform.windows?
183
+ Dir.mkdir config[:backup_dir] + "/tmp/#{cb_name}"
184
+ full_path = File.join(config[:backup_dir] + "/tmp/#{cb_name}", cookbook)
185
+ ui.info "Copy cookbook #{full_cb} to #{full_path}"
186
+ FileUtils.copy_entry(full_cb, full_path)
187
+ else
188
+ full_path = File.join(config[:backup_dir] + "/tmp", cookbook)
189
+ File.symlink(full_cb, full_path)
190
+ end
173
191
  cbu = Chef::Knife::CookbookUpload.new
174
192
  Chef::Knife::CookbookUpload.load_deps
175
193
  cbu.name_args = [ cookbook ]
@@ -178,15 +196,27 @@ module ServerBackup
178
196
  cbu.run
179
197
  rescue Net::HTTPServerException => e
180
198
  handle_error 'cookbook', cb_name, e
199
+ rescue Chef::Exceptions::JSON::ParseError => e
200
+ handle_error 'cookbook', cb_name, e
201
+ throw e unless config[:ignore_metadata_errors]
181
202
  ensure
182
- File.unlink(full_path)
203
+ if Chef::Platform.windows?
204
+ rm_path = config[:backup_dir] + "/tmp/#{cb_name}"
205
+ ui.info "remove dir #{rm_path}"
206
+ FileUtils.remove_dir(rm_path, force = true)
207
+ else
208
+ File.unlink(full_path)
209
+ end
183
210
  end
184
- FileUtils.rm_rf(config[:backup_dir] + "/tmp")
185
211
  end
212
+ ui.info "Uploaded #{count} Cookbooks"
213
+ FileUtils.rm_rf(config[:backup_dir] + "/tmp")
186
214
  end
187
215
 
188
216
  def handle_error(type, name, error)
189
217
  thing = "#{type}[#{name}]"
218
+ return ui.error "Error parsing JSON for: #{thing}" if error.kind_of?(Chef::Exceptions::JSON::ParseError)
219
+
190
220
  case error.response
191
221
  when Net::HTTPConflict # 409
192
222
  ui.warn "#{thing} already exists; skipping"
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Backup
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Ducea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project: knife-backup
64
- rubygems_version: 2.4.4
64
+ rubygems_version: 2.4.8
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Chef knife plugins to help backup and restore chef servers