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