~longbow/percona-xtrabackup/bug664986

« back to all changes in this revision

Viewing changes to contrib/backup_mysql_cron.sh

  • Committer: Alexey Kopytov
  • Date: 2011-09-26 07:31:32 UTC
  • mfrom: (309.1.1 trunk)
  • Revision ID: akopytov@gmail.com-20110926073132-g5xv4iu4hnv0u93z
Manual merge from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# Backup script for MySQL 5.5 on RHEL5 using XtraBackup
 
4
#
 
5
# Requires: xtrabackup, bash, awk, coreutils
 
6
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
 
 
21
## Settings ##
 
22
PATH="/bin:/usr/bin"
 
23
BACKUPDIR="/var/mysql/backups/xtrabackup"
 
24
MINFREE_M="5000"
 
25
INNOBACKUPEX_OPTIONS=""
 
26
RETENTION_DAYS="7"
 
27
 
 
28
## Logic ##
 
29
timestamp=`date +%Y%m%d_%H%M%S_%Z`
 
30
export PATH;
 
31
 
 
32
if [ ! -x "/usr/bin/innobackupex-1.5.1" ]; then
 
33
  echo "ERROR: /usr/bin/innobackupex-1.5.1 is not executable."
 
34
  exit 1
 
35
fi 
 
36
 
 
37
if [ ! -d ${BACKUPDIR} ]; then
 
38
  echo "ERROR: ${BACKUPDIR} is not a directory."
 
39
  exit 2
 
40
fi
 
41
 
 
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}"
 
45
  exit 3
 
46
fi
 
47
 
 
48
# Remove backups older than $RETENTION_DAYS
 
49
find /var/mysql/backups/xtrabackup -name "*_*_*_xtrabackup\.tar\.bz2" -type f -mtime +${RETENTION_DAYS}
 
50
 
 
51
# Create the backup
 
52
/usr/bin/innobackupex-1.5.1 ${INNOBACKUPEX_OPTIONS} --stream=tar /tmp 2> ${BACKUPDIR}/${timestamp}_xtrabackup.log | bzip2 > ${BACKUPDIR}/${timestamp}_xtrabackup.tar.bz2