class Puppet::Application::Filebucket

Attributes

args[R]

Public Instance Methods

backup() click to toggle source
    # File lib/puppet/application/filebucket.rb
225 def backup
226   raise _("You must specify a file to back up") unless args.length > 0
227 
228   args.each do |file|
229     unless Puppet::FileSystem.exist?(file)
230       $stderr.puts _("%{file}: no such file") % { file: file }
231       next
232     end
233     unless FileTest.readable?(file)
234       $stderr.puts _("%{file}: cannot read file") % { file: file }
235       next
236     end
237     digest = @client.backup(file)
238     puts "#{file}: #{digest}"
239   end
240 end
diff() click to toggle source
    # File lib/puppet/application/filebucket.rb
255 def diff
256   raise Puppet::Error, _("Need exactly two arguments: filebucket diff <file_a> <file_b>") unless args.count == 2
257   left = args.shift
258   right = args.shift
259   if Puppet::FileSystem.exist?(left)
260     # It's a file
261     file_a = left
262     checksum_a = nil
263   else
264     file_a = nil
265     checksum_a = left
266   end
267   if Puppet::FileSystem.exist?(right)
268     # It's a file
269     file_b = right
270     checksum_b = nil
271   else
272     file_b = nil
273     checksum_b = right
274   end
275   if (checksum_a || file_a) && (checksum_b || file_b)
276     Puppet.info(_("Comparing %{checksum_a} %{checksum_b} %{file_a} %{file_b}") % { checksum_a: checksum_a, checksum_b: checksum_b, file_a: file_a, file_b: file_b })
277     print @client.diff(checksum_a, checksum_b, file_a, file_b)
278   else
279     raise Puppet::Error, _("Need exactly two arguments: filebucket diff <file_a> <file_b>")
280   end
281 end
digest_algorithm() click to toggle source
   # File lib/puppet/application/filebucket.rb
20 def digest_algorithm
21   Puppet.default_digest_algorithm
22 end
get() click to toggle source
    # File lib/puppet/application/filebucket.rb
219 def get
220   digest = args.shift
221   out = @client.getfile(digest)
222   print out
223 end
help() click to toggle source
    # File lib/puppet/application/filebucket.rb
 24   def help
 25     <<-HELP
 26 
 27 puppet-filebucket(8) -- #{summary}
 28 ========
 29 
 30 SYNOPSIS
 31 --------
 32 A stand-alone Puppet filebucket client.
 33 
 34 
 35 USAGE
 36 -----
 37 puppet filebucket <mode> [-h|--help] [-V|--version] [-d|--debug]
 38   [-v|--verbose] [-l|--local] [-r|--remote] [-s|--server <server>]
 39   [-f|--fromdate <date>] [-t|--todate <date>] [-b|--bucket <directory>]
 40   <file> <file> ...
 41 
 42 Puppet filebucket can operate in three modes, with only one mode per call:
 43 
 44 backup:
 45   Send one or more files to the specified file bucket. Each sent file is
 46   printed with its resulting #{digest_algorithm} sum.
 47 
 48 get:
 49   Return the text associated with an #{digest_algorithm} sum. The text is printed to
 50   stdout, and only one file can be retrieved at a time.
 51 
 52 restore:
 53   Given a file path and an #{digest_algorithm} sum, store the content associated with
 54   the sum into the specified file path. You can specify an entirely new
 55   path to this argument; you are not restricted to restoring the content
 56   to its original location.
 57 
 58 diff:
 59   Print a diff in unified format between two checksums in the filebucket
 60   or between a checksum and its matching file.
 61 
 62 list:
 63   List all files in the current local filebucket. Listing remote
 64   filebuckets is not allowed.
 65 
 66 DESCRIPTION
 67 -----------
 68 This is a stand-alone filebucket client for sending files to a local or
 69 central filebucket.
 70 
 71 Note that 'filebucket' defaults to using a network-based filebucket
 72 available on the server named 'puppet'. To use this, you'll have to be
 73 running as a user with valid Puppet certificates. Alternatively, you can
 74 use your local file bucket by specifying '--local', or by specifying
 75 '--bucket' with a local path.
 76 
 77 > **Note**: Enabling and using the backup option, and by extension the 
 78   filebucket resource, requires appropriate planning and management to ensure 
 79   that sufficient disk space is available for the file backups. Generally, you 
 80   can implement this using one of the following two options:
 81   - Use a `find` command and `crontab` entry to retain only the last X days 
 82   of file backups. For example: 
 83 
 84   ```shell
 85   find /opt/puppetlabs/server/data/puppetserver/bucket -type f -mtime +45 -atime +45 -print0 | xargs -0 rm
 86   ```
 87 
 88   - Restrict the directory to a maximum size after which the oldest items are removed.
 89 
 90 
 91 OPTIONS
 92 -------
 93 Note that any setting that's valid in the configuration
 94 file is also a valid long argument. For example, 'ssldir' is a valid
 95 setting, so you can specify '--ssldir <directory>' as an
 96 argument.
 97 
 98 See the configuration file documentation at
 99 https://puppet.com/docs/puppet/latest/configuration.html for the
