diff modules/mysql/manifests/backup/xtrabackup.pp @ 443:c6c9a2cfcfbd

Update MySQL module Fixes a problem with MariaDB and blank certificate paths
author IBBoard <dev@ibboard.co.uk>
date Mon, 08 May 2023 11:48:41 +0100
parents 668df4711671
children adf6fe9bbc17
line wrap: on
line diff
--- a/modules/mysql/manifests/backup/xtrabackup.pp	Mon Apr 03 19:41:02 2023 +0100
+++ b/modules/mysql/manifests/backup/xtrabackup.pp	Mon May 08 11:48:41 2023 +0100
@@ -3,38 +3,39 @@
 # @api private
 #
 class mysql::backup::xtrabackup (
-  $xtrabackup_package_name  = $mysql::params::xtrabackup_package_name,
-  $backupuser               = undef,
-  Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
-  $backupdir                = '',
-  $maxallowedpacket         = '1M',
-  $backupmethod             = 'xtrabackup',
-  $backupdirmode            = '0700',
-  $backupdirowner           = 'root',
-  $backupdirgroup           = $mysql::params::root_group,
-  $backupcompress           = true,
-  $backuprotate             = 30,
-  $backupscript_template    = 'mysql/xtrabackup.sh.erb',
-  $backup_success_file_path = undef,
-  $ignore_events            = true,
-  $delete_before_dump       = false,
-  $backupdatabases          = [],
-  $file_per_database        = false,
-  $include_triggers         = true,
-  $include_routines         = false,
-  $ensure                   = 'present',
-  $time                     = ['23', '5'],
-  $prescript                = false,
-  $postscript               = false,
-  $execpath                 = '/usr/bin:/usr/sbin:/bin:/sbin',
-  $optional_args            = [],
-  $additional_cron_args     = '--backup',
-  $incremental_backups      = true,
-  $install_cron             = true,
-  $compression_command      = undef,
-  $compression_extension    = undef,
+  Optional[String]                              $backupuser               = undef,
+  Optional[Variant[String, Sensitive[String]]]  $backuppassword = undef,
+  String                                        $backupdir                = '',
+  String[1]                                     $maxallowedpacket         = '1M',
+  String[1]                                     $backupmethod             = 'xtrabackup',
+  String[1]                                     $backupdirmode            = '0700',
+  String[1]                                     $backupdirowner           = 'root',
+  String[1]                                     $backupdirgroup           = $mysql::params::root_group,
+  Boolean                                       $backupcompress           = true,
+  Variant[Integer, String[1]]                   $backuprotate             = 30,
+  String[1]                                     $backupscript_template    = 'mysql/xtrabackup.sh.erb',
+  Optional[String[1]]                           $backup_success_file_path = undef,
+  Boolean                                       $ignore_events            = true,
+  Boolean                                       $delete_before_dump       = false,
+  Array[String[1]]                              $backupdatabases          = [],
+  Boolean                                       $file_per_database        = false,
+  Boolean                                       $include_triggers         = true,
+  Boolean                                       $include_routines         = false,
+  Enum['present', 'absent']                     $ensure                   = 'present',
+  Variant[Array[String[1]], Array[Integer]]     $time                     = ['23', '5'],
+  Variant[Boolean, String[1], Array[String[1]]] $prescript                = false,
+  Variant[Boolean, String[1], Array[String[1]]] $postscript               = false,
+  String[1]                                     $execpath                 = '/usr/bin:/usr/sbin:/bin:/sbin',
+  Array[String[1]]                              $optional_args            = [],
+  String[1]                                     $additional_cron_args     = '--backup',
+  Boolean                                       $incremental_backups      = true,
+  Boolean                                       $install_cron             = true,
+  Optional[String[1]]                           $compression_command      = undef,
+  Optional[String[1]]                           $compression_extension    = undef,
+  String[1]                                     $backupmethod_package     = $mysql::params::xtrabackup_package_name,
+  Array[String]                                 $excludedatabases = [],
 ) inherits mysql::params {
-  ensure_packages($xtrabackup_package_name)
+  ensure_packages($backupmethod_package)
 
   $backuppassword_unsensitive = if $backuppassword =~ Sensitive {
     $backuppassword.unwrap
@@ -48,20 +49,69 @@
       password_hash => mysql::password($backuppassword),
       require       => Class['mysql::server::root_password'],
     }
-
-    mysql_grant { "${backupuser}@localhost/*.*":
-      ensure     => $ensure,
-      user       => "${backupuser}@localhost",
-      table      => '*.*',
-      privileges => ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT'],
-      require    => Mysql_user["${backupuser}@localhost"],
+    # Percona XtraBackup needs additional grants/privileges to work with MySQL 8
+    if versioncmp($facts['mysql_version'], '8') >= 0 and !(/(?i:mariadb)/ in $facts['mysqld_version']) {
+      if ($facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['major'], '11') >= 0) or
+      ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '22.04') >= 0) {
+        mysql_grant { "${backupuser}@localhost/*.*":
+          ensure     => $ensure,
+          user       => "${backupuser}@localhost",
+          table      => '*.*',
+          privileges => ['BINLOG MONITOR', 'RELOAD', 'PROCESS', 'LOCK TABLES', 'BACKUP_ADMIN'],
+          require    => Mysql_user["${backupuser}@localhost"],
+        }
+      }
+      else {
+        mysql_grant { "${backupuser}@localhost/*.*":
+          ensure     => $ensure,
+          user       => "${backupuser}@localhost",
+          table      => '*.*',
+          privileges => ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT', 'BACKUP_ADMIN'],
+          require    => Mysql_user["${backupuser}@localhost"],
+        }
+      }
+      mysql_grant { "${backupuser}@localhost/performance_schema.keyring_component_status":
+        ensure     => $ensure,
+        user       => "${backupuser}@localhost",
+        table      => 'performance_schema.keyring_component_status',
+        privileges => ['SELECT'],
+        require    => Mysql_user["${backupuser}@localhost"],
+      }
+      mysql_grant { "${backupuser}@localhost/performance_schema.log_status":
+        ensure     => $ensure,
+        user       => "${backupuser}@localhost",
+        table      => 'performance_schema.log_status',
+        privileges => ['SELECT'],
+        require    => Mysql_user["${backupuser}@localhost"],
+      }
+    }
+    else {
+      if $facts['os']['family'] == 'debian' and $facts['os']['release']['major'] == '11' or
+      ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '22.04') >= 0) {
+        mysql_grant { "${backupuser}@localhost/*.*":
+          ensure     => $ensure,
+          user       => "${backupuser}@localhost",
+          table      => '*.*',
+          privileges => ['BINLOG MONITOR', 'RELOAD', 'PROCESS', 'LOCK TABLES'],
+          require    => Mysql_user["${backupuser}@localhost"],
+        }
+      }
+      else {
+        mysql_grant { "${backupuser}@localhost/*.*":
+          ensure     => $ensure,
+          user       => "${backupuser}@localhost",
+          table      => '*.*',
+          privileges => ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT'],
+          require    => Mysql_user["${backupuser}@localhost"],
+        }
+      }
     }
   }
 
   if $install_cron {
-    if $::osfamily == 'RedHat' {
+    if $facts['os']['family'] == 'RedHat' {
       ensure_packages('cronie')
-    } elsif $::osfamily != 'FreeBSD' {
+    } elsif $facts['os']['family'] != 'FreeBSD' {
       ensure_packages('cron')
     }
   }
@@ -83,12 +133,12 @@
       hour    => $time[0],
       minute  => $time[1],
       weekday => '0',
-      require => Package[$xtrabackup_package_name],
+      require => Package[$backupmethod_package],
     }
   }
 
   # Wether to use GNU or BSD date format.
-  case $::osfamily {
+  case $facts['os']['family'] {
     'FreeBSD','OpenBSD': {
       $dateformat = '$(date -v-sun +\\%F)_full'
     }
@@ -115,7 +165,7 @@
     hour    => $time[0],
     minute  => $time[1],
     weekday => $daily_cron_data['weekday'],
-    require => Package[$xtrabackup_package_name],
+    require => Package[$backupmethod_package],
   }
 
   file { $backupdir: