Skip to content

Commit 124c9ea

Browse files
authored
Merge pull request #1171 from danquack/mariabackup
Add support for dynamic backupmethods/mariabackup
2 parents 879e431 + a754e1f commit 124c9ea

9 files changed

+35
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ Plugins can be installed by using the `mysql_plugin` defined type. See `examples
421421
* `mysql::client::install`: Installs MySQL client.
422422
* `mysql::backup::mysqldump`: Implements mysqldump backups.
423423
* `mysql::backup::mysqlbackup`: Implements backups with Oracle MySQL Enterprise Backup.
424-
* `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona.
424+
* `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona or Mariabackup.
425425

426426
### Parameters
427427

REFERENCE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _Private Classes_
1818

1919
* `mysql::backup::mysqlbackup`: Manage the mysqlbackup client.
2020
* `mysql::backup::mysqldump`: "Provider" for mysqldump
21-
* `mysql::backup::xtrabackup`: "Provider" for Percona XtraBackup
21+
* `mysql::backup::xtrabackup`: "Provider" for Percona XtraBackup or MariaBackup
2222
* `mysql::bindings::client_dev`: Private class for installing client development bindings
2323
* `mysql::bindings::daemon_dev`: Private class for installing daemon development bindings
2424
* `mysql::bindings::java`: Private class for installing java language bindings.

manifests/backup/mysqlbackup.pp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
$backupdirgroup = $mysql::params::root_group,
1414
$backupcompress = true,
1515
$backuprotate = 30,
16+
$backupmethod = '',
1617
$ignore_events = true,
1718
$delete_before_dump = false,
1819
$backupdatabases = [],

manifests/backup/mysqldump.pp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
$backupdirgroup = $mysql::params::root_group,
1313
$backupcompress = true,
1414
$backuprotate = 30,
15+
$backupmethod = 'mysqldump',
1516
$ignore_events = true,
1617
$delete_before_dump = false,
1718
$backupdatabases = [],

manifests/backup/xtrabackup.pp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# @summary
2-
# "Provider" for Percona XtraBackup
2+
# "Provider" for Percona XtraBackup/MariaBackup
33
# @api private
44
#
55
class mysql::backup::xtrabackup (
@@ -8,7 +8,7 @@
88
$backuppassword = undef,
99
$backupdir = '',
1010
$maxallowedpacket = '1M',
11-
$backupmethod = 'mysqldump',
11+
$backupmethod = 'xtrabackup',
1212
$backupdirmode = '0700',
1313
$backupdirowner = 'root',
1414
$backupdirgroup = $mysql::params::root_group,
@@ -26,7 +26,7 @@
2626
$postscript = false,
2727
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2828
$optional_args = [],
29-
$additional_cron_args = ''
29+
$additional_cron_args = '--backup'
3030
) inherits mysql::params {
3131

3232
ensure_packages($xtrabackup_package_name)
@@ -49,7 +49,7 @@
4949

5050
cron { 'xtrabackup-weekly':
5151
ensure => $ensure,
52-
command => "/usr/local/sbin/xtrabackup.sh ${backupdir} ${additional_cron_args}",
52+
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}",
5353
user => 'root',
5454
hour => $time[0],
5555
minute => $time[1],
@@ -59,7 +59,7 @@
5959

6060
cron { 'xtrabackup-daily':
6161
ensure => $ensure,
62-
command => "/usr/local/sbin/xtrabackup.sh --incremental ${backupdir} ${additional_cron_args}",
62+
command => "/usr/local/sbin/xtrabackup.sh --incremental-basedir=${backupdir} --target-dir=${backupdir}/`date +%F_%H-%M-%S` ${additional_cron_args}",
6363
user => 'root',
6464
hour => $time[0],
6565
minute => $time[1],

manifests/server/backup.pp

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
# backuppassword => 'mypassword',
1111
# backupdir => '/tmp/backups',
1212
# }
13+
# class { 'mysql::server::backup':
14+
# backupmethod => 'mariabackup',
15+
# provider => 'xtrabackup',
16+
# backupdir => '/tmp/backups',
17+
# }
1318
#
1419
# @param backupuser
1520
# MySQL user with backup administrator privileges.
@@ -25,6 +30,8 @@
2530
# Group owner for the backup directory. This parameter is passed directly to the file resource.
2631
# @param backupcompress
2732
# Whether or not to compress the backup (when using the mysqldump provider)
33+
# @param backupmethod
34+
# The execution binary for backing up. ex. mysqldump, xtrabackup, mariabackup
2835
# @param backuprotate
2936
# Backup rotation interval in 24 hour periods.
3037
# @param ignore_events
@@ -64,6 +71,7 @@
6471
$backupdirgroup = 'root',
6572
$backupcompress = true,
6673
$backuprotate = 30,
74+
$backupmethod = undef,
6775
$ignore_events = true,
6876
$delete_before_dump = false,
6977
$backupdatabases = [],
@@ -95,6 +103,7 @@
95103
'backupdirgroup' => $backupdirgroup,
96104
'backupcompress' => $backupcompress,
97105
'backuprotate' => $backuprotate,
106+
'backupmethod' => $backupmethod,
98107
'ignore_events' => $ignore_events,
99108
'delete_before_dump' => $delete_before_dump,
100109
'backupdatabases' => $backupdatabases,

spec/classes/mysql_server_backup_spec.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class { 'mysql::server': }
363363

364364
it 'contains the wrapper script' do
365365
is_expected.to contain_file('xtrabackup.sh').with_content(
366-
%r{^innobackupex\s+.*?"\$@"},
366+
%r{(\n*^xtrabackup\s+.*\$@)},
367367
)
368368
end
369369

@@ -398,6 +398,18 @@ class { 'mysql::server': }
398398
)
399399
end
400400
end
401+
context 'with mariabackup' do
402+
let(:params) do
403+
default_params.merge(provider: 'xtrabackup',
404+
backupmethod: 'mariabackup')
405+
end
406+
407+
it 'contain the mariabackup executor' do
408+
is_expected.to contain_file('xtrabackup.sh').with_content(
409+
%r{(\n*^mariabackup\s+.*\$@)},
410+
)
411+
end
412+
end
401413
end
402414
end
403415
end

templates/mysqlbackup.sh.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ cleanup
9191
<% if @file_per_database -%>
9292
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname
9393
do
94-
mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
94+
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
9595
${ADDITIONAL_OPTIONS} \
9696
${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
9797
done
9898
<% else -%>
99-
mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
99+
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
100100
${ADDITIONAL_OPTIONS} \
101101
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
102102
<% end -%>
103103
<% else -%>
104104
<% @backupdatabases.each do |db| -%>
105-
mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
105+
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
106106
${ADDITIONAL_OPTIONS} \
107107
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
108108
<% end -%>

templates/xtrabackup.sh.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<%- end -%>
2929
<%- end -%>
3030

31-
innobackupex <%= _innobackupex_args %> "$@"
31+
<%= @backupmethod -%> <%= _innobackupex_args %> $@
3232

3333
<% if @postscript -%>
3434
<%- [@postscript].flatten.compact.each do |script| %>

0 commit comments

Comments
 (0)