Restoring files from a filebucket
Puppet, by default, makes a local copy of all the files that it changes on a system; it allows the recover old versions of files overwritten by Puppet. This functionality is managed with the filebucket
type, which allows to store a copy of the original files, either on a central server or locally on the managed system.
When we run Puppet, we see messages like this:
info: /Stage[main]/Ntp/File[ntp.conf]: Filebucketed /etc/ntp.conf to puppet with sum 7fda24f62b1c7ae951db0f746dc6e0cc
The checksum of the original file is useful to retrieve it; in fact files are saved in the directory /var/lib/puppet/clientbucket
in a series of subdirectories named according to the same checksum. So, given the preceding example, our file contents are saved in:
/var/lib/puppet/clientbucket/7/f/d/a/2/4/f/6/7fda24f62b1c7ae951db0f746dc6e0cc/contents
We can verify the original path in:
/var/lib/puppet/clientbucket/7/f/d/a/2/4/f/6/7fda24f62b1c7ae951db0f746dc6e0cc/paths
A quick way to look for the saved copies of a file, therefore, is to use a command like this:
grep -R /etc/ntp.conf /var/lib/puppet/clientbucket/
Puppet provides the filebucket
subcommand to retrieve saved files. In the preceding example, we can recover the original file with a (not particularly handy) command like:
puppet filebucket restore -l --bucket /var/lib/puppet/clientbucket /etc/ntp.conf 7fda24f62b1c7ae951db0f746dc6e0cc
It's possible to configure remote filebucket
, typically on the Puppet Master using the special filebucket
type:
filebucket { 'central': path => false, # This is required for remote filebuckets. server => 'my.s.com', # Optional, by default is the puppetmaster }
Once declared filebucket
, we can assign it to a file with the backup
argument:
file { '/etc/ntp.conf': backup => 'central', }
This is generally done using a resource default defined at top scope (typically in our /etc/puppet/manifests/site.pp
):
File { backup => 'central', }