Subject: Tar -> Pax transition -rf PAIN (BUG?)
To: None <netbsd-users@netbsd.org>
From: Martin Weber <Ephaeton@gmx.net>
List: netbsd-users
Date: 12/10/2002 00:40:20
Formerly, with the tar we used, the following would work:

touch x.tar
tar -rf x.tar <file>

A (mail)backupscript of mine used this to loop over a list
of files, put them into the archive, delete them, touch them, 
and zip the archive lateron.

Well. if it was a bug or not, today I had the extreme pleasure
to watch the output of my script (before I could quickly ^C):

* caml-list :
 Backup... tar: Sorry, unable to determine archive format.
(okay) ...deleting... (okay) ...Touching (okay)
* family :
 Backup... tar: Sorry, unable to determine archive format.
(okay) ...deleting... (okay) ...Touching (okay)
* from :
 Backup... tar: Sorry, unable to determine archive format.
(okay) ...deleting... (okay) ...Touching (okay)
* incoming :
 Backup... tar: Sorry, unable to determine archive format.
(okay) ...deleting... (okay) ...Touching (okay)
* netbsd-advocacy :
 Backup... tar: Sorry, unable to determine archive format.
(okay) ...deleting... (okay)^C

Yes, supposedly I'm an idiot for not checking tar's exit status
inside the script. lucky me, I just had copied incoming before
I shot in my foot. Nonetheless, this change of behaviour, is
this a bug ? After all, when I invoke pax as tar, guess what
format I want to use ?

Oh, I just looked again at my script, I *DO* check the exit status
of tar. *ROAR* So it shot my files because I relied on it working
successfully and it returned 0 from main while it had no clue what
to do ???

Well, for you to know what I was doing, here's 54 lines of
/bin/sh giving you a nice impression of why it shot me that
nicely.

--------------------------------------------------------------------------------
#! /bin/sh
#

##
## -- variables 
MONTH=`date +%b`
YEAR=`date +%Y`
MAILDIR=~/mail/
BCKDIR=~/backups/Mail
BCKFILE=${BCKDIR}/mail-${MONTH}${YEAR}
TARFILE=${BCKFILE}.tar
NOFILES=0
FILESIZES=0
fsize=0

## -- sane ?

if [ -f ${BCKFILE} -o -f ${TARFILE} -o -f ${BCKFILE}.tbz -o -f ${BCKFILE}.tar.bz2 ]; then
	EFILE=`/bin/ls ${BCKFILE}*`
	echo " * Warning! There is already a backup file for $MONTH $YEAR !"
	echo " * Info: Critical: Found existing File(s) $EFILE !"
	exit 1
fi

## k, let's go!

cd $MAILDIR || echo "Cannot cd $MAILDIR !"

touch $TARFILE

for i in *; do
	echo "* $i :"
	printf " Backup... "
	if tar rf $TARFILE $i ; then echo -n "(okay)" ; else echo -n "(failed)" ; exit 1 ; fi
	fsize=`wc -c $i | awk '{print $1}'`; FILESIZES=$(( $FILESIZES + $fsize ))
	printf " ...deleting... "
	if rm -f $i ; then echo -n "(okay)" ; else echo -n "(failed)" ; exit 1 ; fi
	printf " ...Touching "
	if touch $i ; then echo "(okay)" ; else echo "(failed)" ; exit 1 ; fi
	NOFILES=$(( $NOFILES + 1))
done

cd $BCKDIR || echo "Cannot cd $BCKDIR !"

BCKFILE=${TARFILE}.bz2

echo " Compressing backup into ${BCKFILE##*/} "

bzip2 -9 $TARFILE

echo ""
echo "* Info: Backed up $NOFILES Mail folders in ${BCKFILE##*/} "
echo "* Info: Folders ate $FILESIZES bytes before, now taking `wc -c $BCKFILE | awk ' {print $1}'`"
exit 0
--------------------------------------------------------------------------------

-Martin Weber