knife-tarsnap 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Chef Tarsnap
1
+ # Chef / Tarsnap
2
2
 
3
- Provides a chef cookbook with LWRP's to directory snapshots and maintain retention schedules. Includes a knife plugin for managing tarsnap keys, listing backups, and restoring files.
3
+ Provides a chef cookbook with LWRP's to take directory snapshots and maintain retention schedules. Includes a knife plugin for managing tarsnap keys, listing backups, and restoring files.
4
+
5
+ Backup services are handled by [Colin Percival's](https://twitter.com/cperciva) excellent [tarsnap](https://www.tarsnap.com/).
4
6
 
5
7
 
6
8
  ## Installation
@@ -37,7 +39,7 @@ Or install it yourself as:
37
39
 
38
40
  Alternatively, and add this line to your application's Gemfile:
39
41
 
40
- gem 'chef-tarsnap', :path => 'cookbooks/tarsnap/knife-plugin'
42
+ gem 'knife-tarsnap', :path => 'cookbooks/tarsnap/knife-tarsnap'
41
43
 
42
44
  And then execute:
43
45
 
@@ -57,6 +59,7 @@ include_recipe 'tarsnap'
57
59
 
58
60
  tarsnap_backup 'app-data' do
59
61
  path '/opt/my_app/data'
62
+ exclude '/opt/my_app/data/bin'
60
63
  schedule 'hourly'
61
64
  end
62
65
 
@@ -167,6 +170,10 @@ Create the tarsnap key for a node by reading the key contents from a file.
167
170
 
168
171
  Output the decrypted tarsnap key for a node.
169
172
 
173
+ #### $ knife tarsnap key export (options)
174
+
175
+ Export all keys into a local directory named ./tarsnap-keys-TIMESTAMP. Override the directory with the `-D DIRNAME` option.
176
+
170
177
 
171
178
  ### Managing backups with the knife plugin
172
179
 
@@ -220,6 +227,11 @@ Example:
220
227
  DHOME=/home
221
228
 
222
229
 
230
+ ## Warning!
231
+
232
+ You need to keep a copy of your keys somewhere safe. If you lose them, then it is **impossible** to recover anything from your tarsnap backups. The chef server provides a convenient storage system for this data through data bags, however I strongly suggest storing redundant copies of the keys in multiple locations.
233
+
234
+
223
235
  ## Contributing
224
236
 
225
237
  1. Fork it
@@ -91,11 +91,13 @@ class Chef
91
91
  end
92
92
 
93
93
  def pending_nodes
94
- @_pending_nodes || @_pending_nodes = Chef::DataBag.load(tarsnap_data_bag).keep_if{|k,v| k =~ /^__/}.map{|k,v| k.gsub(/^__/, '').gsub("_",".")}
94
+ @_pending_nodes || @_pending_nodes =
95
+ Chef::DataBag.load(tarsnap_data_bag).keep_if{|k,v| k =~ /^__/}.map{|k,v| k.gsub(/^__/, '').gsub("_",".")}
95
96
  end
96
97
 
97
98
  def tarsnap_nodes
98
- @_tarsnap_nodes || @_tarsnap_nodes = Chef::DataBag.load(tarsnap_data_bag).keep_if{|k,v| k !~ /^__/}.map{|k,v| k.gsub("_",".")}
99
+ @_tarsnap_nodes || @_tarsnap_nodes =
100
+ Chef::DataBag.load(tarsnap_data_bag).keep_if{|k,v| k !~ /^__/}.map{|k,v| k.gsub("_",".")}
99
101
  end
100
102
 
101
103
  def fetch_node(fqdn)
@@ -25,8 +25,8 @@ class Chef
25
25
  banner "knife tarsnap backup dump NODE ARCHIVE PATTERN (options)"
26
26
 
27
27
  option :directory,
28
- :short => "-D USERNAME",
29
- :long => "--directory KEY",
28
+ :short => "-D DIRNAME",
29
+ :long => "--directory DIRNAME",
30
30
  :description => "Retrieve matching files into this local directory"
31
31
 
32
32
  def run
@@ -0,0 +1,77 @@
1
+ # Author:: Scott Sanders (ssanders@taximagic.com)
2
+ # Copyright:: Copyright (c) 2013 RideCharge, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'chef/knife/tarsnap/core'
18
+
19
+ class Chef
20
+ class Knife
21
+ class TarsnapKeyExport < Knife
22
+
23
+ include Knife::Tarsnap::Core
24
+
25
+ banner "knife tarsnap key export (options)"
26
+
27
+ option :directory,
28
+ :short => "-D DIRNAME",
29
+ :long => "--directory DIRNAME",
30
+ :default => File.join(Dir.getwd, "tarsnap-keys-#{Time.now.utc.to_i}"),
31
+ :description => "Export into this local directory (default: tarsnap-keys-TIMESTAMP)"
32
+
33
+ def run
34
+
35
+ begin
36
+ Dir.mkdir(config[:directory], 0700)
37
+ rescue Errno::EEXIST => e
38
+ # continue...
39
+ end
40
+
41
+ tarsnap_nodes.each do |n|
42
+ keyfile = File.join(config[:directory], "#{n}.key")
43
+ if confirm_overwrite?(keyfile)
44
+ ui.msg "Exporting #{keyfile}"
45
+ File.write(keyfile, fetch_key(n))
46
+ end
47
+ end
48
+
49
+ ui.msg "Export finished!"
50
+
51
+ end
52
+
53
+ def confirm_overwrite?(file)
54
+ return true if config[:yes]
55
+
56
+ if File.exists?(file)
57
+ stdout.print "Overwrite #{file}? (Y/N) "
58
+ answer = stdin.readline
59
+ answer.chomp!
60
+ case answer
61
+ when "Y", "y"
62
+ true
63
+ when "N", "n"
64
+ self.msg("Skipping #{file}")
65
+ false
66
+ else
67
+ self.msg("I have no idea what to do with #{answer}")
68
+ self.msg("Just say Y or N, please.")
69
+ confirm(question)
70
+ end
71
+ end
72
+ true
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Tarsnap
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-tarsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-07 00:00:00.000000000 Z
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -39,6 +39,7 @@ files:
39
39
  - lib/chef/knife/tarsnap_backup_dump.rb
40
40
  - lib/chef/knife/tarsnap_backup_show.rb
41
41
  - lib/chef/knife/tarsnap_key_create.rb
42
+ - lib/chef/knife/tarsnap_key_export.rb
42
43
  - lib/chef/knife/tarsnap_key_from_file.rb
43
44
  - lib/chef/knife/tarsnap_key_list.rb
44
45
  - lib/chef/knife/tarsnap_key_show.rb