cleanfb 0.2.1.9 → 0.2.1.10
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.
- checksums.yaml +4 -4
- data/README.md +2 -14
- data/lib/cleanfb.rb +144 -197
- data/lib/cleanfb/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 434be941563759cbc0ead8756df2a75e49889362
|
4
|
+
data.tar.gz: 792c9163eead44fe621e28f13483cb8b6a19d5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f657f39c34d663eb3834f280e53b27c7b24de0df905524919352a86211d37097e935a809c933d24a0644ee829f70a87085679b16a18443c763469f7118ead48
|
7
|
+
data.tar.gz: 69a0ab512d7e7e66dc18c94af52f54757a3cce41b5279550457e3b03674a58a7f28218637631ca3a37e01a7abafac67d56353b06691fcbfb60dfaa74828bec57
|
data/README.md
CHANGED
@@ -11,18 +11,6 @@ Old configurations can also be restored using cleanfb.
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
Add this line to your application's Gemfile:
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
gem 'cleanfb'
|
18
|
-
```
|
19
|
-
|
20
|
-
And then execute:
|
21
|
-
|
22
|
-
$ bundle
|
23
|
-
|
24
|
-
Or install it yourself as:
|
25
|
-
|
26
14
|
$ gem install cleanfb
|
27
15
|
|
28
16
|
## Usage
|
@@ -40,7 +28,7 @@ cleanfb restore [file] [options]
|
|
40
28
|
-y | answer yes to all
|
41
29
|
--help | show help message
|
42
30
|
|
43
|
-
|
31
|
+
## Updating Configuration
|
44
32
|
|
45
33
|
Clean the configuration for a host
|
46
34
|
|
@@ -51,7 +39,7 @@ The configuration is now backed up on the server at /root/saved_configs/hostname
|
|
51
39
|
A new configuration will be obtained for the host on the next Puppet run.
|
52
40
|
|
53
41
|
|
54
|
-
|
42
|
+
## Restoring a previous Configuration
|
55
43
|
|
56
44
|
|
57
45
|
To restore a previous saved configuration issue the following command
|
data/lib/cleanfb.rb
CHANGED
@@ -3,201 +3,148 @@ require 'digest'
|
|
3
3
|
|
4
4
|
module Cleanfb
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
if ((ARGV.include? "-h") or (ARGV.include? "--help"))
|
151
|
-
return "Remove backups of an agent from the Puppet master's filebucket.\nBackups are stored at /root/saved_configs/\n\n Usage: cleanfb <client> <options>\n\n options: -h or --help | help and information\n
|
152
|
-
-y | defaults all input to yes\n"
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
arg = ARGV[1]
|
157
|
-
|
158
|
-
# set ans to yes automatically if -y option
|
159
|
-
if !ARGV.nil? and (ARGV.include? "-y") and ARGV.length > 1
|
160
|
-
ans = "y"
|
161
|
-
arg = ARGV[1] if (ARGV.index("-y") == 0)
|
162
|
-
|
163
|
-
# else prompt for answer
|
164
|
-
else
|
165
|
-
print "Restore #{arg} ? y|n: "
|
166
|
-
ans = STDIN.gets.chomp
|
167
|
-
end
|
168
|
-
|
169
|
-
# if yes, retrieve the files and remove them
|
170
|
-
if ans == "y" || ans == "yes"
|
171
|
-
|
172
|
-
host = arg.scan(/_\w+\.\w+\.?\w+?_/).join("").gsub!("_", "")
|
173
|
-
|
174
|
-
store(host)
|
175
|
-
|
176
|
-
file = arg
|
177
|
-
#sum = Digest::MD5.file file
|
178
|
-
#sum = sum.hexdigest + ""
|
179
|
-
#start = (sum.scan /\w/).join("/")
|
180
|
-
#path = "/opt/puppetlabs/puppet/cache/bucket"
|
181
|
-
|
182
|
-
#path += "/" + start[0..15] + sum + "/"
|
183
|
-
|
184
|
-
if File.exist? file
|
185
|
-
#puts "Restoring " + path
|
186
|
-
#unless Dir.exist? path
|
187
|
-
# cmd = `mkdir -p #{path}`
|
188
|
-
#end
|
189
|
-
|
190
|
-
|
191
|
-
#cmd = `cp #{file} #{path}contents`
|
192
|
-
puts "puppet filebucket -l backup #{file}"
|
193
|
-
cmd = `puppet filebucket -l backup #{file}`
|
194
|
-
else
|
195
|
-
puts "No file #{arg} found."
|
196
|
-
end
|
197
|
-
else
|
198
|
-
puts "No file #{arg} found."
|
199
|
-
end
|
200
|
-
return
|
201
|
-
end
|
202
|
-
end
|
6
|
+
class Clean
|
7
|
+
|
8
|
+
def remove()
|
9
|
+
|
10
|
+
return "Please supply a file" if (ARGV[0].nil? || ARGV[0].empty?)
|
11
|
+
|
12
|
+
help_msg = "Remove backups of an agent from the Puppet master filebucket.\nBackups are stored at /root/saved_configs/\n\n"
|
13
|
+
|
14
|
+
return help_msg if ((ARGV.include? "-h") || (ARGV.include? "--help"))
|
15
|
+
|
16
|
+
arg = ARGV[0]
|
17
|
+
|
18
|
+
if (!ARGV.nil? && (ARGV.include? "-y") && ARGV.length > 1)
|
19
|
+
ans = "y"
|
20
|
+
arg = ARGV[1] if (ARGV.index("-y") == 0)
|
21
|
+
|
22
|
+
else
|
23
|
+
print "Remove #{arg} ? y|n: "
|
24
|
+
ans = STDIN.gets.chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
if ans == "y" || ans == "yes"
|
28
|
+
cmd = `puppet filebucket list -l|grep -i #{arg}`
|
29
|
+
|
30
|
+
unless (ARGV.include? "-y")
|
31
|
+
test = cmd.split(" ").last
|
32
|
+
multi_match = false
|
33
|
+
|
34
|
+
cmd.each_line do |line|
|
35
|
+
if !line.include? test
|
36
|
+
multi_match = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if multi_match
|
41
|
+
print "Matched multiple hosts. Remove all? y|n: "
|
42
|
+
ans = STDIN.gets.chomp
|
43
|
+
|
44
|
+
unless ans == "y" || ans == "yes"
|
45
|
+
return "Ending run"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
unless cmd.nil? || cmd.empty?
|
52
|
+
cmd.each_line do |line|
|
53
|
+
path = "/opt/puppetlabs/puppet/cache/bucket"
|
54
|
+
sum = line.split(" ")[0]
|
55
|
+
|
56
|
+
start = (sum.scan /\w/).join("/")
|
57
|
+
|
58
|
+
file = line.split(" ")[3].split("/").last
|
59
|
+
name = file.split("_")[0]
|
60
|
+
date = line.split(" ")[1]
|
61
|
+
time = line.split(" ")[2]
|
62
|
+
|
63
|
+
save_dir = "/root/saved_configs/"
|
64
|
+
|
65
|
+
unless Dir.exist? save_dir
|
66
|
+
Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700)
|
67
|
+
end
|
68
|
+
|
69
|
+
unless Dir.exist? "#{save_dir}/#{name}/"
|
70
|
+
Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700)
|
71
|
+
end
|
72
|
+
|
73
|
+
path += "/" + start[0..15] + sum + "/"
|
74
|
+
|
75
|
+
if File.exist? "#{path}/contents"
|
76
|
+
puts "Storing " + path
|
77
|
+
puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
|
78
|
+
cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
|
79
|
+
cmd = `rm -rf #{path}`
|
80
|
+
else
|
81
|
+
puts "No file #{arg} found."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
else
|
85
|
+
puts "No file #{arg} found."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return
|
89
|
+
end
|
90
|
+
|
91
|
+
def store(host)
|
92
|
+
|
93
|
+
cmd = `puppet filebucket list -l|grep -i #{host}`
|
94
|
+
unless cmd.nil? || cmd.empty?
|
95
|
+
cmd.each_line do |line|
|
96
|
+
path = "/opt/puppetlabs/puppet/cache/bucket"
|
97
|
+
sum = line.split(" ")[0]
|
98
|
+
start = (sum.scan /\w/).join("/")
|
99
|
+
|
100
|
+
file = line.split(" ")[3].split("/").last
|
101
|
+
name = file.split("_")[0]
|
102
|
+
date = line.split(" ")[1]
|
103
|
+
time = line.split(" ")[2]
|
104
|
+
|
105
|
+
save_dir = "/root/saved_configs/"
|
106
|
+
|
107
|
+
Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700) unless (Dir.exist? save_dir)
|
108
|
+
|
109
|
+
Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700) unless Dir.exist? "#{save_dir}/#{name}/"
|
110
|
+
|
111
|
+
path += "/" + start[0..15] + sum + "/"
|
112
|
+
|
113
|
+
if File.exist? "#{path}/contents"
|
114
|
+
puts "Storing " + path
|
115
|
+
puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
|
116
|
+
cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
|
117
|
+
cmd = `rm -rf #{path}`
|
118
|
+
else
|
119
|
+
puts "No file #{host} found."
|
120
|
+
end
|
121
|
+
end
|
122
|
+
else
|
123
|
+
puts "No file #{host} found."
|
124
|
+
end
|
125
|
+
|
126
|
+
return
|
127
|
+
end
|
128
|
+
|
129
|
+
def restore()
|
130
|
+
|
131
|
+
return "Please supply a file" if ARGV[0].nil? || ARGV[0].empty?
|
132
|
+
|
133
|
+
arg = ARGV[1]
|
134
|
+
|
135
|
+
host = arg.scan(/_\w+\.\w+\.?\w+?_/).join("").gsub!("_", "")
|
136
|
+
store(host)
|
137
|
+
file = arg
|
138
|
+
|
139
|
+
if File.exist? file
|
140
|
+
puts "puppet filebucket -l backup #{file}"
|
141
|
+
cmd = `puppet filebucket -l backup #{file}`
|
142
|
+
else
|
143
|
+
puts "No file #{arg} found."
|
144
|
+
end
|
145
|
+
|
146
|
+
return
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
203
150
|
end
|
data/lib/cleanfb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cleanfb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.1.
|
4
|
+
version: 0.2.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lhoffl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.0.14.1
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Cleans the filebucket of a Puppet server
|