knife-tarsnap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +201 -0
- data/README.md +249 -0
- data/Rakefile +2 -0
- data/knife-tarsnap.gemspec +23 -0
- data/lib/chef/knife/tarsnap/core.rb +146 -0
- data/lib/chef/knife/tarsnap_backup_download.rb +69 -0
- data/lib/chef/knife/tarsnap_backup_dump.rb +65 -0
- data/lib/chef/knife/tarsnap_backup_show.rb +62 -0
- data/lib/chef/knife/tarsnap_key_create.rb +83 -0
- data/lib/chef/knife/tarsnap_key_from_file.rb +73 -0
- data/lib/chef/knife/tarsnap_key_list.rb +41 -0
- data/lib/chef/knife/tarsnap_key_show.rb +42 -0
- data/lib/knife-tarsnap/version.rb +5 -0
- metadata +80 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
knife-tarsnap (0.1.0)
|
5
|
+
chef (>= 0.10.10)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
chef (11.4.0)
|
11
|
+
erubis
|
12
|
+
highline (>= 1.6.9)
|
13
|
+
json (>= 1.4.4, <= 1.7.7)
|
14
|
+
mixlib-authentication (>= 1.3.0)
|
15
|
+
mixlib-cli (~> 1.3.0)
|
16
|
+
mixlib-config (>= 1.1.2)
|
17
|
+
mixlib-log (>= 1.3.0)
|
18
|
+
mixlib-shellout
|
19
|
+
net-ssh (~> 2.6)
|
20
|
+
net-ssh-multi (~> 1.1.0)
|
21
|
+
ohai (>= 0.6.0)
|
22
|
+
rest-client (>= 1.0.4, < 1.7.0)
|
23
|
+
yajl-ruby (~> 1.1)
|
24
|
+
erubis (2.7.0)
|
25
|
+
highline (1.6.16)
|
26
|
+
ipaddress (0.8.0)
|
27
|
+
json (1.7.7)
|
28
|
+
mime-types (1.22)
|
29
|
+
mixlib-authentication (1.3.0)
|
30
|
+
mixlib-log
|
31
|
+
mixlib-cli (1.3.0)
|
32
|
+
mixlib-config (1.1.2)
|
33
|
+
mixlib-log (1.6.0)
|
34
|
+
mixlib-shellout (1.1.0)
|
35
|
+
net-ssh (2.6.6)
|
36
|
+
net-ssh-gateway (1.2.0)
|
37
|
+
net-ssh (>= 2.6.5)
|
38
|
+
net-ssh-multi (1.1)
|
39
|
+
net-ssh (>= 2.1.4)
|
40
|
+
net-ssh-gateway (>= 0.99.0)
|
41
|
+
ohai (6.16.0)
|
42
|
+
ipaddress
|
43
|
+
mixlib-cli
|
44
|
+
mixlib-config
|
45
|
+
mixlib-log
|
46
|
+
mixlib-shellout
|
47
|
+
systemu
|
48
|
+
yajl-ruby
|
49
|
+
rest-client (1.6.7)
|
50
|
+
mime-types (>= 1.16)
|
51
|
+
systemu (2.5.2)
|
52
|
+
yajl-ruby (1.1.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
knife-tarsnap!
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
# Chef Tarsnap
|
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.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
### Cookbook Installation
|
9
|
+
|
10
|
+
Install the cookbook using knife:
|
11
|
+
|
12
|
+
$ knife cookbook install tarsnap
|
13
|
+
|
14
|
+
Or install the cookbook from github:
|
15
|
+
|
16
|
+
$ git clone git://github.com/jssjr/chef-tarsnap.git cookbooks/tarsnap
|
17
|
+
$ rm -rf cookbooks/tarsnap/.git
|
18
|
+
|
19
|
+
Or use the [knife-github-cookbooks](https://github.com/websterclay/knife-github-cookbooks) plugin:
|
20
|
+
|
21
|
+
$ knife cookbook github install jssjr/chef-tarsnap
|
22
|
+
|
23
|
+
|
24
|
+
### Knife Plugin Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
gem 'knife-tarsnap'
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install knife-tarsnap
|
37
|
+
|
38
|
+
Alternatively, and add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
gem 'chef-tarsnap', :path => 'cookbooks/tarsnap/knife-plugin'
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle
|
45
|
+
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
### Backing up node data
|
50
|
+
|
51
|
+
Create a recipe to define your tarnsap resources, like this:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# my-app::backups
|
55
|
+
|
56
|
+
include_recipe 'tarsnap'
|
57
|
+
|
58
|
+
tarsnap_backup 'app-data' do
|
59
|
+
path '/opt/my_app/data'
|
60
|
+
schedule 'hourly'
|
61
|
+
end
|
62
|
+
|
63
|
+
tarsnap_backup 'etc-data' do
|
64
|
+
path [ '/etc', '/usr/local/etc' ]
|
65
|
+
schedule 'daily'
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
The tarsnap LWRP will create an archive for each resource and will maintain a set of snapshots according to the schedule.
|
70
|
+
|
71
|
+
You can use the default by including the `tarsnap::default_schedule` recipe or define your own. See the documentation for scheduling at [danrue/feather](https://github.com/danrue/feather) for more information on the rotation behavior. The default schedule is below:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
tarsnap_schedule "monthly" do
|
75
|
+
period 2592000 # 30 days
|
76
|
+
always_keep 12
|
77
|
+
before "0600"
|
78
|
+
end
|
79
|
+
|
80
|
+
tarsnap_schedule "weekly" do
|
81
|
+
period 604800 # 7 days
|
82
|
+
always_keep 6
|
83
|
+
after "0200"
|
84
|
+
before "0600"
|
85
|
+
implies "monthly"
|
86
|
+
end
|
87
|
+
|
88
|
+
tarsnap_schedule "daily" do
|
89
|
+
period 86400 # 1 day
|
90
|
+
always_keep 14
|
91
|
+
after "0200"
|
92
|
+
before "0600"
|
93
|
+
implies "weekly"
|
94
|
+
end
|
95
|
+
|
96
|
+
tarsnap_schedule "hourly" do
|
97
|
+
period 3600 # 1 hour
|
98
|
+
always_keep 24
|
99
|
+
implies "daily"
|
100
|
+
end
|
101
|
+
|
102
|
+
tarsnap_schedule "realtime" do
|
103
|
+
period 900 # 15 minutes
|
104
|
+
always_keep 10
|
105
|
+
implies "hourly"
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
### Tarsnap keys
|
111
|
+
|
112
|
+
Tarsnap keys are stored on the chef server in an encrypted data bag. When the tarsnap::default recipe is included in a node's run list, it will call the tarsnap_key LWRP and attempt to create the /root/tarsnap.key file. If the key is not found in the tarsnap keys data bag, then the LWRP will create a placeholder data bag item indicating the key needs to be created. The tarsnap knife plugin provides tasks to simplify key management.
|
113
|
+
|
114
|
+
The format of the encrypted data bag item is:
|
115
|
+
|
116
|
+
```json
|
117
|
+
{
|
118
|
+
"id": "hostname_domain_tld",
|
119
|
+
"node": "hostname.domain.tld",
|
120
|
+
"key": "# START OF TARSNAP KEY FILE\ndGFyc25hcAAAAAAA..."
|
121
|
+
}
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
### Configuring the tarsnap knife plugin
|
126
|
+
|
127
|
+
> **NOTE** This plugin requires you to have tarsnap installed! Please see [https://www.tarsnap.com/download.html](https://www.tarsnap.com/download.html) for sources, or ask your favorite operating system's package manager.
|
128
|
+
|
129
|
+
> **NOTE** Tarsnap requires an account at [tarsnap.com](http://tarsnap.com) to work. The service is frighteningly secure, lightweight, and very inexpensive.
|
130
|
+
|
131
|
+
You can provide the required options for the knife plugin on the command line, or you can set them in your knife.rb file.
|
132
|
+
|
133
|
+
* **Username**
|
134
|
+
|
135
|
+
command line: `-A` or `--tarsnap-username`
|
136
|
+
|
137
|
+
knife.rb: `knife[:tarsnap_username] = "root@example.com"`
|
138
|
+
|
139
|
+
* **Password** (By default, knife will prompt for the password if required.)
|
140
|
+
|
141
|
+
command line: `-K` or `--tarsnap-password`
|
142
|
+
|
143
|
+
knife.rb: `knife[:tarsnap_password] = "supersecret" # Bad idea!`
|
144
|
+
|
145
|
+
* **Data Bag** (By default, the keys data bag is `tarsnap_keys`)
|
146
|
+
|
147
|
+
command line: `-B` or `--tarsnap-data-bag`
|
148
|
+
|
149
|
+
knife.rb: `knife[:tarsnap_data_bag] = "tarsnap_keys"`
|
150
|
+
|
151
|
+
|
152
|
+
### Managing keys with the knife plugin
|
153
|
+
|
154
|
+
#### $ knife tarsnap key list (options)
|
155
|
+
|
156
|
+
Lists all known and pending tarsnap keys.
|
157
|
+
|
158
|
+
#### $ knife tarsnap key create NODE (options)
|
159
|
+
|
160
|
+
Creates the tarsnap key for a node, and removes the placeholder data bag item so the node is no longer considered pending. This command will prompt for your Tarsnap password if it isn't provided as an option or in your knife.rb config file.
|
161
|
+
|
162
|
+
#### $ knife tarsnap key from file KEYFILE NODE (options)
|
163
|
+
|
164
|
+
Create the tarsnap key for a node by reading the key contents from a file.
|
165
|
+
|
166
|
+
#### $ knife tarsnap key show NODE (options)
|
167
|
+
|
168
|
+
Output the decrypted tarsnap key for a node.
|
169
|
+
|
170
|
+
|
171
|
+
### Managing backups with the knife plugin
|
172
|
+
|
173
|
+
#### $ knife tarsnap backup show NODE \[ARCHIVE\] (options)
|
174
|
+
|
175
|
+
Show all of the archives that tarsnap has for a node. If the archive name is provided, then list the filenames in the archive.
|
176
|
+
|
177
|
+
Example:
|
178
|
+
|
179
|
+
$ knife tarsnap backup show ip-10-72-206-146.ec2.internal <<<
|
180
|
+
etc-201304070526UTC-daily
|
181
|
+
etc-201304070526UTC-hourly
|
182
|
+
etc-201304070526UTC-monthly
|
183
|
+
etc-201304070526UTC-realtime
|
184
|
+
etc-201304070526UTC-weekly
|
185
|
+
etc-201304070545UTC-realtime
|
186
|
+
|
187
|
+
Example:
|
188
|
+
|
189
|
+
$ knife tarsnap backup show ip-10-72-206-146.ec2.internal etc-201304070526UTC-daily | head
|
190
|
+
etc/
|
191
|
+
etc/.pwd.lock
|
192
|
+
etc/X11/
|
193
|
+
etc/X11/xkb/
|
194
|
+
etc/acpi/
|
195
|
+
etc/acpi/events/
|
196
|
+
etc/acpi/events/powerbtn
|
197
|
+
etc/acpi/powerbtn.sh
|
198
|
+
etc/adduser.conf
|
199
|
+
|
200
|
+
#### $ knife tarsnap backup download NODE ARCHIVE (options)
|
201
|
+
|
202
|
+
Download an archive tarball from the tarsnap server.
|
203
|
+
|
204
|
+
#### $ knife tarsnap backup dump NODE ARCHIVE PATTERN (options)
|
205
|
+
|
206
|
+
Dump the contents of files in an archive that match the provided pattern to standard output. This is similar to using the tar command with an inclusion pattern. Use the `-D DIRECTORY` option to retrieve the matching files into a local directory instead.
|
207
|
+
|
208
|
+
Example:
|
209
|
+
|
210
|
+
$ knife tarsnap backup dump ip-10-72-206-146.ec2.internal etc-201304070526UTC-daily 'etc/adduser.conf' | head
|
211
|
+
# /etc/adduser.conf: `adduser' configuration.
|
212
|
+
# See adduser(8) and adduser.conf(5) for full documentation.
|
213
|
+
|
214
|
+
# The DSHELL variable specifies the default login shell on your
|
215
|
+
# system.
|
216
|
+
DSHELL=/bin/bash
|
217
|
+
|
218
|
+
# The DHOME variable specifies the directory containing users' home
|
219
|
+
# directories.
|
220
|
+
DHOME=/home
|
221
|
+
|
222
|
+
|
223
|
+
## Contributing
|
224
|
+
|
225
|
+
1. Fork it
|
226
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
227
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
228
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
229
|
+
5. Create new Pull Request
|
230
|
+
|
231
|
+
## License
|
232
|
+
|
233
|
+
Author:: Scott Sanders (ssanders@taximagic.com)
|
234
|
+
|
235
|
+
Copyright:: Copyright (c) 2013 RideCharge, Inc.
|
236
|
+
|
237
|
+
License:: Apache License, Version 2.0
|
238
|
+
|
239
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
240
|
+
you may not use this file except in compliance with the License.
|
241
|
+
You may obtain a copy of the License at
|
242
|
+
|
243
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
244
|
+
|
245
|
+
Unless required by applicable law or agreed to in writing, software
|
246
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
247
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
248
|
+
See the License for the specific language governing permissions and
|
249
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/knife-tarsnap/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "knife-tarsnap"
|
6
|
+
gem.version = Knife::Tarsnap::VERSION
|
7
|
+
gem.authors = ["Scott Sanders"]
|
8
|
+
gem.email = ["ssanders@taximagic.com"]
|
9
|
+
gem.description = %q{Knife plugin and Chef cookbook for managing tarsnap.}
|
10
|
+
gem.summary = %q{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.}
|
11
|
+
gem.homepage = "https://github.com/jssjr/chef-tarsnap"
|
12
|
+
gem.licenses = ["APACHE"]
|
13
|
+
|
14
|
+
gem.files = Dir['lib/**/*.rb'] + Dir['bin/*']
|
15
|
+
gem.files += Dir['[A-Z]*'] + Dir['test/**/*']
|
16
|
+
gem.files += Dir['*\.gemspec']
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
gem.add_dependency "chef", ">= 0.10.10"
|
21
|
+
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,146 @@
|
|
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
|
+
class Chef
|
18
|
+
class Knife
|
19
|
+
class Tarsnap
|
20
|
+
module Core
|
21
|
+
|
22
|
+
# :nodoc:
|
23
|
+
# Would prefer to do this in a rational way, but can't be done b/c of
|
24
|
+
# Mixlib::CLI's design :(
|
25
|
+
def self.included(includer)
|
26
|
+
includer.class_eval do
|
27
|
+
|
28
|
+
deps do
|
29
|
+
require 'chef/knife'
|
30
|
+
require 'chef/shell/ext'
|
31
|
+
Chef::Knife.load_deps
|
32
|
+
end
|
33
|
+
|
34
|
+
option :tarsnap_username,
|
35
|
+
:short => "-A USERNAME",
|
36
|
+
:long => "--tarsnap-username KEY",
|
37
|
+
:description => "Your Tarsnap Username",
|
38
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:tarsnap_username] = key }
|
39
|
+
|
40
|
+
option :tarsnap_password,
|
41
|
+
:short => "-K SECRET",
|
42
|
+
:long => "--tarsnap-password SECRET",
|
43
|
+
:description => "Your Tarsnap Password",
|
44
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:tarsnap_password] = key }
|
45
|
+
|
46
|
+
option :tarsnap_data_bag,
|
47
|
+
:short => "-B BAG_NAME",
|
48
|
+
:long => "--tarsnap-data-bag BAG_NAME",
|
49
|
+
:description => "The data bag containing Tarsnap keys",
|
50
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:tarsnap_data_bag] = key },
|
51
|
+
:default => "tarsnap_keys"
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Convenience methods for options
|
57
|
+
|
58
|
+
def tarsnap_username
|
59
|
+
if Chef::Config[:knife][:tarsnap_username]
|
60
|
+
Chef::Config[:knife][:tarsnap_username]
|
61
|
+
else
|
62
|
+
raise StandardError, "Please provide the tarsnap account username"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def tarsnap_password
|
67
|
+
if Chef::Config[:knife][:tarsnap_password].nil?
|
68
|
+
Chef::Config[:knife][:tarsnap_password] = ui.ask('Tarsnap Password: ') { |q| q.echo = '*' }
|
69
|
+
end
|
70
|
+
Chef::Config[:knife][:tarsnap_password]
|
71
|
+
end
|
72
|
+
|
73
|
+
def tarsnap_data_bag
|
74
|
+
Chef::Config[:knife][:tarsnap_data_bag] || config[:tarsnap_data_bag]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Required tools
|
78
|
+
|
79
|
+
def keygen_tool
|
80
|
+
@_keygen_path || @_keygen_path = which('tarsnap-keygen')
|
81
|
+
end
|
82
|
+
|
83
|
+
def tarsnap_tool
|
84
|
+
@_tarsnap_path || @_tarsnap_path = which('tarsnap')
|
85
|
+
end
|
86
|
+
|
87
|
+
# Helpers
|
88
|
+
|
89
|
+
def canonicalize(fqdn)
|
90
|
+
fqdn.gsub(".","_")
|
91
|
+
end
|
92
|
+
|
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("_",".")}
|
95
|
+
end
|
96
|
+
|
97
|
+
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
|
+
end
|
100
|
+
|
101
|
+
def fetch_node(fqdn)
|
102
|
+
Shell::Extensions.extend_context_object(self)
|
103
|
+
nodes.find("fqdn:#{fqdn}").first
|
104
|
+
end
|
105
|
+
|
106
|
+
def fetch_key(fqdn)
|
107
|
+
bag_item = fetch_tarsnap_bag_item(fqdn)
|
108
|
+
if bag_item
|
109
|
+
bag_item['key']
|
110
|
+
else
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def is_a_tarsnap_node?(fqdn)
|
116
|
+
tarsnap_nodes.include?(fqdn)
|
117
|
+
end
|
118
|
+
|
119
|
+
def remove_pending_node(fqdn)
|
120
|
+
rest.delete_rest("data/#{tarsnap_data_bag}/__#{canonicalize(fqdn)}")
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def which(binary)
|
126
|
+
which_cmd = "which #{binary}"
|
127
|
+
which_shell = Mixlib::ShellOut.new(which_cmd)
|
128
|
+
which_shell.run_command
|
129
|
+
unless which_shell.status.exitstatus == 0
|
130
|
+
raise StandardError, "Unable to locate the tarsnap tool (#{binary}). Is it installed and in your path?"
|
131
|
+
end
|
132
|
+
which_shell.stdout.chomp
|
133
|
+
end
|
134
|
+
|
135
|
+
def fetch_tarsnap_bag_item(fqdn)
|
136
|
+
begin
|
137
|
+
Chef::EncryptedDataBagItem.load(tarsnap_data_bag, canonicalize(fqdn))
|
138
|
+
rescue Net::HTTPServerException => e
|
139
|
+
nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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 TarsnapBackupDownload < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap backup download NODE ARCHIVE (options)"
|
26
|
+
|
27
|
+
option :save_to,
|
28
|
+
:short => "-S TARBALL",
|
29
|
+
:long => "--save-to TARBALL",
|
30
|
+
:description => "Retrieves the archive tarball into the specific file"
|
31
|
+
|
32
|
+
def run
|
33
|
+
|
34
|
+
unless name_args.size == 2
|
35
|
+
ui.fatal "Must provide only NODE and ARCHIVE."
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
node_name = name_args[0]
|
40
|
+
archive_name = name_args[1]
|
41
|
+
|
42
|
+
tarball = config[:save_to] || File.join(Dir.pwd, "#{archive_name}.tar")
|
43
|
+
|
44
|
+
if File.exists?(tarball)
|
45
|
+
ui.warn "A file named #{tarball} already exists. Do you want to overwrite it?"
|
46
|
+
ui.confirm "Overwrite"
|
47
|
+
end
|
48
|
+
|
49
|
+
Tempfile.open('tarsnap', '/tmp') do |f|
|
50
|
+
key = fetch_key(node_name)
|
51
|
+
f.write(key)
|
52
|
+
f.close
|
53
|
+
|
54
|
+
list_cmd = "#{tarsnap_tool} --keyfile #{f.path} -r -f #{archive_name} > #{tarball}"
|
55
|
+
|
56
|
+
ui.msg "Downloading #{tarball}..."
|
57
|
+
list_shell = Mixlib::ShellOut.new(list_cmd, :timeout => 604800)
|
58
|
+
list_shell.run_command
|
59
|
+
unless list_shell.status.exitstatus == 0
|
60
|
+
raise StandardError, "tarsnap error: #{list_shell.stderr}"
|
61
|
+
end
|
62
|
+
ui.msg "#{tarball} saved."
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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 TarsnapBackupDump < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap backup dump NODE ARCHIVE PATTERN (options)"
|
26
|
+
|
27
|
+
option :directory,
|
28
|
+
:short => "-D USERNAME",
|
29
|
+
:long => "--directory KEY",
|
30
|
+
:description => "Retrieve matching files into this local directory"
|
31
|
+
|
32
|
+
def run
|
33
|
+
|
34
|
+
if name_args.size == 3
|
35
|
+
node_name = name_args[0]
|
36
|
+
archive_name = name_args[1]
|
37
|
+
filename = name_args.last
|
38
|
+
else
|
39
|
+
ui.fatal "Incorrect number of options provided"
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
Tempfile.open('tarsnap', '/tmp') do |f|
|
44
|
+
key = fetch_key(node_name)
|
45
|
+
f.write(key)
|
46
|
+
f.close
|
47
|
+
|
48
|
+
if config[:directory]
|
49
|
+
dump_cmd = "#{tarsnap_tool} --keyfile #{f.path} -x -f #{archive_name} -C #{config[:directory]} --include '#{filename}'"
|
50
|
+
else
|
51
|
+
dump_cmd = "#{tarsnap_tool} --keyfile #{f.path} -x -f #{archive_name} -O --include '#{filename}'"
|
52
|
+
end
|
53
|
+
dump_shell = Mixlib::ShellOut.new(dump_cmd, :timeout => 604800, :environment => {'LC_ALL'=>nil})
|
54
|
+
dump_shell.run_command
|
55
|
+
unless dump_shell.status.exitstatus == 0
|
56
|
+
raise StandardError, "tarsnap error: #{dump_shell.stderr}"
|
57
|
+
end
|
58
|
+
ui.msg dump_shell.stdout
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 TarsnapBackupShow < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap backup show NODE [ARCHIVE] (options)"
|
26
|
+
|
27
|
+
def run
|
28
|
+
|
29
|
+
node_name = name_args.first
|
30
|
+
if name_args.size == 2
|
31
|
+
archive_name = name_args.last
|
32
|
+
elsif name_args.size == 1
|
33
|
+
archive_name = nil
|
34
|
+
else
|
35
|
+
ui.fatal "Must provide only NODE and an option ARCHIVE."
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
Tempfile.open('tarsnap', '/tmp') do |f|
|
40
|
+
key = fetch_key(node_name)
|
41
|
+
f.write(key)
|
42
|
+
f.close
|
43
|
+
|
44
|
+
if archive_name.nil?
|
45
|
+
list_cmd = "#{tarsnap_tool} --keyfile #{f.path} --list-archives"
|
46
|
+
else
|
47
|
+
list_cmd = "#{tarsnap_tool} -t --keyfile #{f.path} -f #{archive_name}"
|
48
|
+
end
|
49
|
+
|
50
|
+
list_shell = Mixlib::ShellOut.new(list_cmd, :environment => {'LC_ALL'=>nil})
|
51
|
+
list_shell.run_command
|
52
|
+
unless list_shell.stderr.empty?
|
53
|
+
raise StandardError, "tarsnap error: #{list_shell.stderr}"
|
54
|
+
end
|
55
|
+
list_shell.stdout.split("\n").sort.each { |l| ui.msg l }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,83 @@
|
|
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 TarsnapKeyCreate < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap key create NODE (options)"
|
26
|
+
|
27
|
+
def run
|
28
|
+
|
29
|
+
unless name_args.size == 1
|
30
|
+
ui.fatal "You must provide a node name"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
n = name_args.last
|
35
|
+
|
36
|
+
match = fetch_node(n)
|
37
|
+
unless match.is_a? Chef::Node
|
38
|
+
ui.fatal "#{n} is not a node. Skipping..."
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
existing_key = fetch_key(n)
|
43
|
+
if existing_key
|
44
|
+
ui.warn "A key for #{n} already exists! Overwrite it with a new key?"
|
45
|
+
ui.warn "The old key will be saved to #{ENV['HOME']}/tarsnap.#{n}.key.old"
|
46
|
+
ui.confirm "Overwrite"
|
47
|
+
IO.write("#{ENV['HOME']}/tarsnap.#{n}.key.old", existing_key)
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
keyfile = File.join('/tmp', "tarsnap-#{rand(36**8).to_s(36)}")
|
52
|
+
keygen_cmd = "echo '#{tarsnap_password}' | #{keygen_tool} --keyfile #{keyfile} --user #{tarsnap_username} --machine #{n}"
|
53
|
+
keygen_shell = Mixlib::ShellOut.new(keygen_cmd)
|
54
|
+
keygen_shell.run_command
|
55
|
+
unless keygen_shell.stderr.empty?
|
56
|
+
raise StandardError, "tarsnap-keygen error: #{keygen_shell.stderr}"
|
57
|
+
end
|
58
|
+
|
59
|
+
ui.info "Creating data bag #{tarsnap_data_bag}/#{canonicalize(n)}"
|
60
|
+
data = { "id" => canonicalize(n), "node" => n, "key" => IO.read(keyfile) }
|
61
|
+
secret = Chef::EncryptedDataBagItem.load_secret(config[:secret_file])
|
62
|
+
item = Chef::EncryptedDataBagItem.encrypt_data_bag_item(data, secret)
|
63
|
+
data_bag = Chef::DataBagItem.new
|
64
|
+
data_bag.data_bag(tarsnap_data_bag)
|
65
|
+
data_bag.raw_data = item
|
66
|
+
data_bag.save
|
67
|
+
|
68
|
+
remove_pending_node(n)
|
69
|
+
|
70
|
+
ui.info ui.color("Data bag created!", :green)
|
71
|
+
rescue Exception => e
|
72
|
+
ui.msg "Error: #{e}"
|
73
|
+
ui.warn ui.color("Key creation failed!", :red)
|
74
|
+
exit 1
|
75
|
+
ensure
|
76
|
+
File.unlink(keyfile) if File.exists?(keyfile)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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 TarsnapKeyFromFile < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap key from file KEYFILE NODE (options)"
|
26
|
+
|
27
|
+
def run
|
28
|
+
|
29
|
+
unless name_args.size == 2
|
30
|
+
ui.fatal "You must provide a key file and a node name"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
k = name_args.first
|
35
|
+
n = name_args.last
|
36
|
+
|
37
|
+
match = fetch_node(n)
|
38
|
+
unless match.is_a? Chef::Node
|
39
|
+
ui.fatal "#{n} is not a node. Skipping..."
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
existing_key = fetch_key(n)
|
44
|
+
if existing_key
|
45
|
+
ui.warn "A key for #{n} already exists! Overwrite it with a new key?"
|
46
|
+
ui.warn "The old key will be saved to #{ENV['HOME']}/tarsnap.#{n}.key.old"
|
47
|
+
ui.confirm "Continue"
|
48
|
+
IO.write("#{ENV['HOME']}/tarsnap.#{n}.key.old", existing_key)
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
data = { "id" => canonicalize(n), "node" => n, "key" => IO.read(k) }
|
53
|
+
secret = Chef::EncryptedDataBagItem.load_secret(config[:secret_file])
|
54
|
+
item = Chef::EncryptedDataBagItem.encrypt_data_bag_item(data, secret)
|
55
|
+
data_bag = Chef::DataBagItem.new
|
56
|
+
data_bag.data_bag(tarsnap_data_bag)
|
57
|
+
data_bag.raw_data = item
|
58
|
+
data_bag.save
|
59
|
+
|
60
|
+
remove_pending_node(n)
|
61
|
+
|
62
|
+
ui.info ui.color("Data bag created from file!", :green)
|
63
|
+
rescue Exception => e
|
64
|
+
ui.msg "Error: #{e}"
|
65
|
+
ui.warn ui.color("Key creation failed!", :red)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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 TarsnapKeyList < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap key list (options)"
|
26
|
+
|
27
|
+
def run
|
28
|
+
|
29
|
+
ui.msg ui.color('status node', :bold)
|
30
|
+
tarsnap_nodes.each do |n|
|
31
|
+
ui.msg "#{ui.color('registered ', :green)}#{n}"
|
32
|
+
end
|
33
|
+
pending_nodes.each do |n|
|
34
|
+
ui.msg "#{ui.color('pending ', :yellow)}#{n}"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 TarsnapKeyShow < Knife
|
22
|
+
|
23
|
+
include Knife::Tarsnap::Core
|
24
|
+
|
25
|
+
banner "knife tarsnap key show NODE (options)"
|
26
|
+
|
27
|
+
def run
|
28
|
+
|
29
|
+
unless name_args.size == 1
|
30
|
+
ui.fatal "You must provide a node name"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
n = name_args.first
|
35
|
+
|
36
|
+
ui.msg fetch_key(n)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-tarsnap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott Sanders
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.10
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.10
|
30
|
+
description: Knife plugin and Chef cookbook for managing tarsnap.
|
31
|
+
email:
|
32
|
+
- ssanders@taximagic.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/chef/knife/tarsnap/core.rb
|
38
|
+
- lib/chef/knife/tarsnap_backup_download.rb
|
39
|
+
- lib/chef/knife/tarsnap_backup_dump.rb
|
40
|
+
- lib/chef/knife/tarsnap_backup_show.rb
|
41
|
+
- lib/chef/knife/tarsnap_key_create.rb
|
42
|
+
- lib/chef/knife/tarsnap_key_from_file.rb
|
43
|
+
- lib/chef/knife/tarsnap_key_list.rb
|
44
|
+
- lib/chef/knife/tarsnap_key_show.rb
|
45
|
+
- lib/knife-tarsnap/version.rb
|
46
|
+
- Gemfile
|
47
|
+
- Gemfile.lock
|
48
|
+
- LICENSE
|
49
|
+
- Rakefile
|
50
|
+
- README.md
|
51
|
+
- knife-tarsnap.gemspec
|
52
|
+
homepage: https://github.com/jssjr/chef-tarsnap
|
53
|
+
licenses:
|
54
|
+
- APACHE
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.23
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Provides a chef cookbook with LWRP's to directory snapshots and maintain
|
77
|
+
retention schedules. Includes a knife plugin for managing tarsnap keys, listing
|
78
|
+
backups, and restoring files.
|
79
|
+
test_files: []
|
80
|
+
has_rdoc:
|