3
# Backup script for MySQL 5.5 on RHEL5 using XtraBackup
5
# Requires: xtrabackup, bash, awk, coreutils
7
# Copyright (C) 2011 Daniel van Eeden
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
BACKUPDIR="/var/mysql/backups/xtrabackup"
25
INNOBACKUPEX_OPTIONS=""
29
timestamp=`date +%Y%m%d_%H%M%S_%Z`
32
if [ ! -x "/usr/bin/innobackupex-1.5.1" ]; then
33
echo "ERROR: /usr/bin/innobackupex-1.5.1 is not executable."
37
if [ ! -d ${BACKUPDIR} ]; then
38
echo "ERROR: ${BACKUPDIR} is not a directory."
42
freespace_m=`df -k ${BACKUPDIR} | awk '{ if ($4 ~ /^[0-9]*$/) { print int($4/1024) } }'`
43
if [ ${freespace_m} -le ${MINFREE_M} ]; then
44
echo "ERROR: There is less than ${MINFREE_M} MB of free space on ${BACKUPDIR}"
48
# Remove backups older than $RETENTION_DAYS
49
find /var/mysql/backups/xtrabackup -name "*_*_*_xtrabackup\.tar\.bz2" -type f -mtime +${RETENTION_DAYS}
52
/usr/bin/innobackupex-1.5.1 ${INNOBACKUPEX_OPTIONS} --stream=tar /tmp 2> ${BACKUPDIR}/${timestamp}_xtrabackup.log | bzip2 > ${BACKUPDIR}/${timestamp}_xtrabackup.tar.bz2