Chef-client cache backup


Ohai Chefs,

Is there a way to tell chef-client not to store chef cache files in the backup path (E.g. for windows C:\chef\backup\chef\cache)

My use case: I am downloading a file into Chef::Config[:file_cache_path] with a powershell_script resource that’s utilizing Read-S3Object cmdlet (not sure whether the actual resource makes a difference or not…) and then using file resource to delete the file in the Chef::Config[:file_cache_path], however the file in the backup folder above obviously persists.

Do I have to explicitly delete it from the backup path as well or is there another mechanism that’s more implicit?

Thank you


Hey there Alex,

Have you looked at the remote_file resource instead of using a powershell
script to download a file? The reason I bring this up is because with this
resource you can specify whether or not you would like to keep any backups
of this file, plus makes it idempotent, unless you have something in your
powershell script that already does this for you.

But if you would like to keep using a powershell_script you could to
specify at the end of your script to delete the file from chef backup cache

Hope this helps



Hello Roberto, thank you for the reply. In my use case the source S3 object is not available via http://, I need to pass explicit iam creds to authenticate with in order to fetch it from the bucket, hence going through aws sdk. Idempotence is handled by outer logic since the script resource is within a larger custom resource. But the backup property of the remote_file that you’ve pointed out is exactly what I was looking for. So looking through remote_file source and then at the Chef::Util::Backup it sounds like I should be able to explicitly call .backup(false) on my ps script resource object? Will give that a shot.


Hmm… That didn’t work even though PowershellScript resource is a subclass of Execute resource, which does have the backup property similar to file resource…


There also is the artifact-cookbook which can download from S3. An example from the readme is:

artifact_file "/tmp/my-artifact.tgz" do
  location "s3://"
  owner "me"
  group "mes"
  checksum "fcb188ed37d41ff2cbf1a52d3a11bfde666e036b5c7ada1496dc1d53dd6ed5dd"
  action :create


Just like the artifact cookbook you could also use the s3_file cookbook and
either explicitly remove the backup file or modify the resource to do so.


Thank you all. Will check out those cookbooks. In the meanwhile I figured out why my powershell_script’s resource_obj.backup failed for me earlier it’s because execute resource doesn’t define any accessor method for that instance var so for now I am just calling resource_obj.instance_variable_set(:@backup, false) to overwrite the default value of 5 backups. Again thanks for the tip on the backup property.