Skip to content

Instantly share code, notes, and snippets.

@eniac111
Last active April 29, 2016 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eniac111/b37297e83cd5fa99e59e to your computer and use it in GitHub Desktop.
Save eniac111/b37297e83cd5fa99e59e to your computer and use it in GitHub Desktop.
#!/bin/bash
##
#####################################################################################
# "THE BEER-WARE LICENSE" (Revision 42):
# <blagovest@petrovs.info> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return. Blagovest Petrov
#####################################################################################
##
DAY=$1
MYSQL_PASS=$2
MYSQL_USER="bkpuser"
BACKUPS_DIR=/var/mysql-backups
THIS_WEEK=$BACKUPS_DIR/this_week
LAST_WEEK=$BACKUPS_DIR/last_week
function do_full_backup() {
if [ -d $LAST_WEEK ]; then
rm -rf $LAST_WEEK
mkdir $LAST_WEEK
fi
if [ -d $THIS_WEEK ]; then
mv $THIS_WEEK/* $LAST_WEEK
mkdir -p $THIS_WEEK/Sunday
fi
xtrabackup --backup --target-dir=$THIS_WEEK/Sunday \
--datadir=/var/lib/mysql \
--user=$MYSQL_USER --password=$MYSQL_PASS
}
function do_incremental_backup() {
if [ -d $THIS_WEEK/$DAY ]; then
rm -rf $THIS_WEEK/$DAY
mkdir $THIS_WEEK/$DAY
fi
xtrabackup --backup --target-dir=$THIS_WEEK/$DAY \
--incremental-basedir=$THIS_WEEK/Sunday \
--datadir=/var/lib/mysql \
--user=$MYSQL_USER --password=$MYSQL_PASS
}
case $1 in
Sunday)
do_full_backup
;;
*)
do_incremental_backup
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment