Skip to content

Instantly share code, notes, and snippets.

@sandhose
Created March 9, 2018 22:38
Show Gist options
  • Save sandhose/cf7dc0814902c6560f19b324e531b83f to your computer and use it in GitHub Desktop.
Save sandhose/cf7dc0814902c6560f19b324e531b83f to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
WD=/var/backups/mysql
LATEST=$WD/latest
PREVIOUS=`readlink -e $LATEST`
NEXT=$WD/`date '+%Y%m%d-%H%M'`
if [ -d "$NEXT" ]; then
echo "\`$NEXT' already exists."
exit 1
fi
if [ "$#" -gt 1 ] && [ "$1" = "full" ]; then
NEXT=$NEXT-full
xtrabackup --backup --target-dir=$NEXT 2> $NEXT.log
else
if ! [ -L "$LATEST" ]; then
echo "\`$LATEST' does not exists. Consider doing a full backup first."
exit 1
fi
xtrabackup --backup --target-dir=$NEXT --incremental-basedir=$PREVIOUS 2> $NEXT.log
fi
rm -f $LATEST $LATEST.log
ln -s $NEXT $LATEST
ln -s $NEXT.log $LATEST.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment