Skip to content

Commit 014e1f1

Browse files
authored
Merge pull request #1176 from elfranne/rotate_xtrabackup
Rotate option for xtrabackup script
2 parents ca33678 + 9834d9a commit 014e1f1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

templates/xtrabackup.sh.erb

+35-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@
55
<%- end -%>
66
#
77
# A wrapper for Xtrabackup
8-
#
8+
9+
ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %>
10+
DIR=<%= @backupdir %>
11+
12+
# Ensure backup directory exist.
13+
mkdir -p $DIR
14+
15+
<%- if @kernel == 'Linux' -%>
16+
set -o pipefail
17+
<%- end -%>
18+
919
<% if @prescript -%>
1020
<%- [@prescript].flatten.compact.each do |script| %>
1121
<%= script %>
1222
<%- end -%>
1323
<% end -%>
1424

25+
26+
cleanup()
27+
{
28+
<%- if @kernel == 'SunOS' -%>
29+
gfind "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | gxargs -0 -r rm -f
30+
<%- else -%>
31+
find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f
32+
<%- end -%>
33+
}
34+
35+
<% if @delete_before_dump -%>
36+
cleanup
37+
<% end -%>
38+
39+
1540
<%- _innobackupex_args = '' -%>
1641

1742
<%- if @backupuser and @backuppassword -%>
@@ -30,6 +55,15 @@
3055

3156
<%= @backupmethod -%> <%= _innobackupex_args %> $@
3257

58+
59+
<% unless @delete_before_dump -%>
60+
if [ $? -eq 0 ] ; then
61+
cleanup
62+
touch /tmp/mysqlbackup_success
63+
fi
64+
<% end -%>
65+
66+
3367
<% if @postscript -%>
3468
<%- [@postscript].flatten.compact.each do |script| %>
3569
<%= script %>

0 commit comments

Comments
 (0)