#/bin/bash

function full_backup(){
echo "Starting full backup ......"
cd /backup/full

rm -rf *

innobackupex --defaults-file=/etc/my.cnf --no-timestamp --user=root --password=123456 /backup/full

}


function increment_backup(){
echo "Starting increment backup ......"

cd /backup/full
BASE_DIR=`ls`
echo "BASE DIR IS $BASE_DIR"

if [[ $BASE_DIR = '' ]];then

 full_backup

else

innobackupex --defaults-file=/etc/my.cnf --no-timestamp --user=root --password=123456 --incremental --incremental-basedir=/backup/full/$BASE_DIR /backup/increment

fi

}


WEEK_DAILY=`date +%a`

case "$WEEK_DAILY" in

        "Mon")
  increment_backup
                ;;
        "Tue")
  increment_backup
                ;;
        "Wed")
  increment_backup
                ;;
        "Thu")
  increment_backup
                ;;
        "Fri")
  increment_backup
                ;;
        "Sat")
  full_backup
                ;;
        "Sun")
  increment_backup
                ;;
        "*")
                echo "error!"
esac