Innobackupex script

From Wiki
Jump to: navigation, search

If you do not have xtrabackup installed you can download the rpms at the following address.

http://www.percona.com/downloads/XtraBackup/LATEST/binary/redhat/6/x86_64/

For cPanel servers you will need to use the binary tarball due to RPM conflicts.

wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/tarball/percona-xtrabackup-2.2.3-4982-Linux-x86_64.tar.gz
tar xzvf percona-xtrabackup-2.2.3-4982-Linux-x86_64.tar.gz
cd percona-xtrabackup-2.2.3-Linux-x86_64/
cp bin/* /usr/local/bin/

The DBD::mysql module for perl is also needed.

cpan DBD::mysql

If that doesn't work use the source install.

wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.028.tar.gz
tar xzvf DBD-mysql-4.028.tar.gz
cd DBD-mysql-4.028
perl Makefile.PL
make
make install
#!/bin/bash

if [ $TERM != "screen" ]; then
        echo "Please run this script from a screen window."
        exit
fi

s=/var/lib/mysql
d=/home/temp/innobackupex

hostname=`hostname`
em='admin@example.com'
dbs=`mysql -Bse 'show databases'`

mkdir -p $d
cd $s
time innobackupex --user='root' --password='password' --databases="$dbs" $d 
 
if [ $? != 0 ]; then
        echo -e "Subject: Error dumping database on ${hostname}\n\nPlease investigate.\n" | sendmail $em
else
        msg="${hostname} backup done"
        echo -e "Subject: ${msg}\n\n${msg}\n" | sendmail $em
fi

echo "dump finished: `date`"

After the script is done you can tar/rsync the destination dir over to another host.