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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -14
  3. data/lib/cleanfb.rb +144 -197
  4. data/lib/cleanfb/version.rb +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c95025d6e6eeb63110d63333a0d1eda6dcdf2503
4
- data.tar.gz: 4364de2ebb6d0140da5ff0b716086e3883574466
3
+ metadata.gz: 434be941563759cbc0ead8756df2a75e49889362
4
+ data.tar.gz: 792c9163eead44fe621e28f13483cb8b6a19d5c4
5
5
  SHA512:
6
- metadata.gz: 10d2ab7c94c4eccc27477e126f07f0c7df3257246962cd3af5f207f37bbd28e549a191e5b4ff0881ef12227166bdf33394a6b64c9eb9b232567e4aec7350720f
7
- data.tar.gz: a78fffefffa0c36908b23b9b4e660c79c9fe2256a6356dd514b1cb5611f9f632e0b6be08d1fe0bd61b682c2c54a2c73d7bcd217b67fa000644055e8b4113d0e8
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
- ###Updating Configuration
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
- ###Restoring a previous Configuration
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
- class Clean
7
-
8
- ##
9
- # Method to remove ALL files backed up on the Puppet masters filebucket
10
- # from a specified agent.
11
- ##
12
- def remove()
13
-
14
- # return if no args
15
- return "Please supply a file" if ARGV[0].nil? || ARGV[0].empty?
16
-
17
- # return the help output if requested
18
- if ((ARGV.include? "-h") or (ARGV.include? "--help"))
19
- 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
20
- -y | defaults all input to yes\n"
21
-
22
- end
23
-
24
- arg = ARGV[0]
25
-
26
- # set ans to yes automatically if -y option
27
- if !ARGV.nil? and (ARGV.include? "-y") and ARGV.length > 1
28
- ans = "y"
29
- arg = ARGV[1] if (ARGV.index("-y") == 0)
30
-
31
- # else prompt for answer
32
- else
33
- print "Remove #{arg} ? y|n: "
34
- ans = STDIN.gets.chomp
35
- end
36
-
37
- # if yes, retrieve the files and remove them
38
- if ans == "y" || ans == "yes"
39
- cmd = `puppet filebucket list -l|grep -i #{arg}`
40
-
41
- unless (ARGV.include? "-y")
42
- test = cmd.split(" ").last
43
- multi_match = false
44
-
45
- cmd.each_line do |line|
46
- if !line.include? test
47
- multi_match = true
48
- end
49
- end
50
-
51
- if multi_match
52
- print "Matched multiple hosts. Remove all? y|n: "
53
- ans = STDIN.gets.chomp
54
-
55
- unless ans == "y" || ans == "yes"
56
- return "Ending run"
57
- end
58
- end
59
- end
60
-
61
-
62
- unless cmd.nil? || cmd.empty?
63
- cmd.each_line do |line|
64
- path = "/opt/puppetlabs/puppet/cache/bucket"
65
- sum = line.split(" ")[0]
66
- start = (sum.scan /\w/).join("/")
67
-
68
- file = line.split(" ")[3].split("/").last
69
- name = file.split("_")[0]
70
- date = line.split(" ")[1]
71
- time = line.split(" ")[2]
72
-
73
- save_dir = "/root/saved_configs/"
74
-
75
- unless Dir.exist? save_dir
76
- Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700)
77
- end
78
-
79
- unless Dir.exist? "#{save_dir}/#{name}/"
80
- Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700)
81
- end
82
-
83
- path += "/" + start[0..15] + sum + "/"
84
-
85
- if File.exist? "#{path}/contents"
86
-
87
- puts "Storing " + path
88
- puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
89
- cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
90
- cmd = `rm -rf #{path}`
91
- else
92
- puts "No file #{arg} found."
93
- end
94
- end
95
- else
96
- puts "No file #{arg} found."
97
- end
98
- end
99
- return
100
- end
101
-
102
- def store(host)
103
-
104
- cmd = `puppet filebucket list -l|grep -i #{host}`
105
- unless cmd.nil? || cmd.empty?
106
- cmd.each_line do |line|
107
- path = "/opt/puppetlabs/puppet/cache/bucket"
108
- sum = line.split(" ")[0]
109
- start = (sum.scan /\w/).join("/")
110
-
111
- file = line.split(" ")[3].split("/").last
112
- name = file.split("_")[0]
113
- date = line.split(" ")[1]
114
- time = line.split(" ")[2]
115
-
116
- save_dir = "/root/saved_configs/"
117
-
118
- unless Dir.exist? save_dir
119
- Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700)
120
- end
121
-
122
- unless Dir.exist? "#{save_dir}/#{name}/"
123
- Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700)
124
- end
125
-
126
- path += "/" + start[0..15] + sum + "/"
127
-
128
- if File.exist? "#{path}/contents"
129
-
130
- puts "Storing " + path
131
- puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
132
- cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
133
- cmd = `rm -rf #{path}`
134
- else
135
- puts "No file #{host} found."
136
- end
137
- end
138
- else
139
- puts "No file #{host} found."
140
- end
141
- return
142
- end
143
-
144
- def restore()
145
-
146
- # return if no args
147
- return "Please supply a file" if ARGV[0].nil? || ARGV[0].empty?
148
-
149
- # return the help output if requested
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
@@ -1,3 +1,3 @@
1
1
  module Cleanfb
2
- VERSION = "0.2.1.9"
2
+ VERSION = "0.2.1.10"
3
3
  end
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.9
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: 2016-09-22 00:00:00.000000000 Z
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.6.6
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