Puppet Class: mysql::backup::mysqldump

Inherits:
mysql::params
Defined in:
manifests/backup/mysqldump.pp

Summary

"Provider" for mysqldump

Overview

Parameters:

  • backupuser (Any) (defaults to: '')
  • backuppassword (Variant[String, Sensitive[String]]) (defaults to: '')
  • backupdir (Any) (defaults to: '')
  • maxallowedpacket (Any) (defaults to: '1M')
  • backupdirmode (Any) (defaults to: '0700')
  • backupdirowner (Any) (defaults to: 'root')
  • backupdirgroup (Any) (defaults to: $mysql::params::root_group)
  • backupcompress (Any) (defaults to: true)
  • backuprotate (Any) (defaults to: 30)
  • backupmethod (Any) (defaults to: 'mysqldump')
  • backup_success_file_path (Any) (defaults to: undef)
  • ignore_events (Any) (defaults to: true)
  • delete_before_dump (Any) (defaults to: false)
  • backupdatabases (Any) (defaults to: [])
  • file_per_database (Any) (defaults to: false)
  • include_triggers (Any) (defaults to: false)
  • include_routines (Any) (defaults to: false)
  • ensure (Any) (defaults to: 'present')
  • time (Any) (defaults to: ['23', '5'])
  • prescript (Any) (defaults to: false)
  • postscript (Any) (defaults to: false)
  • execpath (Any) (defaults to: '/usr/bin:/usr/sbin:/bin:/sbin')
  • optional_args (Any) (defaults to: [])
  • mysqlbackupdir_ensure (Any) (defaults to: 'directory')
  • mysqlbackupdir_target (Any) (defaults to: undef)
  • incremental_backups (Any) (defaults to: false)
  • install_cron (Any) (defaults to: true)
  • compression_command (Any) (defaults to: 'bzcat -zc')
  • compression_extension (Any) (defaults to: '.bz2')
  • backupmethod_package (Any) (defaults to: undef)
  • excludedatabases (Array[String]) (defaults to: [])


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'manifests/backup/mysqldump.pp', line 5

class mysql::backup::mysqldump (
  $backupuser               = '',
  Variant[String, Sensitive[String]] $backuppassword = '',
  $backupdir                = '',
  $maxallowedpacket         = '1M',
  $backupdirmode            = '0700',
  $backupdirowner           = 'root',
  $backupdirgroup           = $mysql::params::root_group,
  $backupcompress           = true,
  $backuprotate             = 30,
  $backupmethod             = 'mysqldump',
  $backup_success_file_path = undef,
  $ignore_events            = true,
  $delete_before_dump       = false,
  $backupdatabases          = [],
  $file_per_database        = false,
  $include_triggers         = false,
  $include_routines         = false,
  $ensure                   = 'present',
  $time                     = ['23', '5'],
  $prescript                = false,
  $postscript               = false,
  $execpath                 = '/usr/bin:/usr/sbin:/bin:/sbin',
  $optional_args            = [],
  $mysqlbackupdir_ensure    = 'directory',
  $mysqlbackupdir_target    = undef,
  $incremental_backups      = false,
  $install_cron             = true,
  $compression_command      = 'bzcat -zc',
  $compression_extension    = '.bz2',
  $backupmethod_package     = undef,
  Array[String] $excludedatabases = [],
) inherits mysql::params {
  $backuppassword_unsensitive = if $backuppassword =~ Sensitive {
    $backuppassword.unwrap
  } else {
    $backuppassword
  }

  unless $::osfamily == 'FreeBSD' {
    if $backupcompress and $compression_command == 'bzcat -zc' {
      ensure_packages(['bzip2'])
      Package['bzip2'] -> File['mysqlbackup.sh']
    }
  }

  mysql_user { "${backupuser}@localhost":
    ensure        => $ensure,
    password_hash => mysql::password($backuppassword),
    require       => Class['mysql::server::root_password'],
  }

  if $include_triggers {
    $privs = ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER']
  } else {
    $privs = ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS']
  }

  mysql_grant { "${backupuser}@localhost/*.*":
    ensure     => $ensure,
    user       => "${backupuser}@localhost",
    table      => '*.*',
    privileges => $privs,
    require    => Mysql_user["${backupuser}@localhost"],
  }

  if $install_cron {
    if $::osfamily == 'RedHat' {
      ensure_packages('cronie')
    } elsif $::osfamily != 'FreeBSD' {
      ensure_packages('cron')
    }
  }

  cron { 'mysql-backup':
    ensure   => $ensure,
    command  => '/usr/local/sbin/mysqlbackup.sh',
    user     => 'root',
    hour     => $time[0],
    minute   => $time[1],
    monthday => $time[2],
    month    => $time[3],
    weekday  => $time[4],
    require  => File['mysqlbackup.sh'],
  }

  # TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado
  file { 'mysqlbackup.sh':
    ensure  => $ensure,
    path    => '/usr/local/sbin/mysqlbackup.sh',
    mode    => '0700',
    owner   => 'root',
    group   => $mysql::params::root_group,
    content => template('mysql/mysqlbackup.sh.erb'),
  }

  if $mysqlbackupdir_target {
    file { $backupdir:
      ensure => $mysqlbackupdir_ensure,
      target => $mysqlbackupdir_target,
      mode   => $backupdirmode,
      owner  => $backupdirowner,
      group  => $backupdirgroup,
    }
  } else {
    file { $backupdir:
      ensure => $mysqlbackupdir_ensure,
      mode   => $backupdirmode,
      owner  => $backupdirowner,
      group  => $backupdirgroup,
    }
  }
}