#!/bin/sh

# 
# Little helper to backup NfSen-1.2 style profile stat data

if [ $# -ne 2 ]; then
	echo "Usage: $0: <ProfileStatDir> <BackupDir>"
	exit;
fi

SRC=$1
DST=$2

# need absolute path for DST
echo $DST | grep '^/' > /dev/null
if [ $? -eq 1 ]; then
	DST=`pwd`/${DST}
fi

if  [ ! -d $DST ]; then
	echo "Create backup directory '$DST'"
	mkdir -p $DST
	if [ $? -ne 0 ]; then
		echo "Can't create $DST"
		exit 1;
	fi
fi

echo "Backup up stat data ..."
cd $SRC 
if [ $? -ne 0 ]; then
	echo "Can't change to $SRC"
	exit 1;
fi

for entry in `find . -maxdepth 2`; do
	if [ $entry = "." -o $entry = ".." ]; then
		continue
	fi
	if [ -d $entry ]; then
		# is a directory
		echo "$entry ..."
		if [ ! -d ${DST}/$entry ]; then
			mkdir -p ${DST}/$entry
		fi
	fi
	if [ -f $entry ]; then
		# it's a file to be copied
		cp -f -p  $entry  ${DST}/$entry
	fi
done
