Last active
March 20, 2017 17:15
-
-
Save victorpendleton/20e3791174f815040a80300c2690c43c to your computer and use it in GitHub Desktop.
Perform a surgical pull of MySQL data using Percona innobackupex
This file contains 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/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