Re: [NEWBIE] Compiling a stock circle I got from ceramicmouse

From: Daniel A. Koepke (dkoepke@circlemud.org)
Date: 01/24/01


On Wed, 24 Jan 2001, Peter Ajamian wrote:

> There's an even better way, just throw in a file with the patterns of
> all the files to exclude from the tarball and pass the filename to tar
> with the -X switch to make tar exclude the files from the archive.

Well, mind you, the idea was to make a script or method to clean-up for
preparing to distribute, since how the distribution is going to be
packaged really depends.  (They might be, for instance, zipping it with
zip instead of tarring it.)

On the other hand, the -X flag is great when you're making backups.  I
have an old shell script here that does it because I often keep backups of
various projects and it got to the point where I wanted to do enough with
it that a shell script was in order (plus, I constantly forget the date
and almost always put the -X flag afer the f flag when I'm typing it).
Hopefully, it'll fit (it's probably longer than it needs to be since it
was a quick hack that was meant to be written once and applicable to many
different situations):

--8<- cut ->8--

#!/bin/sh
# backtar - make a backup tar.bz2 file of a directory
# public domain, dkoepke@circlemud.org

DONT_EXCLUDE=0
EXT="tar.bz2"
CP="bzip2"
DIR=`pwd`
BDIR=""
DFORM="%d%b%Y"
DOPT=""
DATE=`date $DOPT +$DFORM`

while [ $# -ne 0 ]; do
        case "$1" in
                -e|--ext)
                        echo "Setting extension to \`$2'"
                        EXT="$2" ; shift 2 ;;
                -b|--base)
                        echo "Setting archive basename to \`$2'"
                        BDIR="$2" ; shift 2 ;;
                -F|--dateform)
                        echo "Setting date format to \`$2'"
                        DFORM="$2" ; shift 2 ;;
                -d|--date)
                        echo "Passing date string \`$2' to date"
                        DOPT="$2" ; shift 2 ;;
                -p|--compress)
                        echo "Using compression program \`$2'"
                        CP="$2" ; shift 2 ;;
                -X)
                        echo "Ignoring $DIR/.backtar_exclude."
                        DONT_EXCLUDE=1 ; shift ;;
                *)
                        echo "Using directory \`$1'"
                        DIR="$1" ; shift ;;
        esac
done

if [ $DONT_EXCLUDE -eq 0 ] && [ -r $DIR/.backtar_exclude ]; then
        echo "Excluding files from $DIR/.backtar_exclude."
        OPT="-X $DIR/.backtar_exclude"
fi

if [ -z "$BDIR" ]; then
        BDIR=`basename $DIR`
fi

X=0
Y=0

if [ -n "$DOPT" ]; then
        DATE=`date -d "$DOPT" +$DFORM`
else
        DATE=`date $DOPT +$DFORM`
fi

FNAME="$BDIR-$DATE-$X$Y.$EXT"

while [ -f $FNAME ]; do
        let Y=$Y+1
        if [ $Y -eq 10 ]; then
                let Y=0
                let X=$X+1

                if [ $X -eq 10 ]; then
                        echo "Too many backup files today.  Delete some."
                        exit 1
                fi
        fi
        FNAME="$BDIR-$DATE-$X$Y.$EXT"
done

echo The command line will be:
echo
echo "    tar -c $OPT"
echo "        --use-compress-program $CP"
echo "        -f $FNAME"
echo "        $DIR"
echo
echo ENTER to execute, Control-C if you don\'t want to do it.
read foobaz
tar -c --use-compress-program $CP $OPT -f $FNAME $DIR

--8<- fin ->8--

I've condensed it and removed some comments.  Hopefully I didn't break
anything.  Usage: backtar [options] [directory], the options should be
fairly self-documenting.

-dak

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST