Puppet Class: dbbackup

Defined in:
manifests/init.pp

Summary

module to configure a systemd timer + script to backup postgres, mysql and ldap databases

Overview

Parameters:

  • pigz_cpu_cores (Optional[Integer[1]]) (defaults to: undef)

    number of cpu cores used for backup compression. If undefined, nproc will be used when available.

  • destination (Stdlib::Absolutepath) (defaults to: '/mnt/dumps')

    directory where backups will be stored (with one subdirectory per backup day)

  • interval (String[2]) (defaults to: '1h')

    how often the systemd timer will trigger the dump script. This will be used for the OnUnitInactiveSec option in the timer

  • backuphistory (Optional[Integer[1]]) (defaults to: undef)

    number of days to keep the backup history

  • cleanup_empty_backup_dirs (Boolean) (defaults to: true)

    enable/disable a post command to cleanup empty directories with $destination. They can occour if the system run out of free diskspace

  • dependencies (Array[String[1]]) (defaults to: ['pigz'])

    array of dependencies for the database dump script

  • manage_dependencies (Boolean) (defaults to: false)

    Boolean to enable/disable the installation of the dependencies. defaults to false because the parameter was added after the initial release

Author:

  • Tim Meusel <tim@bastelfreak.de>



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'manifests/init.pp', line 19

class dbbackup (
  Optional[Integer[1]] $pigz_cpu_cores = undef,
  Stdlib::Absolutepath $destination    = '/mnt/dumps',
  String[2] $interval                  = '1h',
  Optional[Integer[1]] $backuphistory  = undef,
  Boolean $cleanup_empty_backup_dirs   = true,
  Array[String[1]] $dependencies       = ['pigz'],
  Boolean $manage_dependencies         = false,
) {
  file { '/usr/local/bin/dump_databases':
    content => epp("${module_name}/dump_databases.epp", {
        'destination'    => $destination,
        'pigz_cpu_cores' => $pigz_cpu_cores,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
  }
  -> systemd::timer { 'dump_databases.timer':
    enable          => true,
    active          => true,
    timer_content   => epp("${module_name}/dump_databases.timer.epp", {
        'interval' => $interval,
    }),
    service_content => epp("${module_name}/dump_databases.service.epp", {
        'backuphistory'             => $backuphistory,
        'destination'               => $destination,
        'cleanup_empty_backup_dirs' => $cleanup_empty_backup_dirs,
    }),
  }

  if $manage_dependencies {
    $dependencies.each |String[1] $package| {
      package { $package:
        ensure => 'installed',
        before => Systemd::Timer['dump_databases.timer'],
      }
    }
  }
}