Skip to content

Commit a7a5c66

Browse files
author
David Danzilio
committed
Add support for postscript for xtrabackup provider
This commit implements the 'postscript' functionality for the xtrabackup provider. It also adds a 'prescript' option to be executed before a backup.
1 parent e3c9932 commit a7a5c66

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

manifests/backup/mysqlbackup.pp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
$include_routines = false,
1717
$ensure = 'present',
1818
$time = ['23', '5'],
19+
$prescript = false,
1920
$postscript = false,
2021
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2122
) {

manifests/backup/mysqldump.pp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
$include_routines = false,
1717
$ensure = 'present',
1818
$time = ['23', '5'],
19+
$prescript = false,
1920
$postscript = false,
2021
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2122
) {

manifests/backup/xtrabackup.pp

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
$include_routines = false,
1818
$ensure = 'present',
1919
$time = ['23', '5'],
20+
$prescript = false,
2021
$postscript = false,
2122
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2223
) {
@@ -27,7 +28,7 @@
2728

2829
cron { 'xtrabackup-weekly':
2930
ensure => $ensure,
30-
command => "innobackupex ${backupdir}",
31+
command => "/usr/local/sbin/xtrabackup.sh ${backupdir}",
3132
user => 'root',
3233
hour => $time[0],
3334
minute => $time[1],
@@ -37,7 +38,7 @@
3738

3839
cron { 'xtrabackup-daily':
3940
ensure => $ensure,
40-
command => "innobackupex --incremental ${backupdir}",
41+
command => "/usr/local/sbin/xtrabackup.sh --incremental ${backupdir}",
4142
user => 'root',
4243
hour => $time[0],
4344
minute => $time[1],
@@ -52,4 +53,13 @@
5253
owner => $backupdirowner,
5354
group => $backupdirgroup,
5455
}
56+
57+
file { 'xtrabackup.sh':
58+
ensure => $ensure,
59+
path => '/usr/local/sbin/xtrabackup.sh',
60+
mode => '0700',
61+
owner => 'root',
62+
group => $mysql::params::root_group,
63+
content => template('mysql/xtrabackup.sh.erb'),
64+
}
5565
}

manifests/server/backup.pp

+6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
$include_triggers = false,
1717
$ensure = 'present',
1818
$time = ['23', '5'],
19+
$prescript = false,
1920
$postscript = false,
2021
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2122
$provider = 'mysqldump',
2223
) {
2324

25+
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
26+
warn("The \$prescript option is not currently implemented for the ${provider} backup provider.")
27+
}
28+
2429
create_resources('class', {
2530
"mysql::backup::${provider}" => {
2631
'backupuser' => $backupuser,
@@ -39,6 +44,7 @@
3944
'include_triggers' => $include_triggers,
4045
'ensure' => $ensure,
4146
'time' => $time,
47+
'prescript' => $prescript,
4248
'postscript' => $postscript,
4349
'execpath' => $execpath,
4450
}

spec/classes/mysql_server_backup_spec.rb

+48
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,54 @@
349349
)
350350
end
351351
end
352+
353+
context 'with the xtrabackup provider' do
354+
let(:params) do
355+
default_params.merge({:provider => 'xtrabackup'})
356+
end
357+
358+
it 'should contain the wrapper script' do
359+
is_expected.to contain_file('xtrabackup.sh').with_content(
360+
/^innobackupex\s+"\$@"/
361+
)
362+
end
363+
364+
context 'with prescript defined' do
365+
let(:params) do
366+
default_params.merge({
367+
:provider => 'xtrabackup',
368+
:prescript => [
369+
'rsync -a /tmp backup01.local-lan:',
370+
'rsync -a /tmp backup02.local-lan:',
371+
]
372+
})
373+
end
374+
375+
it 'should contain the prescript' do
376+
is_expected.to contain_file('xtrabackup.sh').with_content(
377+
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
378+
)
379+
end
380+
end
381+
382+
context 'with postscript defined' do
383+
let(:params) do
384+
default_params.merge({
385+
:provider => 'xtrabackup',
386+
:postscript => [
387+
'rsync -a /tmp backup01.local-lan:',
388+
'rsync -a /tmp backup02.local-lan:',
389+
]
390+
})
391+
end
392+
393+
it 'should contain the prostscript' do
394+
is_expected.to contain_file('xtrabackup.sh').with_content(
395+
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
396+
)
397+
end
398+
end
399+
end
352400
end
353401
end
354402
end

templates/xtrabackup.sh.erb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<%- if @kernel == 'Linux' -%>
2+
#!/bin/bash
3+
<%- else -%>
4+
#!/bin/sh
5+
<%- end -%>
6+
#
7+
# A wrapper for Xtrabackup
8+
#
9+
<% if @prescript -%>
10+
<%- [@prescript].flatten.compact.each do |script| %>
11+
<%= script %>
12+
<%- end -%>
13+
<% end -%>
14+
15+
innobackupex "$@"
16+
17+
<% if @postscript -%>
18+
<%- [@postscript].flatten.compact.each do |script| %>
19+
<%= script %>
20+
<%- end -%>
21+
<% end -%>

0 commit comments

Comments
 (0)