100 full list of acceptable parameters. A commented list of all
101 configuration options can also be generated by running puppet with
102 '--genconfig'.
103 
104 * --bucket:
105   Specify a local filebucket path. This overrides the default path
106   set in '$clientbucketdir'.
107 
108 * --debug:
109   Enable full debugging.
110 
111 * --fromdate:
112   (list only) Select bucket files from 'fromdate'.
113 
114 * --help:
115   Print this help message.
116 
117 * --local:
118   Use the local filebucket. This uses the default configuration
119   information and the bucket located at the '$clientbucketdir'
120   setting by default. If '--bucket' is set, puppet uses that
121   path instead.
122 
123 * --remote:
124   Use a remote filebucket. This uses the default configuration
125   information and the bucket located at the '$bucketdir' setting
126   by default.
127 
128 * --server_list:
129   A list of comma separated servers; only the first entry is used for file storage.
130   This setting takes precidence over `server`.
131 
132 * --server:
133   The server to use for file storage. This setting is only used if `server_list`
134   is not set.
135 
136 * --todate:
137   (list only) Select bucket files until 'todate'.
138 
139 * --verbose:
140   Print extra information.
141 
142 * --version:
143   Print version information.
144 
145 EXAMPLES
146 --------
147     ## Backup a file to the filebucket, then restore it to a temporary directory
148     $ puppet filebucket backup /etc/passwd
149     /etc/passwd: 429b225650b912a2ee067b0a4cf1e949
150     $ puppet filebucket restore /tmp/passwd 429b225650b912a2ee067b0a4cf1e949
151 
152     ## Diff between two files in the filebucket
153     $ puppet filebucket -l diff d43a6ecaa892a1962398ac9170ea9bf2 7ae322f5791217e031dc60188f4521ef
154     1a2
155     > again
156 
157     ## Diff between the file in the filebucket and a local file
158     $ puppet filebucket -l diff d43a6ecaa892a1962398ac9170ea9bf2 /tmp/testFile
159     1a2
160     > again
161 
162     ## Backup a file to the filebucket and observe that it keeps each backup separate
163     $ puppet filebucket -l list
164     d43a6ecaa892a1962398ac9170ea9bf2 2015-05-11 09:27:56 /tmp/TestFile
165 
166     $ echo again >> /tmp/TestFile
167 
168     $ puppet filebucket -l backup /tmp/TestFile
169     /tmp/TestFile: 7ae322f5791217e031dc60188f4521ef
170 
171     $ puppet filebucket -l list
172     d43a6ecaa892a1962398ac9170ea9bf2 2015-05-11 09:27:56 /tmp/TestFile
173     7ae322f5791217e031dc60188f4521ef 2015-05-11 09:52:15 /tmp/TestFile
174 
175     ## List files in a filebucket within date ranges
176     $ puppet filebucket -l -f 2015-01-01 -t 2015-01-11 list
177     <Empty Output>
178 
179     $ puppet filebucket -l -f 2015-05-10 list
180     d43a6ecaa892a1962398ac9170ea9bf2 2015-05-11 09:27:56 /tmp/TestFile
181     7ae322f5791217e031dc60188f4521ef 2015-05-11 09:52:15 /tmp/TestFile
182 
183     $ puppet filebucket -l -f "2015-05-11 09:30:00" list
184     7ae322f5791217e031dc60188f4521ef 2015-05-11 09:52:15 /tmp/TestFile
185 
186     $ puppet filebucket -l -t "2015-05-11 09:30:00" list
187     d43a6ecaa892a1962398ac9170ea9bf2 2015-05-11 09:27:56 /tmp/TestFile
188     ## Manage files in a specific local filebucket
189     $ puppet filebucket -b /tmp/TestBucket backup /tmp/TestFile2
190     /tmp/TestFile2: d41d8cd98f00b204e9800998ecf8427e
191     $ puppet filebucket -b /tmp/TestBucket list
192     d41d8cd98f00b204e9800998ecf8427e 2015-05-11 09:33:22 /tmp/TestFile2
193 
194     ## From a Puppet Server, list files in the server bucketdir
195     $ puppet filebucket -b $(puppet config print bucketdir --section server) list
196     d43a6ecaa892a1962398ac9170ea9bf2 2015-05-11 09:27:56 /tmp/TestFile
197     7ae322f5791217e031dc60188f4521ef 2015-05-11 09:52:15 /tmp/TestFile
198 
199 AUTHOR
200 ------
201 Luke Kanies
202 
203 
204 COPYRIGHT
205 ---------
206 Copyright (c) 2011 Puppet Inc., LLC Licensed under the Apache 2.0 License
207 
208     HELP
209   end
list() click to toggle source
    # File lib/puppet/application/filebucket.rb
