Skip to content

Commit

Permalink
Merge pull request #744 from danzilio/xtrabackup_enhancements
Browse files Browse the repository at this point in the history
(MODULES-2340) Implement script functionality for xtrabackup provider
  • Loading branch information
jonnytdevops committed Aug 6, 2015
2 parents 8dcb82c + a7a5c66 commit 2c8a822
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions manifests/backup/mysqlbackup.pp
Expand Up @@ -16,6 +16,7 @@
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/mysqldump.pp
Expand Up @@ -16,6 +16,7 @@
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
Expand Down
14 changes: 12 additions & 2 deletions manifests/backup/xtrabackup.pp
Expand Up @@ -17,6 +17,7 @@
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
Expand All @@ -27,7 +28,7 @@

cron { 'xtrabackup-weekly':
ensure => $ensure,
command => "innobackupex ${backupdir}",
command => "/usr/local/sbin/xtrabackup.sh ${backupdir}",
user => 'root',
hour => $time[0],
minute => $time[1],
Expand All @@ -37,7 +38,7 @@

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],
Expand All @@ -52,4 +53,13 @@
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'),
}
}
6 changes: 6 additions & 0 deletions manifests/server/backup.pp
Expand Up @@ -16,11 +16,16 @@
$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,
Expand All @@ -39,6 +44,7 @@
'include_triggers' => $include_triggers,
'ensure' => $ensure,
'time' => $time,
'prescript' => $prescript,
'postscript' => $postscript,
'execpath' => $execpath,
}
Expand Down
48 changes: 48 additions & 0 deletions spec/classes/mysql_server_backup_spec.rb
Expand Up @@ -349,6 +349,54 @@
)
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
Expand Down
21 changes: 21 additions & 0 deletions templates/xtrabackup.sh.erb
@@ -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 -%>

0 comments on commit 2c8a822

Please sign in to comment.