#!/bin/sh
# STTA Rev. 1.3 Copyright (c) 2001-2003 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.3pre1049295437- [2003_4_02_165717]
TTADIR=/opt/tarantella 
. $TTADIR/var/javaenv
USAGE="$0 {directorio-de-backup} {directorios-de-var} [-nodocroot] "
ZipTool="gzip";
ttawebmindefs=$TTADIR/defs
cd $TTADIR/var

ALL="docroot ens info password preferences serverconfig serverresources tsp"
if [ "$#" -eq 0 ] ; then
  echo "$USAGE";
  exit 1
fi
if [ -d $1 ] ; then 
   DestDir=$1
else
   echo "Directorio $1 no existe !!!"
   exit 2
fi 
if [ "$2" != "" ] ; then 
 case $2 in 
 -nodocroot) newall=`echo $ALL | sed 's/docroot//g'`
             ALL=$newall ; break ;;
  *) if [ -d $2 ] ; then 
          ALL="$2"
     else
           echo "Directorio $2 no existe !!!"
           exit 2
     fi ;;
 esac
fi
ahora=`date +%Y_%m_%d_%H%M%S`
mkdir $DestDir/$ahora
for nomdir in `echo $ALL` 
do
   echo "Copiando Ficheros de \"$nomdir\" ..."
   find $nomdir -print -depth | cpio -ocvO $DestDir/$ahora/$nomdir".cpio"
   gzip $DestDir/$ahora/$nomdir".cpio"
done
echo "Copiando Ficheros de \"$ttawebmindefs\" ..."
cd $ttawebmindefs
nameDefs=`basename $ttawebmindefs`
cd ..
tar cpvf $DestDir/$ahora/defs".tar"   $nameDefs
gzip $DestDir/$ahora/defs".tar"
   

