Created
September 28, 2012 14:36
-
-
Save koko1000ban/3800230 to your computer and use it in GitHub Desktop.
run innobackupex for slave script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
BACKUP_DIR="${HOME}/backup" | |
TMPFILE="/tmp/backup_xtra.tmp" | |
MY_CONF="/etc/my.cnf" | |
XTRABACKUP="/usr/bin/innobackupex" | |
USER="root" | |
PASSWORD="--password=ぱすわーど" | |
LOCKFILE=`basename $0`.lock | |
ON_SLAVE='--slave-info --safe-slave-backup' | |
export PATH=/opt/mysql/bin/:$PATH | |
if [ ! -d $BACKUP_DIR ]; then | |
echo "Backup destination folder: $BACKUP_DIR does not exist."; echo | |
exit 1 | |
fi | |
trap 'echo "trapped."; rm -f ${LOCKFILE}; exit 1' 1 2 3 15 | |
if [ -e ${LOCKFILE} ]; then | |
echo "LOCKFILE exists: $LOCKFILE" | |
exit 1; | |
fi | |
touch ${LOCKFILE} | |
$XTRABACKUP --defaults-file=$MY_CONF $ON_SLAVE --user=$USER $PASSWORD $BACKUP_DIR 2>&1 | tee $TMPFILE | |
if [ -z "`tail -1 $TMPFILE | grep 'completed OK!'`" ] ; then | |
echo "backup failed:"; echo | |
echo "---------- ERROR OUTPUT ----------" | |
cat $TMPFILE | |
rm -f $TMPFILE | |
exit 1 | |
fi | |
THISBACKUP=`awk -- "/Backup created in directory/ { split( \\\$0, p, \"'\" ) ; print p[2] }" $TMPFILE` | |
rm -f $TMPFILE | |
$XTRABACKUP --apply-log --defaults-file=$MY_CONF $ON_SLAVE --user=$USER $PASSWORD $THISBACKUP 2>&1 | tee $TMPFILE | |
if [ -z "`tail -1 $TMPFILE | grep 'completed OK!'`" ] ; then | |
echo "backup --apply-log failed:"; echo | |
echo "---------- ERROR OUTPUT --apply-log ----------" | |
cat $TMPFILE | |
rm -f $TMPFILE | |
exit 1 | |
fi | |
#Compress backup | |
echo "Compressing backup files" | |
tar -zcf $THISBACKUP.tar.gz -C / $(echo $THISBACKUP | cut -c 2-) | |
# Cleanup | |
echo "Cleaning up old backups (older than $AGE days) and temporary files" | |
rm -f $TMPFILE | |
rm -f $LOCKFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment