Puppet Class: mysql::server::backup

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

Summary

Create and manage a MySQL backup.

Overview

Examples:

Create a basic MySQL backup:

class { 'mysql::server':
  root_password           => 'password'
}
class { 'mysql::server::backup':
  backupuser              => 'myuser',
  backuppassword          => 'mypassword',
  backupdir               => '/tmp/backups',
}

Create a basic MySQL backup using mariabackup:

class { 'mysql::server':
  root_password           => 'password'
}
class { 'mysql::server::backup':
  backupmethod            => 'mariabackup',
  backupmethod_package    => 'mariadb-backup'
  provider                => 'xtrabackup',
  backupdir               => '/tmp/backups',
}

Parameters:

  • backupuser (Any) (defaults to: undef)

    MySQL user to create with backup administrator privileges.

  • backuppassword (Optional[Variant[String, Sensitive[String]]]) (defaults to: undef)

    Password to create for ‘backupuser`.

  • backupdir (Any) (defaults to: undef)

    Directory to store backup.

  • backupdirmode (Any) (defaults to: '0700')

    Permissions applied to the backup directory. This parameter is passed directly to the file resource.

  • backupdirowner (Any) (defaults to: 'root')

    Owner for the backup directory. This parameter is passed directly to the file resource.

  • backupdirgroup (Any) (defaults to: $mysql::params::root_group)

    Group owner for the backup directory. This parameter is passed directly to the file resource.

  • backupcompress (Any) (defaults to: true)

    Whether or not to compress the backup (when using the mysqldump or xtrabackup provider)

  • backupmethod (Any) (defaults to: undef)

    The execution binary for backing up. ex. mysqldump, xtrabackup, mariabackup

  • backup_success_file_path (Any) (defaults to: '/tmp/mysqlbackup_success')

    Specify a path where upon successfull backup a file should be created for checking purposes.

  • backuprotate (Any) (defaults to: 30)

    Backup rotation interval in 24 hour periods.

  • ignore_events (Any) (defaults to: true)

    Ignore the mysql.event table.

  • delete_before_dump (Any) (defaults to: false)

    Whether to delete old .sql files before backing up. Setting to true deletes old files before backing up, while setting to false deletes them after backup.

  • backupdatabases (Any) (defaults to: [])

    Databases to backup (required if using xtrabackup provider). By default ‘[]` will back up all databases.

  • file_per_database (Any) (defaults to: false)

    Use file per database mode creating one file per database backup.

  • include_routines (Any) (defaults to: false)

    Dump stored routines (procedures and functions) from dumped databases when doing a ‘file_per_database` backup.

  • include_triggers (Any) (defaults to: false)

    Dump triggers for each dumped table when doing a ‘file_per_database` backup.

  • incremental_backups (Any) (defaults to: true)

    A flag to activate/deactivate incremental backups. Currently only supported by the xtrabackup provider.

  • ensure (Any) (defaults to: 'present')
  • time (Any) (defaults to: ['23', '5'])

    An array of two elements to set the backup time. Allows [‘23’, ‘5’] (i.e., 23:05) or [‘3’, ‘45’] (i.e., 03:45) for HH:MM times.

  • prescript (Any) (defaults to: false)

    A script that is executed before the backup begins.

  • postscript (Any) (defaults to: false)

    A script that is executed when the backup is finished. This could be used to sync the backup to a central store. This script can be either a single line that is directly executed or a number of lines supplied as an array. It could also be one or more externally managed (executable) files.

  • execpath (Any) (defaults to: '/usr/bin:/usr/sbin:/bin:/sbin')

    Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to ‘/usr/bin:/usr/sbin:/bin:/sbin`.

  • provider (Any) (defaults to: 'mysqldump')

    Sets the server backup implementation. Valid values are: xtrabackup, mysqldump, mysqlbackup

  • maxallowedpacket (Any) (defaults to: '1M')

    Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.

  • optional_args (Any) (defaults to: [])

    Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.)

  • install_cron (Any) (defaults to: true)

    Manage installation of cron package

  • compression_command (Any) (defaults to: undef)

    Configure the command used to compress the backup (when using the mysqldump provider). Make sure the command exists on the target system. Packages for it are NOT automatically installed.

  • compression_extension (Any) (defaults to: undef)

    Configure the file extension for the compressed backup (when using the mysqldump provider)

  • backupmethod_package (Any) (defaults to: $mysql::params::xtrabackup_package_name)

    The package which provides the binary specified by the backupmethod parameter.

  • excludedatabases (Array[String]) (defaults to: [])

    Give a list of excluded databases when using file_per_database, e.g.: [ ‘information_schema’, ‘performance_schema’ ]



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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'manifests/server/backup.pp', line 85

class mysql::server::backup (
  $backupuser               = undef,
  Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
  $backupdir                = undef,
  $backupdirmode            = '0700',
  $backupdirowner           = 'root',
  $backupdirgroup           = $mysql::params::root_group,
  $backupcompress           = true,
  $backuprotate             = 30,
  $backupmethod             = undef,
  $backup_success_file_path = '/tmp/mysqlbackup_success',
  $ignore_events            = true,
  $delete_before_dump       = false,
  $backupdatabases          = [],
  $file_per_database        = false,
  $include_routines         = false,
  $include_triggers         = false,
  $ensure                   = 'present',
  $time                     = ['23', '5'],
  $prescript                = false,
  $postscript               = false,
  $execpath                 = '/usr/bin:/usr/sbin:/bin:/sbin',
  $provider                 = 'mysqldump',
  $maxallowedpacket         = '1M',
  $optional_args            = [],
  $incremental_backups      = true,
  $install_cron             = true,
  $compression_command      = undef,
  $compression_extension    = undef,
  $backupmethod_package     = $mysql::params::xtrabackup_package_name,
  Array[String] $excludedatabases = [],
) inherits mysql::params {
  if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
    warning("The 'prescript' option is not currently implemented for the ${provider} backup provider.")
  }

  create_resources('class', {
      "mysql::backup::${provider}" => {
        'backupuser'               => $backupuser,
        'backuppassword'           => $backuppassword,
        'backupdir'                => $backupdir,
        'backupdirmode'            => $backupdirmode,
        'backupdirowner'           => $backupdirowner,
        'backupdirgroup'           => $backupdirgroup,
        'backupcompress'           => $backupcompress,
        'backuprotate'             => $backuprotate,
        'backupmethod'             => $backupmethod,
        'backup_success_file_path' => $backup_success_file_path,
        'ignore_events'            => $ignore_events,
        'delete_before_dump'       => $delete_before_dump,
        'backupdatabases'          => $backupdatabases,
        'file_per_database'        => $file_per_database,
        'include_routines'         => $include_routines,
        'include_triggers'         => $include_triggers,
        'ensure'                   => $ensure,
        'time'                     => $time,
        'prescript'                => $prescript,
        'postscript'               => $postscript,
        'execpath'                 => $execpath,
        'maxallowedpacket'         => $maxallowedpacket,
        'optional_args'            => $optional_args,
        'incremental_backups'      => $incremental_backups,
        'install_cron'             => $install_cron,
        'compression_command'      => $compression_command,
        'compression_extension'    => $compression_extension,
        'backupmethod_package'     => $backupmethod_package,
        'excludedatabases'         => $excludedatabases,
      }
  })
}