Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@
# Whether to install a cronjob to perform a scheduled backup.
# Enabled by default, pass 'false' to disable.
# (Optional, enabled by default)
# [*silentcron*]
# Generate backup output only if there was an error. Setting this
# to true will surpress all mails from cron unless the backup script
# failed.
# (Optional, defaults to send daily emails).
# [*install_20*]
# Whether to install Xtrabackup 2.0; if set to false installs the latest (2.1)
# instead.
# (Optional, disabled by default)
# [*statusfile*]
# File to touch in case the backup was successfull. Can be used for to monitor
# the backup status using check_file_age.
#
# === Examples
#
Expand Down Expand Up @@ -98,7 +106,9 @@
$safeslave = undef, # Disconnect clients from slave
$addrepo = true, # Add the Percona yum/apt repo
$cronjob = true, # Install a cron job
$silentcron = false, # Send emails always
$install_20 = false, # Install 2.0 instead of latest
$statusfile = undef, # statusfile to touch if cronjob was successfull.
) {

if ($addrepo) {
Expand Down Expand Up @@ -141,8 +151,13 @@
if ( !$hour or !$minute ) {
fail('Hour and minute parameters are mandatory when cronjob is true.')
}
if $silentcron {
$command_add = ' silent'
} else {
$command_add = ''
}
cron { 'xtrabackup':
command => '/usr/local/bin/mysql-backup',
command => "/usr/local/bin/mysql-backup${command_add}",
hour => $hour,
minute => $minute,
}
Expand Down
75 changes: 57 additions & 18 deletions templates/backupscript.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,64 @@
# (C) 2013 Bashton Ltd

DATE=$( date +%Y-%m-%d )
TMP=$(mktemp)
SILENT="$1"

/usr/bin/innobackupex \
--stream=xbstream \
--user=<%= @dbuser %> \
--password=<%= @dbpass %> \
--parallel=<%= @parallel %> \
<%= " --slave-info \\\n" if @slaveinfo -%>
<%= " --safe-slave-backup \\\n" if @safeslave -%>
<%= " " + @workdir + " \\\n" -%>
<%= " | gzip -c9 \\\n" if @gzip -%>
<%= " | ssh " + @sshdest if @sshdest -%>
<%= " -i " + @sshkey + " \\\n" if @sshkey -%>
<%= " cat - \\\n" if @sshdest -%>
> <%= @outputdir -%>/mysql-backup-${DATE}.xbstream<%= ".gz" if @gzip %>
function cleanup() {
rm -f ${TMP}
}

function backup() {
/usr/bin/innobackupex \
--stream=xbstream \
--user=<%= @dbuser %> \
--password=<%= @dbpass %> \
--parallel=<%= @parallel %> \
<%= " --slave-info \\\n" if @slaveinfo -%>
<%= " --safe-slave-backup \\\n" if @safeslave -%>
<%= " " + @workdir + " \\\n" -%>
<%= " | gzip -c9 \\\n" if @gzip -%>
<%= " | ssh " + @sshdest if @sshdest -%>
<%= " -i " + @sshkey + " \\\n" if @sshkey -%>
<%= " cat - \\\n" if @sshdest -%>
> <%= @outputdir -%>/mysql-backup-${DATE}.xbstream<%= ".gz" if @gzip %>

for i in ${PIPESTATUS[@]}; do
if [ $i -gt 0 ]; then
return $i
fi
done
}

<% if @keepdays -%>
# Clean up backups older than <%= @keepdays %>
<%= "ssh " + @sshdest if @sshdest -%>
<%= " -i " + @sshkey + " \\\n " if @sshkey -%>
find <%= @outputdir %> -maxdepth 1 -name 'mysql-backup-*.xbstream*' \
-type f -mtime +<%= @keepdays %> -delete
function keepdays() {
# Clean up backups older than <%= @keepdays %>
<%= "ssh " + @sshdest if @sshdest -%>
<%= " -i " + @sshkey + " \\\n " if @sshkey -%>
find <%= @outputdir %> -maxdepth 1 -name 'mysql-backup-*.xbstream*' \
-type f -mtime +<%= @keepdays %> -delete
}
<% end -%>


trap cleanup EXIT

backup 2>${TMP}
ret=$?

if [ "${SILENT}" != "silent" -o $ret -gt 0 ]; then
cat ${TMP}
fi

<% if @statusfile -%>
if [ $ret -eq 0 ]; then touch <%= @statusfile -%>; fi
<% end -%>

<% if @keepdays -%>
keepdays
<% end -%>

trap - EXIT
cleanup

exit $ret