#!/bin/bash
export FOLDERS="bin sbin boot lib etc root media tmp proc compartir dev mnt server srv var sys cdrom dvd floppy"
export BIGFOLDERS="usr opt home"
export DEST="/xtras/rw2/gnt686"
export REALLYBIGFOLDERS="usr/local usr/src usr/share usr/X11R6 usr/loki opt/kde3 usr/kde"
echo "BACKUP de los archivos RAIZ"
find -type f -maxdepth 1 -not -name . | 
    while read i
     do tar -cv "$i" | gzip -f9> "$DEST"/barra-files-`echo $i | awk -F / '{print $NF}'`.tgz
    done

find -type l -maxdepth 1 -not -name . | 
    while read i
     do tar -cv "$i" | gzip -f9> "$DEST"/barra-sym-`echo $i | awk -F / '{print $NF}'`.tgz
    done

for DIR in $FOLDERS 
    do 
    echo "Backup de $DIR en $DEST/$DIR.tgz"
    tar -cv "$DIR" | gzip -f9 > $DEST/$DIR.tgz
done
for BIGDIR in $BIGFOLDERS
    do
    #Enlaces simbolicos en los directorios ralmente grandes
    find $BIGDIR -maxdepth 1 -type l |
	while read DIR
	    do tar -cv $DIR | gzip -f9 > $DEST/`echo $DIR | awk -F '/' '{print \$1"-"\$2}'`.tgz
	    done
    #Revisar las carpetas completas
    find $BIGDIR -maxdepth 1 -not -name $BIGDIR |
	while read DIR
	    do 
		if echo "$REALLYBIGFOLDERS" |  grep "$DIR" > /dev/null;
		    then 
		    echo "Excluded: $DIR"
		    else 
		    echo "tar -cv $DIR | gzip -f9 > $DEST/`echo $DIR | awk -F '/' '{print \$1\$2}'`.tgz"
#		    sleep 3
		    tar -cv $DIR | gzip -f9 > $DEST/`echo $DIR | awk -F '/' '{print \$1"-"\$2}'`.tgz
		fi
	    done
	    #tar -cv $DIR | gzip -f9 
done

for BIGDIR in $REALLYBIGFOLDERS
    do
    find $BIGDIR -maxdepth 1 |
	while read DIR
	    do 
		if echo "$REALLYBIGFOLDERS" |  grep "$DIR" > /dev/null;
		    then 
		    echo "Excluded: $DIR"
		    else 
		    echo "tar -cv $DIR | gzip -f9 > $DEST/`echo $DIR | awk -F '/' '{print \$1\$2\$3}'`.tgz"
#		    sleep 3
		    tar -cv "$DIR" | gzip -f9 > $DEST/`echo $DIR | awk -F '/' '{print \$1"-"\$2"-"\$3}'`.tgz
		    fi 
	done
done