Skip to content

Instantly share code, notes, and snippets.

@victorpendleton
Last active March 20, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorpendleton/20e3791174f815040a80300c2690c43c to your computer and use it in GitHub Desktop.
Save victorpendleton/20e3791174f815040a80300c2690c43c to your computer and use it in GitHub Desktop.
Perform a surgical pull of MySQL data using Percona innobackupex
#!/bin/bash
# This file contains the user/password combination to connect to the database
source creds.sh
DATE=`date +%Y%m%d`
instancedirectory="/var/lib/"
retval=-1
backupdirectory="${1}"
exportconfig="${2}"
socket="${instancedirectory}/mysql.sock"
config="${instancedirectory}/mysql.cnf"
targetdirectory="${backupdirectory}/${DATE}/"
if [ -z ${backupdirectory} ] || [ -z ${exportconfig} ]
then
echo "usage: ./backup.sh <backup directory> <export config>"
else
if [ -d ${backupdirectory} ]
then
echo "Starting backup to ${backupdirectory}...";
innobackupex --user=${user} --password=${password} --defaults-file=${config} --socket=${socket} "${targetdirectory}" --tmpdir=/scratch/xtrabackups/tmpdir/ --no-timestamp --databases=${exportconfig} --slave-info;
retval=$?
if [ ${retval} -eq 0 ]
then
echo "Backup complete!";
echo "Preparing to apply logs...";
innobackupex --apply-log ${targetdirectory}
retval=$?
if [ ${retval} -eq 0 ]
then
echo "Logs have been applied and the backup has been prepared.";
else
echo "Unable to apply logs to the backup!";
fi
else
echo "Error backing up to ${backupdirectory}!";
fi
else
echo "${backupdirectory} does not exist!"
fi
fi
### Example of export config file
## Specific database tables
# database.table1
# database.table2
## Entire database
# mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment