diff --git a/manifests/backup/mysqlbackup.pp b/manifests/backup/mysqlbackup.pp index e7bb4d9..3b0d94d 100644 --- a/manifests/backup/mysqlbackup.pp +++ b/manifests/backup/mysqlbackup.pp @@ -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', ) { diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index 77d5e39..543476d 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -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', ) { diff --git a/manifests/backup/xtrabackup.pp b/manifests/backup/xtrabackup.pp index a9c76ba..4dc31f9 100644 --- a/manifests/backup/xtrabackup.pp +++ b/manifests/backup/xtrabackup.pp @@ -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'), + } } diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp index 94e7732..3b1f1ee 100644 --- a/manifests/server/backup.pp +++ b/manifests/server/backup.pp @@ -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, } diff --git a/spec/classes/mysql_server_backup_spec.rb b/spec/classes/mysql_server_backup_spec.rb index ce88ae3..8d19943 100644 --- a/spec/classes/mysql_server_backup_spec.rb +++ b/spec/classes/mysql_server_backup_spec.rb @@ -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 diff --git a/templates/xtrabackup.sh.erb b/templates/xtrabackup.sh.erb new file mode 100644 index 0000000..1449398 --- /dev/null +++ b/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 -%>