diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4aca98123..f962f9fa7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -95,6 +95,7 @@ RSpec/NamedSubject: - 'spec/classes/mysql_server_spec.rb' - 'spec/defines/mysql_db_spec.rb' - 'spec/functions/mysql_normalise_and_deepmerge_spec.rb' + - 'spec/functions/mysql_innobackupex_args_spec.rb' - 'spec/functions/mysql_strip_hash_spec.rb' # Offense count: 45 diff --git a/lib/puppet/functions/mysql/innobackupex_args.rb b/lib/puppet/functions/mysql/innobackupex_args.rb new file mode 100644 index 000000000..e9cc12064 --- /dev/null +++ b/lib/puppet/functions/mysql/innobackupex_args.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# @summary this function populates and returns the string of arguments which later gets injected in template. +# arguments that return string holds is conditional and decided by the the input given to function. + +Puppet::Functions.create_function(:'mysql::innobackupex_args') do + # @param args + # String backupuser + # Boolean backupcompress + # String backuppassword_unsensitive + # Array backupdatabases + # Array optional_args + # + # @return String + # Generated on the basis of provided values. + # + dispatch :innobackupex_args do + required_param 'Optional[String]', :backupuser + required_param 'Boolean', :backupcompress + required_param 'Optional[Variant[String, Sensitive[String]]]', :backuppassword_unsensitive + required_param 'Array[String[1]]', :backupdatabases + required_param 'Array[String[1]]', :optional_args + return_type 'Variant[String]' + end + + def innobackupex_args(backupuser, backupcompress, backuppassword_unsensitive, backupdatabases, optional_args) + innobackupex_args = '' + innobackupex_args = "--user=\"#{backupuser}\" --password=\"#{backuppassword_unsensitive}\"" if backupuser && backuppassword_unsensitive + + innobackupex_args = "#{innobackupex_args} --compress" if backupcompress + + innobackupex_args = "#{innobackupex_args} --databases=\"#{backupdatabases.join(' ')}\"" if backupdatabases.is_a?(Array) && !backupdatabases.empty? + + if optional_args.is_a?(Array) + optional_args.each do |arg| + innobackupex_args = "#{innobackupex_args} #{arg}" + end + end + innobackupex_args + end +end diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index c41c5a14d..2fba423c5 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -88,6 +88,30 @@ require => File['mysqlbackup.sh'], } + $parameters = { + 'backupuser'=> $backupuser, + 'backuppassword_unsensitive'=> $backuppassword_unsensitive, + 'maxallowedpacket'=> $maxallowedpacket, + 'backupdir'=> $backupdir, + 'backuprotate'=> $backuprotate, + 'prescript'=> $prescript, + 'ignore_events'=> $ignore_events, + 'backupdatabases'=> $backupdatabases, + 'include_triggers'=> $include_triggers, + 'optional_args'=> $optional_args, + 'execpath'=> $execpath, + 'delete_before_dump'=> $delete_before_dump, + 'excludedatabases'=> $excludedatabases, + 'backupmethod'=> $backupmethod, + 'backupcompress'=> $backupcompress, + 'compression_command'=> $compression_command, + 'compression_extension'=> $compression_extension, + 'backup_success_file_path'=> $backup_success_file_path, + 'postscript'=> $postscript, + 'file_per_database'=> $file_per_database, + 'include_routines' => $include_routines, + } + # TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado file { 'mysqlbackup.sh': ensure => $ensure, @@ -95,7 +119,7 @@ mode => '0700', owner => 'root', group => $mysql::params::root_group, - content => template('mysql/mysqlbackup.sh.erb'), + content => epp('mysql/mysqlbackup.sh.epp',$parameters), } if $mysqlbackupdir_target { diff --git a/manifests/backup/xtrabackup.pp b/manifests/backup/xtrabackup.pp index d60822a5f..c73831f38 100644 --- a/manifests/backup/xtrabackup.pp +++ b/manifests/backup/xtrabackup.pp @@ -13,7 +13,7 @@ String[1] $backupdirgroup = $mysql::params::root_group, Boolean $backupcompress = true, Variant[Integer, String[1]] $backuprotate = 30, - String[1] $backupscript_template = 'mysql/xtrabackup.sh.erb', + String[1] $backupscript_template = 'mysql/xtrabackup.sh.epp', Optional[String[1]] $backup_success_file_path = undef, Boolean $ignore_events = true, Boolean $delete_before_dump = false, @@ -176,12 +176,23 @@ } # TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado + $parameters = { + 'innobackupex_args' => mysql::innobackupex_args($backupuser, $backupcompress, $backuppassword_unsensitive, $backupdatabases, $optional_args), + 'backuprotate' => $backuprotate, + 'backupdir' => $backupdir, + 'backupmethod' => $backupmethod, + 'delete_before_dump' => $delete_before_dump, + 'prescript' => $prescript, + 'backup_success_file_path'=> $backup_success_file_path, + 'postscript'=> $postscript, + } + file { 'xtrabackup.sh': ensure => $ensure, path => '/usr/local/sbin/xtrabackup.sh', mode => '0700', owner => 'root', group => $mysql::params::root_group, - content => template($backupscript_template), + content => epp($backupscript_template,$parameters), } } diff --git a/manifests/server/config.pp b/manifests/server/config.pp index 8b6717a83..d45ccf4d1 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -61,10 +61,15 @@ default: {} } + $parameters= { + 'options' => $options, + 'includedir' => $includedir, + } + if $mysql::server::manage_config_file { file { 'mysql-config-file': path => $mysql::server::config_file, - content => template('mysql/my.cnf.erb'), + content => epp('mysql/my.cnf.epp', $parameters), mode => $mysql::server::config_file_mode, owner => $mysql::server::mycnf_owner, group => $mysql::server::mycnf_group, diff --git a/manifests/server/root_password.pp b/manifests/server/root_password.pp index a182f6787..91b047626 100644 --- a/manifests/server/root_password.pp +++ b/manifests/server/root_password.pp @@ -37,10 +37,16 @@ } } + $parameters = { + 'root_password_set' => $root_password_set, + 'root_password' => $root_password, + 'options' => $options, + } + if $mysql::server::create_root_my_cnf and $root_password_set { # TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado file { "${facts['root_home']}/.my.cnf": - content => template('mysql/my.cnf.pass.erb'), + content => epp('mysql/my.cnf.pass.epp',$parameters), owner => 'root', mode => '0600', } diff --git a/spec/functions/mysql_innobackupex_args_spec.rb b/spec/functions/mysql_innobackupex_args_spec.rb new file mode 100644 index 000000000..36be79ca7 --- /dev/null +++ b/spec/functions/mysql_innobackupex_args_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'mysql::innobackupex_args' do + it 'exists' do + expect(subject).not_to be_nil + end + + it 'accepts empty strings as puppet undef' do + expect(subject).to run.with_params('', true, '', [], []) + end + + context 'should work with username and password' do + it 'returns args with username and password' do + expect(subject).to run.with_params('root', false, '12345', [], []).and_return('--user="root" --password="12345"') + end + + it 'returns args with database lists' do + expect(subject).to run.with_params('root', false, '12345', ['db1', 'db2'], []).and_return('--user="root" --password="12345" --databases="db1 db2"') + end + + it 'returns args with backup compress only' do + expected_results = '--user="root" --password="12345" --compress' + expect(subject).to run.with_params('root', true, '12345', [], []).and_return(expected_results) + end + + it 'returns args with backup compress, database list and optional_args' do + expected_results = '--user="root" --password="12345" --compress --databases="db1 db2" tst_arg_1 tst_arg_2' + expect(subject).to run.with_params('root', true, '12345', ['db1', 'db2'], ['tst_arg_1', 'tst_arg_2']).and_return(expected_results) + end + end + + context 'should work without database args' do + it 'returns args without database list' do + expect(subject).to run.with_params('root', false, '12345', [], []).and_return('--user="root" --password="12345"') + end + end + + it 'returns args without backup compress' do + expect(subject).to run.with_params('root', false, '12345', [], []).and_return('--user="root" --password="12345"') + end + + it 'returns args with backup compress and database list' do + expected_results = '--user="root" --password="12345" --compress --databases="db1 db2"' + expect(subject).to run.with_params('root', true, '12345', ['db1', 'db2'], []).and_return(expected_results) + end + + it 'returns args without backup compress database list and optional_args' do + expected_results = '--user="root" --password="12345" --databases="db1 db2" tst_arg_1 tst_arg_2' + expect(subject).to run.with_params('root', false, '12345', ['db1', 'db2'], ['tst_arg_1', 'tst_arg_2']).and_return(expected_results) + end + + it 'returns args without backup compress database list and with optional_args' do + expected_results = '--user="root" --password="12345" tst_arg_1 tst_arg_2' + expect(subject).to run.with_params('root', false, '12345', [], ['tst_arg_1', 'tst_arg_2']).and_return(expected_results) + end +end diff --git a/templates/my.cnf.epp b/templates/my.cnf.epp new file mode 100644 index 000000000..7371164c3 --- /dev/null +++ b/templates/my.cnf.epp @@ -0,0 +1,25 @@ +### MANAGED BY PUPPET ### + +<% sort($options.map |$key, $value| { [$key, $value] }).map |$v| { -%> +<% if type($v[1]) =~ Type[Hash] { -%> +[<%= $v[0] %>] +<%sort($v[1].map |$key, $value| { [$key, $value] }).map |$vi| { -%> +<%- if ($vi[0] == 'ssl-disable') or ($vi[0] =~ /^ssl/ and $v[1]['ssl-disable'] == true) or ($vi[0] =~ /^ssl-/ and $v[1]['ssl'] == false) { -%> +<%- next -%> +<%- } elsif $vi[1] == true or $vi[1] == '' { -%> +<%= $vi[0] -%> +<%- } elsif type($vi[1]) =~ Type[Array] { -%> +<%- $vi[1].each |$vii| { -%> +<%-$base = $vi[0]-%> +<%= $base %> = <%= $vii %> +<%- } -%> +<%- } elsif !($vi[1] ==nil or $vi[1]=='' or $vi[1]==undef) { -%> +<%-$base = $vi[0]-%> +<%= $base %> = <%= $vi[1] -%> +<% } %> +<% } %> +<% } %> +<% } %> +<% if $includedir and $includedir != '' { -%> +!includedir <%= $includedir %> +<% } -%> diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb deleted file mode 100644 index 3680d81d0..000000000 --- a/templates/my.cnf.erb +++ /dev/null @@ -1,24 +0,0 @@ -### MANAGED BY PUPPET ### - -<% @options.sort.map do |k,v| -%> -<% if v.is_a?(Hash) -%> -[<%= k %>] -<% v.sort.map do |ki, vi| -%> -<% if ki == 'ssl-disable' or (ki =~ /^ssl/ and v['ssl-disable'] == true) or (ki =~ /^ssl-/ and v['ssl'] == false) -%> -<% next %> -<% elsif vi == true or vi == '' -%> -<%= ki %> -<% elsif vi.is_a?(Array) -%> -<% vi.each do |vii| -%> -<%= ki %> = <%= vii %> -<% end -%> -<% elsif ![nil, '', :undef].include?(vi) -%> -<%= ki %> = <%= vi %> -<% end -%> -<% end -%> -<% end %> -<% end -%> - -<% if @includedir and @includedir != '' %> -!includedir <%= @includedir %> -<% end %> diff --git a/templates/my.cnf.pass.epp b/templates/my.cnf.pass.epp new file mode 100644 index 000000000..1c59732ac --- /dev/null +++ b/templates/my.cnf.pass.epp @@ -0,0 +1,9 @@ +<%['mysql', 'client', 'mysqldump', 'mysqladmin', 'mysqlcheck'].each |$section| { %> +[<%= $section -%>] +user=root +host=localhost +<% if $root_password_set { -%> +password='<%= $root_password %>' +<% } -%> +socket=<%= $options['client']['socket'] %> +<% } %> diff --git a/templates/my.cnf.pass.erb b/templates/my.cnf.pass.erb deleted file mode 100644 index 9f9d03890..000000000 --- a/templates/my.cnf.pass.erb +++ /dev/null @@ -1,11 +0,0 @@ -### MANAGED BY PUPPET ### - -<% %w(mysql client mysqldump mysqladmin mysqlcheck).each do |section| %> -[<%= section -%>] -user=root -host=localhost -<% if @root_password_set -%> -password='<%= @root_password %>' -<% end -%> -socket=<%= @options['client']['socket'] %> -<% end %> diff --git a/templates/mysqlbackup.sh.epp b/templates/mysqlbackup.sh.epp new file mode 100644 index 000000000..f1301043b --- /dev/null +++ b/templates/mysqlbackup.sh.epp @@ -0,0 +1,121 @@ +<%- if $kernel == 'Linux' { -%> +#!/bin/bash +<%- } else { -%> +#!/bin/sh +<%- } -%> +# +# MySQL Backup Script +# Dumps mysql databases to a file for another backup tool to pick up. +# +# MySQL code: +# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost' +# IDENTIFIED BY 'password'; +# FLUSH PRIVILEGES; +# +##### START CONFIG ################################################### + +USER=<%= $backupuser %> +PASS='<%= $backuppassword_unsensitive %>' +MAX_ALLOWED_PACKET=<%= $maxallowedpacket %> +DIR=<%= $backupdir %> +ROTATE=<%= [ Integer($backuprotate) - 1, 0 ].max %> + +# Create temporary mysql cnf file. +TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1 +echo -e "[client]\npassword=$PASS\nuser=$USER\nmax_allowed_packet=$MAX_ALLOWED_PACKET" > $TMPFILE + +<% if $prescript { -%> +<%- [$prescript].flatten().filter |$value| {$value}.each |$script| { %> +<%= $script %> +<%- } -%> +<% } -%> + +# Ensure backup directory exist. +mkdir -p $DIR + +PREFIX=mysql_backup_ +<% if $ignore_events { %> +ADDITIONAL_OPTIONS="--ignore-table=mysql.event" +<% } else { %> +ADDITIONAL_OPTIONS="--events" +<% } %> + +<%# Only include routines or triggers if we're doing a file per database -%> +<%# backup. This happens if we named databases, or if we explicitly set -%> +<%# file per database mode -%> +<% if !$backupdatabases.empty or $file_per_database { -%> +<% if $include_triggers { -%> +ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --triggers" +<% } else { -%> +ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-triggers" +<% } -%> +<% if $include_routines { -%> +ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --routines" +<% } else { -%> +ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-routines" +<% } -%> +<% } -%> + +<%- if $optional_args and type($optional_args) =~ Type(Array) { -%> +<% $optional_args.each |$arg| { -%> +ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS <%= $arg %>" +<%- } -%> +<%- } -%> +##### STOP CONFIG #################################################### +PATH=<%= $execpath %> + +<%- if $kernel == 'Linux' { -%> +set -o pipefail +<%- } -%> + + + +cleanup() +{ + find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f +} + +<% if $delete_before_dump { -%> +cleanup + +<% } -%> +<% if $backupdatabases.empty { -%> +<% if $file_per_database { -%> +<% if $excludedatabases.empty { -%> +mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname +<%} else {-%> +mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= $excludedatabases.join('|') %>\)$' | while read dbname +<% } -%> +do + <%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ + ${ADDITIONAL_OPTIONS} \ + ${dbname} <% if $backupcompress { %>| <%= $compression_command %> <% } %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if $backupcompress { %><%= $compression_extension %><% } %> +done +<% } else { -%> +<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ + ${ADDITIONAL_OPTIONS} \ + --all-databases <% if $backupcompress { %>| <%= $compression_command %> <% } %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if $backupcompress { %><%= $compression_extension %><% } %> +<% } -%> +<% } else { -%> +<% $backupdatabases.each |$db| { -%> +<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ + ${ADDITIONAL_OPTIONS} \ + <%= $db %><% if $backupcompress { %>| <%= $compression_command %> <% } %>> ${DIR}/${PREFIX}<%= $db %>_`date +%Y%m%d-%H%M%S`.sql<% if $backupcompress { %><%= $compression_extension %><% } %> +<% } -%> +<% } -%> + +<% unless $delete_before_dump { -%> +if [ $? -eq 0 ] ; then + cleanup + touch <%= $backup_success_file_path %> +fi +<% } -%> + +<% if $postscript { -%> + <%- [$postscript].flatten().filter |$value| { $value }.each |$script| { %> +<%= $script %> + <%- } -%> +<% } -%> + +# Remove temporary file +rm -f $TMPFILE diff --git a/templates/mysqlbackup.sh.erb b/templates/mysqlbackup.sh.erb deleted file mode 100755 index 1fccc981f..000000000 --- a/templates/mysqlbackup.sh.erb +++ /dev/null @@ -1,121 +0,0 @@ -<%- if @kernel == 'Linux' -%> -#!/bin/bash -<%- else -%> -#!/bin/sh -<%- end -%> -# -# MySQL Backup Script -# Dumps mysql databases to a file for another backup tool to pick up. -# -# MySQL code: -# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost' -# IDENTIFIED BY 'password'; -# FLUSH PRIVILEGES; -# -##### START CONFIG ################################################### - -USER=<%= @backupuser %> -PASS='<%= @backuppassword_unsensitive %>' -MAX_ALLOWED_PACKET=<%= @maxallowedpacket %> -DIR=<%= @backupdir %> -ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %> - -# Create temporary mysql cnf file. -TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1 -echo -e "[client]\npassword=$PASS\nuser=$USER\nmax_allowed_packet=$MAX_ALLOWED_PACKET" > $TMPFILE - -<% if @prescript -%> -<%- [@prescript].flatten.compact.each do |script|%> -<%= script %> -<%- end -%> -<% end -%> - -# Ensure backup directory exist. -mkdir -p $DIR - -PREFIX=mysql_backup_ -<% if @ignore_events %> -ADDITIONAL_OPTIONS="--ignore-table=mysql.event" -<% else %> -ADDITIONAL_OPTIONS="--events" -<% end %> -<%# Only include routines or triggers if we're doing a file per database -%> -<%# backup. This happens if we named databases, or if we explicitly set -%> -<%# file per database mode -%> -<% if !@backupdatabases.empty? || @file_per_database -%> -<% if @include_triggers -%> -ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --triggers" -<% else -%> -ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-triggers" -<% end -%> -<% if @include_routines -%> -ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --routines" -<% else -%> -ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-routines" -<% end -%> -<% end -%> - -<%- if @optional_args and @optional_args.is_a?(Array) -%> -<%- @optional_args.each do |arg| -%> -ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS <%= arg %>" -<%- end -%> -<%- end -%> - -##### STOP CONFIG #################################################### -PATH=<%= @execpath %> - - - -<%- if @kernel == 'Linux' -%> -set -o pipefail -<%- end -%> - -cleanup() -{ - find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f -} - -<% if @delete_before_dump -%> -cleanup - -<% end -%> -<% if @backupdatabases.empty? -%> -<% if @file_per_database -%> -<% if @excludedatabases.empty? -%> -mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname -<% else -%> -mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= @excludedatabases.join('|') %>\)$' | while read dbname -<% end -%> -do - <%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ - ${ADDITIONAL_OPTIONS} \ - ${dbname} <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %> -done -<% else -%> -<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ - ${ADDITIONAL_OPTIONS} \ - --all-databases <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %> -<% end -%> -<% else -%> -<% @backupdatabases.each do |db| -%> -<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ - ${ADDITIONAL_OPTIONS} \ - <%= db %><% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %> -<% end -%> -<% end -%> - -<% unless @delete_before_dump -%> -if [ $? -eq 0 ] ; then - cleanup - touch <%= @backup_success_file_path %> -fi -<% end -%> - -<% if @postscript -%> - <%- [@postscript].flatten.compact.each do |script|%> -<%= script %> - <%- end -%> -<% end -%> - -# Remove temporary file -rm -f $TMPFILE diff --git a/templates/xtrabackup.sh.epp b/templates/xtrabackup.sh.epp new file mode 100644 index 000000000..dae476513 --- /dev/null +++ b/templates/xtrabackup.sh.epp @@ -0,0 +1,50 @@ +<%- if $kernel == 'Linux' {-%> +#!/bin/bash +<%-} else {-%> +#!/bin/sh +<%- } -%> +# +# A wrapper for Xtrabackup + +ROTATE=<%= [ Integer($backuprotate) - 1, 0 ].max %> +DIR=<%= $backupdir %> + +# Ensure backup directory exist. +mkdir -p $DIR + +<%- if $kernel == 'Linux' {-%> +set -o pipefail +<%- } -%> + +<% if $prescript {-%> +<%- [$prescript].flatten().filter |$value| {$value}.each |$script| { -%> + +<%= $script %> +<%- } -%> +<% } -%> + +cleanup() +{ + find "${DIR}/" -mindepth 1 -maxdepth 1 -mtime +${ROTATE} -print0 | xargs -0 -r rm -rf +} + +<% if $delete_before_dump { -%> +cleanup +<% } -%> + +<%= $backupmethod %> <%= $innobackupex_args %> $@ + +<% unless $delete_before_dump {-%> +if [ $? -eq 0 ] ; then + cleanup + <% if $backup_success_file_path { -%> + touch <%= $backup_success_file_path %> + <% } -%> +fi +<% } -%> + +<% if $postscript { -%> + <%- [$postscript].flatten().filter |$value| {$value}.each |$script| {%> +<%= $script %> + <%- } -%> +<% } -%> diff --git a/templates/xtrabackup.sh.erb b/templates/xtrabackup.sh.erb deleted file mode 100644 index 11093b077..000000000 --- a/templates/xtrabackup.sh.erb +++ /dev/null @@ -1,73 +0,0 @@ -<%- if @kernel == 'Linux' -%> -#!/bin/bash -<%- else -%> -#!/bin/sh -<%- end -%> -# -# A wrapper for Xtrabackup - -ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %> -DIR=<%= @backupdir %> - -# Ensure backup directory exist. -mkdir -p $DIR - -<%- if @kernel == 'Linux' -%> -set -o pipefail -<%- end -%> - -<% if @prescript -%> - <%- [@prescript].flatten.compact.each do |script| %> -<%= script %> - <%- end -%> -<% end -%> - - -cleanup() -{ - find "${DIR}/" -mindepth 1 -maxdepth 1 -mtime +${ROTATE} -print0 | xargs -0 -r rm -rf -} - -<% if @delete_before_dump -%> -cleanup -<% end -%> - - -<%- _innobackupex_args = '' -%> - -<%- if @backupuser and @backuppassword_unsensitive -%> - <%- _innobackupex_args = '--user="' + @backupuser + '" --password="' + @backuppassword_unsensitive + '"' -%> -<%- end -%> - -<%- if @backupcompress -%> - <%- _innobackupex_args = _innobackupex_args + ' --compress' -%> -<%- end -%> - -<%- if @backupdatabases and @backupdatabases.is_a?(Array) and !@backupdatabases.empty? -%> - <%- _innobackupex_args = _innobackupex_args + ' --databases="' + @backupdatabases.join(' ') + '"' -%> -<%- end -%> - -<%- if @optional_args and @optional_args.is_a?(Array) -%> - <%- @optional_args.each do |arg| -%> - <%- _innobackupex_args = _innobackupex_args + ' ' + arg -%> - <%- end -%> -<%- end -%> - -<%= @backupmethod -%> <%= _innobackupex_args %> $@ - - -<% unless @delete_before_dump -%> -if [ $? -eq 0 ] ; then - cleanup - <% if @backup_success_file_path -%> - touch <%= @backup_success_file_path %> - <% end -%> -fi -<% end -%> - - -<% if @postscript -%> - <%- [@postscript].flatten.compact.each do |script| %> -<%= script %> - <%- end -%> -<% end -%>