#!/bin/sh
begintime=`date +"%Y-%m-%d %H:%M:%S"`
format_time=`date +"%Y-%m-%d_%H:%M:%S"`
week=`date +%w`
port=3306
#ip=
backdir=/backup
file_cnf=/etc/my.cnf
user_name=root
passwd=
out_log=$datadir/xtraback_log_$format_time
time_cost=$backdir/xtraback_time.txt
if [ ! -d "$backdir" ]; then
mkdir -p $backdir
fi
if [ -d "$backdir/rec5" ];then
rm -rf $backdir-bak
mv $backdir $backdir-bak
mkdir $backdir
fi
#full backup
if [ ! -d "$backdir/full" ];then
echo "#####start full backup at $begintime to directory full" >>$time_cost
innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=3306 $backdir/full 1>$out_log-full 2>&1
tar -zcvf $backdir/full.tar.gz $backdir/full
break;
elif [ ! -d "$backdir/rec0" ];then
echo "######start 0 incremental backup at $begintime to directory rec0" >>$time_cost
innobackupex --default-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=$port --incremental --incremental-ba
sedir=$backdir/full $backdir/rec0 1> $out_log-rec0 2>&1
break;
elif [ ! -d "$backdir/rec1" ];then
echo "#######start 1 incremental backup at $begintime to directory rec1" >>$time_cost
innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=port --incremental --incremental-basedir=$backdir/full $backdir/rec1 1>$out_log-rec1 2>&1
break;
elif [ ! -d "$backdir/rec2" ]; then
echo "######start 2 incremental backup at $begintime to directory rec2" >>$time_cost
innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=port --incremental --incremental-basedir=$backdir/rec1 $backdir/rec2 1> $out_log-rec2 2>&1
break;
elif [ ! -d "$backdir/rec3" ]; then
echo "#######start 3 incremental backup at $begintime to directory rec3" >$time_cost
innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=root --port=port --incremental --incremental-basedir=$/backdir/rec2 $backdir/rec3 1> $out_log-rec3 2>&1
break;
elif [! -d "$backdir/rec4" ];then
echo "########start 4 incremental backup at $begintime to directory rec4" >>$time_cost
innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=root --port=port --incremental --incremental-basedir=$backdir/rec4 1> $out_log-rec4 2>&1
break;
elif [ ! -d "$backdir/rec5" ];then
echo "#######start 5 incremental backup at $begintime to directory rec5" >>$time_cost
innobackupex --defaults-file=$file_cnf --no-lock --no-timestamp --user=$user_name --port=port --incremental --incremental-basedir=$backdir/rec4 $backdir/rec5 1> $out_log-rec5 2>&1
break;
fi