Skip to content

Commit

Permalink
Rotate option for xtrabackup
Browse files Browse the repository at this point in the history
  • Loading branch information
elfranne committed Mar 29, 2019
1 parent 9075bc3 commit 9834d9a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion templates/xtrabackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand All @@ -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 %>
Expand Down

0 comments on commit 9834d9a

Please sign in to comment.