Subject: Re: Suggestions for a backup solution
To: None <netbsd-users@netbsd.org>
From: Jim Breton <jamesb-netbsd@alongtheway.com>
List: netbsd-users
Date: 01/07/2002 00:49:36
On Fri, Jan 04, 2002 at 10:45:10AM +0100, Wojciech Puchar wrote:
> writing real time so it SHOULD work but may not :)

Thank you, it does work. :) I have modified it a bit, I'll paste the
result at the bottom of this message.

In the meantime, has anyone looked into implementing compression
directly in dump?

Someone has implemented it on the linux port:

http://www.geocrawler.com/archives/3/1111/2001/7/0/6262664/

Apparently it also correctly handles splitting the compressed data into
the desired chunks.  Seems like a feature that has been needed for a
long time, no?



Here's the modified script:

#/bin/sh
#backup to CD-RW with gzip hack.
#run with -dumplevel as parameter

#Warning - this script assumes that every device, speed and buffer
#settings are already present in /etc/default/cdrecord

cdrecord=/opt/bin/cdrecord

case $(uname -s) in
*BSD)	DUMP_OPTIONS="-b 32 -r 128 -B 100000000 -u"
;;
Linux)	DUMP_OPTIONS="-b 32 -B 100000000 -u"
;;
esac

#change it to whatever your CD-RW fits.
VOLUME_SIZE=$((333000*2048))

#maybe 'compress' for slower machines or gzip without -1 for alpha ;)?
COMPRESSOR="gzip -1"

BAKTMPDIR=${TMPDIR:-/tmp}/_backup.$$

cleanup () {
find $BAKTMPDIR -type p -print0 | xargs -0 rm && rmdir $BAKTMPDIR
exit
}

trap cleanup 1 2 3 13 15

mkdir -m 0700 $BAKTMPDIR || exit 1
cd $BAKTMPDIR || exit 1

#26*4 volumes is enough? if not add more letters in first line
for x in a b c d ; do
	for y in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do
 		mkfifo -m 0700 x$x$y || exit 1
	done
done

dump -f - $DUMP_OPTIONS "$@" | $COMPRESSOR | split -b $VOLUME_SIZE &

for x in a b c d ; do
	for y in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do
		echo "** Insert volume $x$y and press Enter, or CTRL+C to cancel"
		read line || cleanup

		#making sure CD-RW is blanked
		echo Blanking CD-RW...
		$cdrecord blank=fast || exit 1

		echo Recording...
		$cdrecord -data -eject x$x$y || cleanup
		echo "done."
	done
done