#!/bin/bash
# TODO: test for missing/too much arguments, there must be exactly 2
# TODO: make sure the arguments are:
# 1) directories
# 2) existing
function show_time () {
num=$1
min=0
hour=0
day=0
if((num>59));then
((sec=num%60))
((num=num/60))
if((num>59));then
((min=num%60))
((num=num/60))
if((num>23));then
((hour=num%24))
((day=num/24))
else
((hour=num))
fi
else
((min=num))
fi
else
((sec=num))
fi
echo "$day"d "$hour"h "$min"m "$sec"s
}
DATE=`date '+%Y%m%d%H%M'`
# TODO: remove potentially trailing slash
SRC=$1
DST=$2
STARTTIME=$(date +%s)
rsync -av --link-dest=../latest $SRC/ $DST/$DATE/
ENDTIME=$(date +%s)
echo "It took $(show_time $(($ENDTIME - $STARTTIME)) ) to complete this task..."
rm $DST/latest
ln -s $DST/$DATE $DST/latest