Puppet Class: pdns_server::db_backups

Defined in:
modules/pdns_server/manifests/db_backups.pp

Overview

SPDX-License-Identifier: Apache-2.0



2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# File 'modules/pdns_server/manifests/db_backups.pp', line 2

class pdns_server::db_backups(
) {
    if !defined(Class['pdns_server']) {
        notice('no pdns_server class defined?')
    }

    $db = 'pdns'
    $dbuser = 'dump'

    if debian::codename::ge('bookworm') {
      $binlog_privilege = 'BINLOG MONITOR'
    } else {
      $binlog_privilege = 'REPLICATION CLIENT'
    }

    $statements = [
        {
            'stmt'              => "CREATE USER IF NOT EXISTS ${dbuser}@localhost IDENTIFIED VIA unix_socket",
            'unless'            => 'SELECT user, plugin FROM mysql.user',
            'unless_grep_match' => "${dbuser}[[:space:]]unix_socket",
        },
        {
            'stmt'              => "GRANT RELOAD, FILE, SUPER, ${binlog_privilege} ON *.* TO \\`${dbuser}\\`@\\`localhost\\`",
            'unless'            => "SHOW GRANTS FOR '${dbuser}'@'localhost'",
            'unless_grep_match' => undef,  # will use the same stmt

        },
        {
            'stmt'              => "GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON \\`${db}\\`.* TO \\`${dbuser}\\`@\\`localhost\\`",
            'unless'            => "SHOW GRANTS FOR '${dbuser}'@'localhost'",
            'unless_grep_match' => undef,  # will use the same stmt
        },
    ].each |Integer $index, Hash $item| {
        dbutils::statement { "pdns_server_db_backups_stmt_${index}":
            statement         => $item['stmt'],
            unless            => $item['unless'],
            unless_grep_match => $item['unless_grep_match'],
        }
    }
}