Search Puppet file bucket for a changed file(s)

When you use Puppet to manage your infrastructure, it’s common to manage several files on a system with a template or something. The default setting when a file is changed, it gets a backup on the client system in a filebucket

You can use to command ‘puppet filebucket’ with a lot of options to hopefully get what you want…. Or…. just search the filesystem 🙂

The location below holds the directory structure were the files are physically stored! with a lot of hashes added 😐

'/opt/puppetlabs/puppet/cache/clientbucket/'

A directory structure could look like this:

f
f/8
f/8/6
f/8/6/3
f/8/6/3/1
f/8/6/3/1/b
f/8/6/3/1/b/a
f/8/6/3/1/b/a/a
f/8/6/3/1/b/a/a/f8631baa8f83d5067af7eedcd7bdf641
f/8/6/3/1/b/a/a/f8631baa8f83d5067af7eedcd7bdf641/contents
f/8/6/3/1/b/a/a/f8631baa8f83d5067af7eedcd7bdf641/paths

The files content and paths hold the magic information about original file and its location. YES!!

Use the following command the search your filebucket to get you’re long lost files back!!

find /opt/puppetlabs/puppet/cache/clientbucket/ -name paths -print -exec grep <file to look for> {} \;

This only works when the file is managed through the ‘file’ resource type.

Files changed by augeas or not to be found here…. Bummer!

Rename all files in directory from $file to $newfile

The what?

Dead simple.
How do I rename

hello_kitty2.png
hello_kitty3.png

to

byebye_kitty2.png
byebye_kitty3.png

I think it’s simple, but it’s hard to Google for this kind of thing unless you already know.

The how…..!

You can do this with a simple one-liner with bash

for file in $(ls hello_ki*); do mv "$file" "${file/hello/byebye}"; done