242 def list
243   fromdate = options[:fromdate]
244   todate = options[:todate]
245   out = @client.list(fromdate, todate)
246   print out
247 end
restore() click to toggle source
    # File lib/puppet/application/filebucket.rb
249 def restore
250   file = args.shift
251   digest = args.shift
252   @client.restore(file, digest)
253 end
run_command() click to toggle source
    # File lib/puppet/application/filebucket.rb
212 def run_command
213   @args = command_line.args
214   command = args.shift
215   return send(command) if %w{get backup restore diff list}.include? command
216   help
217 end
setup() click to toggle source
    # File lib/puppet/application/filebucket.rb
283 def setup
284   Puppet::Log.newdestination(:console)
285 
286   @client = nil
287   @server = nil
288 
289   Signal.trap(:INT) do
290     $stderr.puts _("Cancelling")
291     exit(1)
292   end
293 
294   if options[:debug]
295     Puppet::Log.level = :debug
296   elsif options[:verbose]
297     Puppet::Log.level = :info
298   end
299 
300   exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
301 
302   require_relative '../../puppet/file_bucket/dipper'
303   begin
304     if options[:local] or options[:bucket]
305       path = options[:bucket] || Puppet[:clientbucketdir]
306       @client = Puppet::FileBucket::Dipper.new(:Path => path)
307     else
308       session = Puppet.lookup(:http_session)
309       api = session.route_to(:puppet)
310 
311       @client = Puppet::FileBucket::Dipper.new(Server: api.url.host, Port: api.url.port)
312     end
313   rescue => detail
314     Puppet.log_exception(detail)
315     exit(1)
316   end
317 end
summary() click to toggle source
   # File lib/puppet/application/filebucket.rb
16 def summary
17   _("Store and retrieve files in a filebucket")
18 end