diff --git a/templates/xtrabackup.sh.erb b/templates/xtrabackup.sh.erb index a8e83ce20..de5319763 100644 --- a/templates/xtrabackup.sh.erb +++ b/templates/xtrabackup.sh.erb @@ -5,13 +5,38 @@ <%- 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() +{ + <%- if @kernel == 'SunOS' -%> + gfind "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | gxargs -0 -r rm -f + <%- else -%> + find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f + <%- end -%> +} + +<% if @delete_before_dump -%> +cleanup +<% end -%> + + <%- _innobackupex_args = '' -%> <%- if @backupuser and @backuppassword -%> @@ -30,6 +55,15 @@ <%= @backupmethod -%> <%= _innobackupex_args %> $@ + +<% unless @delete_before_dump -%> +if [ $? -eq 0 ] ; then + cleanup + touch /tmp/mysqlbackup_success +fi +<% end -%> + + <% if @postscript -%> <%- [@postscript].flatten.compact.each do |script| %> <%= script %>