#!/bin/bash #Customize the following variables for your environment CONTROLLER_HOME="/opt/AppDynamics/Controller" DESTINATION="/opt/AppDynamics/backup" #Derived constants DATECODE=`date +%Y%m%d` # Set threads equal to core count on system THREADS=`cat /proc/cpuinfo | grep processor | wc -l` ### Critical sanity checks if ! ( [ -d "$CONTROLLER_HOME" ] && [ -d "$DESTINATION" ] ) then >&2 echo "$CONTROLLER_HOME and/or $DESTINATION do not exist or are not directories." exit 2 fi DATADIR=`grep ^datadir $CONTROLLER_HOME/db/db.cnf | cut -d = -f 2` if [ -e "$DATADIR/test" ] then >&2 echo "$DATADIR/test exists and will interfere with the correct operation of Xtrabackup. Please make sure you can remove it safely, and re-run this script" exit 3 fi if ! [[ -x `which innobackupex` ]] then echo "Percona Xtrabackup is not installed on this host." [ -e /etc/redhat-release ] && >&2 echo "\ Please set up the Percona yum repository http://www.percona.com/doc/percona-xtrabackup/2.2/installation/yum_repo.html and run \"yum install percona-xtrabackup qpress\"" [ -e /etc/debian-version ] && >&2 echo "\ Please set up the Percona apt repository http://www.percona.com/doc/percona-xtrabackup/2.2/installation/apt_repo.html and run \"apt-get install percona-xtrabackup qpress\"" exit 4 fi ### End Sanity checks # Run the backup with "nice -n 10" to keep the backup from interfering with the # running controller nohup nice -n 10 innobackupex \ --defaults-file=$CONTROLLER_HOME/db/db.cnf --user=root --password=`cat \ $CONTROLLER_HOME/db/.rootpw` --stream=xbstream --socket=/tmp/mysql.sock \ --compress --parallel=$THREADS --compress-threads=$THREADS --lock-wait-timeout=1200 \ $DESTINATION > \ "$DESTINATION"/controller-$DATECODE.xbstream 2> "$DESTINATION"/controller-$DATECODE.log if [ "$?" == "0" ] #backup completed successfully then # call your enterprise backup client to pick up "$DESTINATION"/controller-$DATECODE.xbstream # # remove "$DESTINATION"/controller-$DATECODE.xbstream if the backup client returns success? echo "Backup completed successfully" exit 0 # exit and return success else # send an email to the controller admin and maybe attache $DESTINATION/controller-$DATECODE.log echo "Backup failed. Please see $DESTINATION/controller-$DATECODE.log for more details." exit 1 # exit and return failure fi