Skip to content

Rotate option for xtrabackup script #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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