Skip to content

Commit db30274

Browse files
fraenkiDavid Swansheenaajay
authored
(MODULES-10023) Fix multiple xtrabackup regressions (#1245)
* fix xtrabackup target directory and related regressions * fix handling of incremental backups with xtrabackup * MODULES-10023 add parameter $incremental_backups to parent class * MODULES-10023 add acceptance tests for xtrabackup * MODULES-10023 add xtrabackup documentation * MODULES-10023 fix acceptance tests * MODULES-10023 fix xtrabackup tests on CentOS 6 * MODULES-10023 fix xtrabackup tests on Debian 8, Ubuntu 14.04, Scientific 6 * MODULES-10023 fix xtrabackup tests on SLES, RHEL 8 and RHEL/CentOS 5 * MODULES-10023 fix xtrabackup tests on RHEL/CentOS 5 * MODULES-10023 disable new xtrabackup tests on EOL operating systems * (maint) exclude oracle6/centos6 platforms on running the feature tests Co-authored-by: David Swan <david.swan@puppet.co.uk> Co-authored-by: sheena <sheena@puppet.com>
1 parent 39b7bde commit db30274

File tree

9 files changed

+393
-15
lines changed

9 files changed

+393
-15
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [Install Percona server on CentOS](#install-percona-server-on-centos)
1515
* [Install MariaDB on Ubuntu](#install-mariadb-on-ubuntu)
1616
* [Install Plugins](#install-plugins)
17+
* [Use Percona XtraBackup](#use-percona-xtrabackup)
1718
4. [Reference - An under-the-hood peek at what the module is doing and how](REFERENCE.md)
1819
5. [Limitations - OS compatibility, etc.](#limitations)
1920
6. [Development - Guide for contributing to the module](#development)
@@ -392,6 +393,69 @@ mysql::server::db:
392393
### Install Plugins
393394

394395
Plugins can be installed by using the `mysql_plugin` defined type. See `examples/mysql_plugin.pp` for futher examples.
396+
397+
### Use Percona XtraBackup
398+
399+
This example shows how to configure MySQL backups with Percona XtraBackup. This sets up a weekly cronjob to perform a full backup and additional daily cronjobs for incremental backups. Each backup will create a new directory. A cleanup job will automatically remove backups that are older than 15 days.
400+
401+
```puppet
402+
yumrepo { 'percona':
403+
descr => 'CentOS $releasever - Percona',
404+
baseurl => 'http://repo.percona.com/release/$releasever/RPMS/$basearch',
405+
gpgkey => 'https://www.percona.com/downloads/RPM-GPG-KEY-percona https://repo.percona.com/yum/PERCONA-PACKAGING-KEY',
406+
enabled => 1,
407+
gpgcheck => 1,
408+
}
409+
410+
class { 'mysql::server::backup':
411+
backupuser => 'myuser',
412+
backuppassword => 'mypassword',
413+
backupdir => '/tmp/backups',
414+
provider => 'xtrabackup',
415+
rotate => 15,
416+
execpath => '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin',
417+
time => ['23', '15'],
418+
}
419+
```
420+
421+
If the daily or weekly backup was successful, then the empty file `/tmp/mysqlbackup_success` is created, which makes it easy to monitor the status of the database backup.
422+
423+
After two weeks the backup directory should look similar to the example below.
424+
425+
```
426+
/tmp/backups/2019-11-10_full
427+
/tmp/backups/2019-11-11_23-15-01
428+
/tmp/backups/2019-11-13_23-15-01
429+
/tmp/backups/2019-11-13_23-15-02
430+
/tmp/backups/2019-11-14_23-15-01
431+
/tmp/backups/2019-11-15_23-15-02
432+
/tmp/backups/2019-11-16_23-15-01
433+
/tmp/backups/2019-11-17_full
434+
/tmp/backups/2019-11-18_23-15-01
435+
/tmp/backups/2019-11-19_23-15-01
436+
/tmp/backups/2019-11-20_23-15-02
437+
/tmp/backups/2019-11-21_23-15-01
438+
/tmp/backups/2019-11-22_23-15-02
439+
/tmp/backups/2019-11-23_23-15-01
440+
```
441+
442+
A drawback of using incremental backups is the need to keep at least 7 days of backups, otherwise the full backups is removed early and consecutive incremental backups will fail. Furthermore an incremental backups becomes obsolete once the required full backup was removed.
443+
444+
The next example uses XtraBackup with incremental backups disabled. In this case the daily cronjob will always perform a full backup.
445+
446+
```puppet
447+
class { 'mysql::server::backup':
448+
backupuser => 'myuser',
449+
backuppassword => 'mypassword',
450+
backupdir => '/tmp/backups',
451+
provider => 'xtrabackup',
452+
incremental_backups => false,
453+
rotate => 5,
454+
execpath => '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin',
455+
time => ['23', '15'],
456+
}
457+
```
458+
395459
## Reference
396460

397461
### Classes

manifests/backup/mysqlbackup.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
$postscript = false,
2828
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2929
$optional_args = [],
30+
$incremental_backups = false,
3031
) inherits mysql::params {
3132

3233
mysql_user { "${backupuser}@localhost":

manifests/backup/mysqldump.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
$optional_args = [],
2929
$mysqlbackupdir_ensure = 'directory',
3030
$mysqlbackupdir_target = undef,
31+
$incremental_backups = false,
3132
) inherits mysql::params {
3233

3334
unless $::osfamily == 'FreeBSD' {

manifests/backup/xtrabackup.pp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,18 @@
5151
}
5252

5353
if $incremental_backups {
54+
# Warn if old backups are removed too soon. Incremental backups will fail
55+
# if the full backup is no longer available.
56+
if ($backuprotate.convert_to(Integer) < 7) {
57+
warning(translate('The value for `backuprotate` is too low, it must be set to at least 7 days when using incremental backups.'))
58+
}
59+
60+
# The --target-dir uses a more predictable value for the full backup so
61+
# that it can easily be calculated and used in incremental backup jobs.
62+
# Besides that it allows to have multiple full backups.
5463
cron { 'xtrabackup-weekly':
5564
ensure => $ensure,
56-
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}",
65+
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir}/$(date +\\%F)_full ${additional_cron_args}",
5766
user => 'root',
5867
hour => $time[0],
5968
minute => $time[1],
@@ -62,13 +71,23 @@
6271
}
6372
}
6473

74+
# Wether to use GNU or BSD date format.
75+
case $::osfamily {
76+
'FreeBSD','OpenBSD': {
77+
$dateformat = '$(date -v-sun +\\%F)_full'
78+
}
79+
default: {
80+
$dateformat = '$(date -d "last sunday" +\\%F)_full'
81+
}
82+
}
83+
6584
$daily_cron_data = ($incremental_backups) ? {
6685
true => {
67-
'directories' => "--incremental-basedir=${backupdir} --target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)",
86+
'directories' => "--incremental-basedir=${backupdir}/${dateformat} --target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)",
6887
'weekday' => '1-6',
6988
},
7089
false => {
71-
'directories' => "--target-dir=${backupdir}",
90+
'directories' => "--target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)",
7291
'weekday' => '*',
7392
},
7493
}

manifests/params.pp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$client_dev_package_provider = undef
3939
$daemon_dev_package_ensure = 'present'
4040
$daemon_dev_package_provider = undef
41-
$xtrabackup_package_name = 'percona-xtrabackup'
41+
$xtrabackup_package_name_default = 'percona-xtrabackup'
4242

4343

4444
case $::osfamily {
@@ -55,8 +55,12 @@
5555
/^(RedHat|CentOS|Scientific|OracleLinux)$/: {
5656
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
5757
$provider = 'mariadb'
58+
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
59+
$xtrabackup_package_name_override = 'percona-xtrabackup-24'
60+
}
5861
} else {
5962
$provider = 'mysql'
63+
$xtrabackup_package_name_override = 'percona-xtrabackup-20'
6064
}
6165
if versioncmp($::operatingsystemmajrelease, '8') >= 0 {
6266
$java_package_name = 'mariadb-java-client'
@@ -158,6 +162,7 @@
158162
$mycnf_owner = undef
159163
$mycnf_group = undef
160164
$server_service_name = 'mysql'
165+
$xtrabackup_package_name_override = 'xtrabackup'
161166

162167
if $::operatingsystem =~ /(SLES|SLED)/ {
163168
if versioncmp( $::operatingsystemmajrelease, '12' ) >= 0 {
@@ -237,6 +242,10 @@
237242
} else {
238243
$php_package_name = 'php5-mysql'
239244
}
245+
if ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '16.04') < 0) or
246+
($::operatingsystem == 'Debian') {
247+
$xtrabackup_package_name_override = 'percona-xtrabackup-24'
248+
}
240249

241250
$python_package_name = 'python-mysqldb'
242251
$ruby_package_name = $::lsbdistcodename ? {
@@ -548,6 +557,12 @@
548557
},
549558
}
550559

560+
if defined('$xtrabackup_package_name_override') {
561+
$xtrabackup_package_name = pick($xtrabackup_package_name_override, $xtrabackup_package_name_default)
562+
} else {
563+
$xtrabackup_package_name = $xtrabackup_package_name_default
564+
}
565+
551566
## Additional graceful failures
552567
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '4' and $::operatingsystem != 'Amazon' {
553568
fail(translate('Unsupported platform: puppetlabs-%{module_name} only supports RedHat 5.0 and beyond.', {'module_name' => $module_name}))

manifests/server/backup.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
# Dump stored routines (procedures and functions) from dumped databases when doing a `file_per_database` backup.
4949
# @param include_triggers
5050
# Dump triggers for each dumped table when doing a `file_per_database` backup.
51+
# @param incremental_backups
52+
# A flag to activate/deactivate incremental backups. Currently only supported by the xtrabackup provider.
5153
# @param ensure
5254
# @param time
5355
# 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.
@@ -88,6 +90,7 @@
8890
$provider = 'mysqldump',
8991
$maxallowedpacket = '1M',
9092
$optional_args = [],
93+
$incremental_backups = true,
9194
) inherits mysql::params {
9295

9396
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
@@ -120,6 +123,7 @@
120123
'execpath' => $execpath,
121124
'maxallowedpacket' => $maxallowedpacket,
122125
'optional_args' => $optional_args,
126+
'incremental_backups' => $incremental_backups,
123127
}
124128
})
125129
}

0 commit comments

Comments
 (0)