Created
March 9, 2018 22:38
-
-
Save sandhose/cf7dc0814902c6560f19b324e531b83f to your computer and use it in GitHub Desktop.
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/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