2013-04-18 08:51:50 +02:00
|
|
|
#!/bin/bash
|
2012-04-24 07:53:59 +02:00
|
|
|
#
|
|
|
|
# MySQL Backup Script
|
|
|
|
# Dumps mysql databases to a file for another backup tool to pick up.
|
|
|
|
#
|
|
|
|
# MySQL code:
|
|
|
|
# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost'
|
|
|
|
# IDENTIFIED BY 'password';
|
|
|
|
# FLUSH PRIVILEGES;
|
|
|
|
#
|
|
|
|
##### START CONFIG ###################################################
|
|
|
|
|
2013-05-24 16:01:52 +02:00
|
|
|
USER=<%= @backupuser %>
|
|
|
|
PASS=<%= @backuppassword %>
|
|
|
|
DIR=<%= @backupdir %>
|
2013-04-18 08:51:50 +02:00
|
|
|
ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %>
|
|
|
|
|
|
|
|
PREFIX=mysql_backup_
|
2012-04-24 07:53:59 +02:00
|
|
|
|
|
|
|
##### STOP CONFIG ####################################################
|
|
|
|
PATH=/usr/bin:/usr/sbin:/bin:/sbin
|
|
|
|
|
2013-04-18 08:51:50 +02:00
|
|
|
set -o pipefail
|
|
|
|
|
2012-04-24 07:53:59 +02:00
|
|
|
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
|
2013-04-18 08:51:50 +02:00
|
|
|
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
|
|
|
|
|
|
|
|
if [ $? -eq 0 ] ; then
|
|
|
|
find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f
|
|
|
|
fi
|
2012-04-24 07:53:59 +02:00
|
|
|
|