Skip to content

Add support for mariabackup #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,30 @@ class { 'mysql::server::backup':
}
```

The next example shows how to use mariabackup (a fork of xtrabackup) as a backup provider.
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`).

```puppet
class { 'mysql::server':
package_name => 'mariadb-server',
package_ensure => '1:10.3.21+maria~xenial',
service_name => 'mysqld',
root_password => 'AVeryStrongPasswordUShouldEncrypt!',
}

class { 'mysql::server::backup':
backupuser => 'mariabackup',
backuppassword => 'AVeryStrongPasswordUShouldEncrypt!',
provider => 'xtrabackup',
backupmethod => 'mariabackup'
backupmethod_package => 'mariadb-backup',
backupdir => '/tmp/backups',
backuprotate => 15,
execpath => '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin',
time => ['23', '15'],
}
```

## Reference

### Classes
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/mysqlbackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
$install_cron = true,
$compression_command = undef,
$compression_extension = undef,
$backupmethod_package = undef,
) inherits mysql::params {
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
$backuppassword.unwrap
Expand Down
3 changes: 2 additions & 1 deletion manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
$incremental_backups = false,
$install_cron = true,
$compression_command = 'bzcat -zc',
$compression_extension = '.bz2'
$compression_extension = '.bz2',
$backupmethod_package = undef,
) inherits mysql::params {
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
$backuppassword.unwrap
Expand Down
8 changes: 4 additions & 4 deletions manifests/backup/xtrabackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# @api private
#
class mysql::backup::xtrabackup (
$xtrabackup_package_name = $mysql::params::xtrabackup_package_name,
$backupuser = undef,
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
$backupdir = '',
Expand Down Expand Up @@ -33,8 +32,9 @@
$install_cron = true,
$compression_command = undef,
$compression_extension = undef,
$backupmethod_package = $mysql::params::xtrabackup_package_name,
) inherits mysql::params {
ensure_packages($xtrabackup_package_name)
ensure_packages($backupmethod_package)

$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
$backuppassword.unwrap
Expand Down Expand Up @@ -94,7 +94,7 @@
hour => $time[0],
minute => $time[1],
weekday => '0',
require => Package[$xtrabackup_package_name],
require => Package[$backupmethod_package],
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@
hour => $time[0],
minute => $time[1],
weekday => $daily_cron_data['weekday'],
require => Package[$xtrabackup_package_name],
require => Package[$backupmethod_package],
}

file { $backupdir:
Expand Down
15 changes: 6 additions & 9 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
$client_dev_package_provider = undef
$daemon_dev_package_ensure = 'present'
$daemon_dev_package_provider = undef
$xtrabackup_package_name_default = 'percona-xtrabackup'

case $::osfamily {
'RedHat': {
Expand All @@ -61,11 +60,11 @@
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
$provider = 'mariadb'
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
$xtrabackup_package_name_override = 'percona-xtrabackup-24'
$xtrabackup_package_name = 'percona-xtrabackup-24'
}
} else {
$provider = 'mysql'
$xtrabackup_package_name_override = 'percona-xtrabackup-20'
$xtrabackup_package_name = 'percona-xtrabackup-20'
}
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
$java_package_name = 'mariadb-java-client'
Expand Down Expand Up @@ -154,7 +153,7 @@
$mycnf_owner = undef
$mycnf_group = undef
$server_service_name = 'mysql'
$xtrabackup_package_name_override = 'xtrabackup'
$xtrabackup_package_name = 'xtrabackup'

$ssl_ca = '/etc/mysql/cacert.pem'
$ssl_cert = '/etc/mysql/server-cert.pem'
Expand Down Expand Up @@ -224,7 +223,7 @@
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '16.04') < 0) or
($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) or
($::operatingsystem == 'Debian') {
$xtrabackup_package_name_override = 'percona-xtrabackup-24'
$xtrabackup_package_name = 'percona-xtrabackup-24'
}
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '20.04') >= 0) or
($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '11') >= 0) {
Expand Down Expand Up @@ -511,10 +510,8 @@
},
}

if defined('$xtrabackup_package_name_override') {
$xtrabackup_package_name = pick($xtrabackup_package_name_override, $xtrabackup_package_name_default)
} else {
$xtrabackup_package_name = $xtrabackup_package_name_default
if !defined('$xtrabackup_package_name') {
$xtrabackup_package_name = 'percona-xtrabackup'
}

## Additional graceful failures
Expand Down
28 changes: 19 additions & 9 deletions manifests/server/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
#
# @example Create a basic MySQL backup:
# class { 'mysql::server':
# root_password => 'password'
# root_password => 'password'
# }
# class { 'mysql::server::backup':
# backupuser => 'myuser',
# backuppassword => 'mypassword',
# backupdir => '/tmp/backups',
# backupuser => 'myuser',
# backuppassword => 'mypassword',
# backupdir => '/tmp/backups',
# }
#
# @example Create a basic MySQL backup using mariabackup:
# class { 'mysql::server':
# root_password => 'password'
# }
# class { 'mysql::server::backup':
# backupmethod => 'mariabackup',
# provider => 'xtrabackup',
# backupdir => '/tmp/backups',
# backupmethod => 'mariabackup',
# backupmethod_package => 'mariadb-backup'
# provider => 'xtrabackup',
# backupdir => '/tmp/backups',
# }
#
# @param backupuser
Expand Down Expand Up @@ -60,7 +66,7 @@
# @param execpath
# Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`.
# @param provider
# Sets the server backup implementation. Valid values are:
# Sets the server backup implementation. Valid values are: xtrabackup, mysqldump, mysqlbackup
# @param maxallowedpacket
# Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.
# @param optional_args
Expand All @@ -72,6 +78,8 @@
# on the target system. Packages for it are NOT automatically installed.
# @param compression_extension
# Configure the file extension for the compressed backup (when using the mysqldump provider)
# @param backupmethod_package
# The package which provides the binary specified by the backupmethod parameter.
class mysql::server::backup (
$backupuser = undef,
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
Expand Down Expand Up @@ -100,7 +108,8 @@
$incremental_backups = true,
$install_cron = true,
$compression_command = undef,
$compression_extension = undef
$compression_extension = undef,
$backupmethod_package = $mysql::params::xtrabackup_package_name,
) inherits mysql::params {
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
warning("The 'prescript' option is not currently implemented for the ${provider} backup provider.")
Expand Down Expand Up @@ -135,6 +144,7 @@
'install_cron' => $install_cron,
'compression_command' => $compression_command,
'compression_extension' => $compression_extension,
'backupmethod_package' => $backupmethod_package,
}
})
}
3 changes: 2 additions & 1 deletion spec/classes/mysql_backup_xtrabackup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class { 'mysql::server': }

context 'with mariabackup' do
let(:params) do
{ backupmethod: 'mariabackup' }.merge(default_params)
{ backupmethod: 'mariabackup',
backupmethod_package: 'mariadb-backup' }.merge(default_params)
end

it 'contain the mariabackup executor' do
Expand Down