Skip to content

Commit 056fa5b

Browse files
committed
Add xtrabackup_package_name param to allow usage of mariabackup from the mariadb-backup package
1 parent e73d43c commit 056fa5b

File tree

6 files changed

+56
-23
lines changed

6 files changed

+56
-23
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,30 @@ class { 'mysql::server::backup':
505505
}
506506
```
507507

508+
The next example shows how to use mariabackup (a fork of xtrabackup) as a backup provider.
509+
Note that on most Linux/BSD distributions, this will require setting `backupmethod_package => 'mariadb-backup'` in the `mysql::server::backup` declaration in order to override the default xtrabackup package (`percona-xtrabackup`).
510+
511+
```puppet
512+
class { 'mysql::server':
513+
package_name => 'mariadb-server',
514+
package_ensure => '1:10.3.21+maria~xenial',
515+
service_name => 'mysqld',
516+
root_password => 'AVeryStrongPasswordUShouldEncrypt!',
517+
}
518+
519+
class { 'mysql::server::backup':
520+
backupuser => 'mariabackup',
521+
backuppassword => 'AVeryStrongPasswordUShouldEncrypt!',
522+
provider => 'xtrabackup',
523+
backupmethod => 'mariabackup'
524+
backupmethod_package => 'mariadb-backup',
525+
backupdir => '/tmp/backups',
526+
backuprotate => 15,
527+
execpath => '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin',
528+
time => ['23', '15'],
529+
}
530+
```
531+
508532
## Reference
509533

510534
### Classes

manifests/backup/mysqlbackup.pp

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
$install_cron = true,
3232
$compression_command = undef,
3333
$compression_extension = undef,
34+
$backupmethod_package = undef,
3435
) inherits mysql::params {
3536
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
3637
$backuppassword.unwrap

manifests/backup/mysqldump.pp

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
$incremental_backups = false,
3232
$install_cron = true,
3333
$compression_command = 'bzcat -zc',
34-
$compression_extension = '.bz2'
34+
$compression_extension = '.bz2',
35+
$backupmethod_package = undef,
3536
) inherits mysql::params {
3637
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
3738
$backuppassword.unwrap

manifests/backup/xtrabackup.pp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# @api private
44
#
55
class mysql::backup::xtrabackup (
6-
$xtrabackup_package_name = $mysql::params::xtrabackup_package_name,
76
$backupuser = undef,
87
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
98
$backupdir = '',
@@ -33,8 +32,9 @@
3332
$install_cron = true,
3433
$compression_command = undef,
3534
$compression_extension = undef,
35+
$backupmethod_package = $mysql::params::xtrabackup_package_name,
3636
) inherits mysql::params {
37-
ensure_packages($xtrabackup_package_name)
37+
ensure_packages($backupmethod_package)
3838

3939
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
4040
$backuppassword.unwrap
@@ -94,7 +94,7 @@
9494
hour => $time[0],
9595
minute => $time[1],
9696
weekday => '0',
97-
require => Package[$xtrabackup_package_name],
97+
require => Package[$backupmethod_package],
9898
}
9999
}
100100

@@ -126,7 +126,7 @@
126126
hour => $time[0],
127127
minute => $time[1],
128128
weekday => $daily_cron_data['weekday'],
129-
require => Package[$xtrabackup_package_name],
129+
require => Package[$backupmethod_package],
130130
}
131131

132132
file { $backupdir:

manifests/params.pp

+6-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
$client_dev_package_provider = undef
3838
$daemon_dev_package_ensure = 'present'
3939
$daemon_dev_package_provider = undef
40-
$xtrabackup_package_name_default = 'percona-xtrabackup'
4140

4241
case $::osfamily {
4342
'RedHat': {
@@ -61,11 +60,11 @@
6160
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
6261
$provider = 'mariadb'
6362
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
64-
$xtrabackup_package_name_override = 'percona-xtrabackup-24'
63+
$xtrabackup_package_name = 'percona-xtrabackup-24'
6564
}
6665
} else {
6766
$provider = 'mysql'
68-
$xtrabackup_package_name_override = 'percona-xtrabackup-20'
67+
$xtrabackup_package_name = 'percona-xtrabackup-20'
6968
}
7069
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
7170
$java_package_name = 'mariadb-java-client'
@@ -154,7 +153,7 @@
154153
$mycnf_owner = undef
155154
$mycnf_group = undef
156155
$server_service_name = 'mysql'
157-
$xtrabackup_package_name_override = 'xtrabackup'
156+
$xtrabackup_package_name = 'xtrabackup'
158157

159158
$ssl_ca = '/etc/mysql/cacert.pem'
160159
$ssl_cert = '/etc/mysql/server-cert.pem'
@@ -224,7 +223,7 @@
224223
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '16.04') < 0) or
225224
($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) or
226225
($::operatingsystem == 'Debian') {
227-
$xtrabackup_package_name_override = 'percona-xtrabackup-24'
226+
$xtrabackup_package_name = 'percona-xtrabackup-24'
228227
}
229228
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) or
230229
($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '11') >= 0) {
@@ -511,10 +510,8 @@
511510
},
512511
}
513512

514-
if defined('$xtrabackup_package_name_override') {
515-
$xtrabackup_package_name = pick($xtrabackup_package_name_override, $xtrabackup_package_name_default)
516-
} else {
517-
$xtrabackup_package_name = $xtrabackup_package_name_default
513+
if !defined('$xtrabackup_package_name') {
514+
$xtrabackup_package_name = 'percona-xtrabackup'
518515
}
519516

520517
## Additional graceful failures

manifests/server/backup.pp

+19-9
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
#
44
# @example Create a basic MySQL backup:
55
# class { 'mysql::server':
6-
# root_password => 'password'
6+
# root_password => 'password'
77
# }
88
# class { 'mysql::server::backup':
9-
# backupuser => 'myuser',
10-
# backuppassword => 'mypassword',
11-
# backupdir => '/tmp/backups',
9+
# backupuser => 'myuser',
10+
# backuppassword => 'mypassword',
11+
# backupdir => '/tmp/backups',
12+
# }
13+
#
14+
# @example Create a basic MySQL backup using mariabackup:
15+
# class { 'mysql::server':
16+
# root_password => 'password'
1217
# }
1318
# class { 'mysql::server::backup':
14-
# backupmethod => 'mariabackup',
15-
# provider => 'xtrabackup',
16-
# backupdir => '/tmp/backups',
19+
# backupmethod => 'mariabackup',
20+
# backupmethod_package => 'mariadb-backup'
21+
# provider => 'xtrabackup',
22+
# backupdir => '/tmp/backups',
1723
# }
1824
#
1925
# @param backupuser
@@ -60,7 +66,7 @@
6066
# @param execpath
6167
# Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`.
6268
# @param provider
63-
# Sets the server backup implementation. Valid values are:
69+
# Sets the server backup implementation. Valid values are: xtrabackup, mysqldump, mysqlbackup
6470
# @param maxallowedpacket
6571
# Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.
6672
# @param optional_args
@@ -72,6 +78,8 @@
7278
# on the target system. Packages for it are NOT automatically installed.
7379
# @param compression_extension
7480
# Configure the file extension for the compressed backup (when using the mysqldump provider)
81+
# @param backupmethod_package
82+
# The package which provides the binary specified by the backupmethod parameter.
7583
class mysql::server::backup (
7684
$backupuser = undef,
7785
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
@@ -100,7 +108,8 @@
100108
$incremental_backups = true,
101109
$install_cron = true,
102110
$compression_command = undef,
103-
$compression_extension = undef
111+
$compression_extension = undef,
112+
$backupmethod_package = $mysql::params::xtrabackup_package_name,
104113
) inherits mysql::params {
105114
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
106115
warning("The 'prescript' option is not currently implemented for the ${provider} backup provider.")
@@ -135,6 +144,7 @@
135144
'install_cron' => $install_cron,
136145
'compression_command' => $compression_command,
137146
'compression_extension' => $compression_extension,
147+
'backupmethod_package' => $backupmethod_package,
138148
}
139149
})
140150
}

0 commit comments

Comments
 (0)