Merge pull request #744 from danzilio/xtrabackup_enhancements

(MODULES-2340) Implement script functionality for xtrabackup provider
This commit is contained in:
JT (Jonny) 2015-08-06 13:57:02 +01:00
commit 2c8a822f25
6 changed files with 89 additions and 2 deletions

View file

@ -16,6 +16,7 @@ class mysql::backup::mysqlbackup (
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {

View file

@ -16,6 +16,7 @@ class mysql::backup::mysqldump (
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {

View file

@ -17,6 +17,7 @@ class mysql::backup::xtrabackup (
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
@ -27,7 +28,7 @@ class mysql::backup::xtrabackup (
cron { 'xtrabackup-weekly':
ensure => $ensure,
command => "innobackupex ${backupdir}",
command => "/usr/local/sbin/xtrabackup.sh ${backupdir}",
user => 'root',
hour => $time[0],
minute => $time[1],
@ -37,7 +38,7 @@ class mysql::backup::xtrabackup (
cron { 'xtrabackup-daily':
ensure => $ensure,
command => "innobackupex --incremental ${backupdir}",
command => "/usr/local/sbin/xtrabackup.sh --incremental ${backupdir}",
user => 'root',
hour => $time[0],
minute => $time[1],
@ -52,4 +53,13 @@ class mysql::backup::xtrabackup (
owner => $backupdirowner,
group => $backupdirgroup,
}
file { 'xtrabackup.sh':
ensure => $ensure,
path => '/usr/local/sbin/xtrabackup.sh',
mode => '0700',
owner => 'root',
group => $mysql::params::root_group,
content => template('mysql/xtrabackup.sh.erb'),
}
}

View file

@ -16,11 +16,16 @@ class mysql::server::backup (
$include_triggers = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$provider = 'mysqldump',
) {
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
warn("The \$prescript option is not currently implemented for the ${provider} backup provider.")
}
create_resources('class', {
"mysql::backup::${provider}" => {
'backupuser' => $backupuser,
@ -39,6 +44,7 @@ class mysql::server::backup (
'include_triggers' => $include_triggers,
'ensure' => $ensure,
'time' => $time,
'prescript' => $prescript,
'postscript' => $postscript,
'execpath' => $execpath,
}

View file

@ -349,6 +349,54 @@ describe 'mysql::server::backup' do
)
end
end
context 'with the xtrabackup provider' do
let(:params) do
default_params.merge({:provider => 'xtrabackup'})
end
it 'should contain the wrapper script' do
is_expected.to contain_file('xtrabackup.sh').with_content(
/^innobackupex\s+"\$@"/
)
end
context 'with prescript defined' do
let(:params) do
default_params.merge({
:provider => 'xtrabackup',
:prescript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]
})
end
it 'should contain the prescript' do
is_expected.to contain_file('xtrabackup.sh').with_content(
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
)
end
end
context 'with postscript defined' do
let(:params) do
default_params.merge({
:provider => 'xtrabackup',
:postscript => [
'rsync -a /tmp backup01.local-lan:',
'rsync -a /tmp backup02.local-lan:',
]
})
end
it 'should contain the prostscript' do
is_expected.to contain_file('xtrabackup.sh').with_content(
/.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/
)
end
end
end
end
end
end

View file

@ -0,0 +1,21 @@
<%- if @kernel == 'Linux' -%>
#!/bin/bash
<%- else -%>
#!/bin/sh
<%- end -%>
#
# A wrapper for Xtrabackup
#
<% if @prescript -%>
<%- [@prescript].flatten.compact.each do |script| %>
<%= script %>
<%- end -%>
<% end -%>
innobackupex "$@"
<% if @postscript -%>
<%- [@postscript].flatten.compact.each do |script| %>
<%= script %>
<%- end -%>
<% end -%>