#!/bin/sh
#
# full backup script called from uback
# $Revision: 1.5 $


if [ "x$1" = "x--help" ]; then
    echo "full: does a full backup of the specified directories."
    echo "      configuration should be in /etc/uback.d/full."
    echo
    exit 1;
else
    . $1
fi

if [ "x$confdir" = "x" ]; then
    echo "Error: configfile \"$1\" missing or invalid!"
    exit 1;
else
    . $confdir/full
fi


etc=$base/etc
log=$tarlog
full=$backup/full
datum=`$date +%d.%m.%Y.%H%M`
case $tarcompress in
    "-z")
	suffix="gz"
	;;
    "-I")
	suffix="bz2"
	;;
    "-Z")
	suffix="Z"
	;;
    "")
	suffix=""
	;;
    "*")
	suffix="gz"
	tarcompress="-z"
	;;
esac


trap '$rm -f $full/$tardir.$datum.tar.$suffix $log/fullbackup.$tardir.$datum.log; echo "abort."; exit 127' 1 2 3 15

for dir in $backupdirs;
do
	tardir=`echo $dir | $sed s'/^\///' | $sed s'/\//_/g'`
	# or use a tape drive: find $dir/ | afio -o /dev/rmt0
	decho "   => $tar $taroptions $tarcompress -c -f $full/$tardir.$datum.tar.$suffix $dir"
	$tar $taroptions $tarcompress -c -f $full/$tardir.$datum.tar.$suffix $dir > $log/fullbackup.$tardir.$datum.log 2>&1
	size=`$du -h $full/$tardir.$datum.tar.$suffix | $cut -f 1`
	decho "      saved $dir to $full/$tardir.$datum.tar.$suffix ($size)"
	decho "      log is in $log/fullbackup.$tardir.$datum.log"
	if [ "x$dbtool" != "x" ]; then
		$rm -f $full/$tardir.$datum.catalog
		$find $dir -ls | $dbtool -d $full/$tardir.$datum.catalog -i -f -R -t "^(.+?) (\/.*)$"
		decho "      catalog has been created in $full/$tardir.$datum.catalog."
	fi
done
