Puppet Class: postgresql::backup

Defined in:
modules/postgresql/manifests/backup.pp

Overview

class { '::postgresql::backup': } backup::set { 'postgresql': }

Or add your custom Bacula fileset in modules/profile/manifests/backup/director.pp)

Parameters:

  • path (String) (defaults to: '/srv/postgres-backup')

    Full path to a directory to dump to. No ending slash. default: /srv/postgres-backup

  • rotate_days (Integer) (defaults to: 7)

    Number of days after which old backups are deleted. default: 7



16
17
18
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
59
60
61
62
63
# File 'modules/postgresql/manifests/backup.pp', line 16

class postgresql::backup(
    String $path = '/srv/postgres-backup',
    Integer $rotate_days = 7,
) {

    file { $path:
        ensure => 'directory',
        owner  => 'postgres',
        group  => 'postgres',
        mode   => '0750',
    }

    file { '/usr/local/bin/dump_all.sh':
        ensure => 'file',
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
        source => 'puppet:///modules/postgresql/dump_all.sh',
    }

    $dump_hour = fqdn_rand(23, 'pgdump')
    $dump_minute = fqdn_rand(59, 'pgdump')

    systemd::timer::job { 'postgres-dump':
        ensure      => 'present',
        description => 'Regular jobs to dump all databases and meta information',
        user        => 'postgres',
        command     => "/usr/local/bin/dump_all.sh ${path}",
        interval    => {
            'start'    => 'OnCalendar',
            'interval' => "*-*-* ${dump_hour}:${dump_minute}:00",
        },
    }

    $clean_hour = fqdn_rand(23, 'pgclean')
    $clean_minute = fqdn_rand(59, 'pgclean')

    systemd::timer::job { 'rotate-postgres-dump':
        ensure      => 'present',
        description => 'Regular jobs to clean up old dumps',
        user        => 'postgres',
        command     => "/usr/bin/find ${path} -type f -name '*.sql.gz' -mtime +${rotate_days} -delete",
        interval    => {
            'start'    => 'OnCalendar',
            'interval' => "*-*-* ${clean_hour}:${clean_minute}:00",
        },
    }
}