knife-backup 0.0.4 → 0.0.5

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.
@@ -21,7 +21,6 @@ require 'chef/node'
21
21
  require 'chef/api_client'
22
22
  require 'chef/knife/cookbook_download'
23
23
 
24
-
25
24
  module ServerBackup
26
25
  class BackupExport < Chef::Knife
27
26
 
@@ -30,7 +29,7 @@ module ServerBackup
30
29
  require 'chef/cookbook_loader'
31
30
  end
32
31
 
33
- banner "knife backup export [-D DIR]"
32
+ banner "knife backup export [COMPONENT [COMPONENT ...]] [-D DIR] (options)"
34
33
 
35
34
  option :backup_dir,
36
35
  :short => "-D DIR",
@@ -45,12 +44,20 @@ module ServerBackup
45
44
  :boolean => true
46
45
 
47
46
  def run
48
- clients
49
- nodes
50
- roles
51
- data_bags
52
- environments
53
- cookbooks
47
+ validate!
48
+ components = name_args.empty? ? COMPONENTS.keys : name_args
49
+ Array(components).each { |component| self.send(component) }
50
+ end
51
+
52
+ private
53
+ COMPONENTS = %w(clients nodes roles data_bags environments cookbooks)
54
+
55
+ def validate!
56
+ bad_names = name_args - COMPONENTS
57
+ unless bad_names.empty?
58
+ ui.error "Component types #{bad_names.join(",")} are not valid."
59
+ exit 1
60
+ end
54
61
  end
55
62
 
56
63
  def nodes
@@ -101,7 +108,7 @@ module ServerBackup
101
108
  end
102
109
 
103
110
  def cookbooks
104
- ui.msg "Backing up cookboks"
111
+ ui.msg "Backing up cookbooks"
105
112
  dir = File.join(config[:backup_dir], "cookbooks")
106
113
  FileUtils.mkdir_p(dir)
107
114
  if config[:latest]
@@ -110,7 +117,7 @@ module ServerBackup
110
117
  cookbooks = rest.get_rest("/cookbooks?num_versions=all")
111
118
  end
112
119
  cookbooks.keys.each do |cb|
113
- ui.msg "Backing up coookbook #{cb}"
120
+ ui.msg "Backing up cookbook #{cb}"
114
121
  dld = Chef::Knife::CookbookDownload.new
115
122
  cookbooks[cb]['versions'].each do |ver|
116
123
  dld.name_args = [cb, ver['version']]
@@ -34,7 +34,7 @@ module ServerBackup
34
34
  require 'chef/api_client'
35
35
  end
36
36
 
37
- banner "knife backup restore [-D DIR]"
37
+ banner "knife backup restore [COMPONENT [COMPONENT ...]] [-D DIR] (options)"
38
38
 
39
39
  option :backup_dir,
40
40
  :short => "-D DIR",
@@ -46,12 +46,20 @@ module ServerBackup
46
46
  ui.warn "This will overwrite existing data!"
47
47
  ui.warn "Backup is at least 1 day old" if (Time.now - File.atime(config[:backup_dir])) > 86400
48
48
  ui.confirm "Do you want to restore backup, possibly overwriting exisitng data"
49
- clients
50
- nodes
51
- roles
52
- data_bags
53
- environments
54
- cookbooks
49
+ validate!
50
+ components = name_args.empty? ? COMPONENTS.keys : name_args
51
+ Array(components).each { |component| self.send(component) }
52
+ end
53
+
54
+ private
55
+ COMPONENTS = %w(clients nodes roles data_bags environments cookbooks)
56
+
57
+ def validate!
58
+ bad_names = name_args - COMPONENTS
59
+ unless bad_names.empty?
60
+ ui.error "Component types #{bad_names.join(",")} are not valid."
61
+ exit 1
62
+ end
55
63
  end
56
64
 
57
65
  def nodes
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Backup
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef