Forge Home


Backs up files before changing them, even if you don't know how they get changed.


5,909 latest version

4.6 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.2.4 (latest)
  • 0.2.3
  • 0.2.2
  • 0.2.1
  • 0.2.0
  • 0.1.2
  • 0.1.1
  • 0.1.0
released Jul 6th 2017
This version is compatible with:
  • Debian, RedHat, Ubuntu, Windows, Solaris, AIX

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'dylanratcliffe-backup', '0.2.4'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add dylanratcliffe-backup
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install dylanratcliffe-backup --version 0.2.4

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.



dylanratcliffe/backup — version 0.2.4 Jul 6th 2017

Backup module

Backs up files before changing them, even if you don't know how they get changed.

This module allows you to ensure that Puppet backs up critical files before it touches them, even if you are using a forge module to manage those files and you don't know how it actually works under the hood.

Defined Types


This defined type causes puppet to back up a file before it changes it. This functionality is different to that of the Filebucket in that it can back up files regardless of the type of resource that is changing them. Filebucket on the other hand only works with file resources. The functionality that this provides is implemented by the puppetlabs/transition module which allows puppet to modify the state of one resource before it goes to change another.

In this case is creates a backup if a given file, before changing the $watch resource or class.

This defined type also supports restoring files from a backup. Simply set ensure to restored and the file will copied from the backup directory. Please not that this may cause duplicate declaration or loops where Puppet restored the file then changes it again. You will likely need to comment out the class that caused the erroneous change to get this to work properly.


watch: The resource or class to watch. If this resource/class is going to change, a backup will be created

backup_dir: Where to put the backups. This defaults to relative, meaning that the backup file will be put in the same location as the original file, but with the version appended.

file: The file to back up

ensure: backed_up or restored

version: This allows you to specify a string to be assigned to the backup version. If this parameter is set, the file will be backed up once per version, the first time it is touched. This allows us to set the version to pre_puppet and maintain a backup of the state of the file before it was managed by Puppet. This state will not be overwritten. When restoring files the version parameter refers to which version to restore. If version is not specified, backup keeps the previous version of the file.


Backing up ssh config

backup { '/etc/ssh/sshd_config':
  ensure        => 'backed_up',
  backup_before => Class['::ssh'],

Backing up ssh config to a specific location

backup { '/etc/ssh/sshd_config':
  ensure        => 'backed_up',
  backup_before => Class['::ssh'],
  backup_dir    => '/var/backups',