Skip to content

Commit 016632e

Browse files
author
Daniel Quackenbush
committed
Add support for dynamic backupmethods/mariabackup
1 parent 2d46d23 commit 016632e

File tree

7 files changed

+27
-10
lines changed

7 files changed

+27
-10
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
$backupdirgroup = 'root',
6565
$backupcompress = true,
6666
$backuprotate = 30,
67+
$backupmethod = undef,
6768
$ignore_events = true,
6869
$delete_before_dump = false,
6970
$backupdatabases = [],
@@ -95,6 +96,7 @@
9596
'backupdirgroup' => $backupdirgroup,
9697
'backupcompress' => $backupcompress,
9798
'backuprotate' => $backuprotate,
99+
'backupmethod' => $backupmethod,
98100
'ignore_events' => $ignore_events,
99101
'delete_before_dump' => $delete_before_dump,
100102
'backupdatabases' => $backupdatabases,

spec/classes/mysql_server_backup_spec.rb

+14-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,19 @@ 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+
)
406+
end
407+
408+
it 'contain the mariabackup executor' do
409+
is_expected.to contain_file('xtrabackup.sh').with_content(
410+
%r{(\n*^mariabackup\s+.*\$@)},
411+
)
412+
end
413+
end
401414
end
402415
end
403416
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)