#!/bin/sh # This script dumps the specified Filesystem via dump on a CD/DVD # DISK_CAPACITY defines the capacity in MB per disk. # The script's own name $0 is passed via the -F option of dump # When using cdrecord/dvdrecord and at least for my DVD-Recorder (a PHILIPS # DVR-A03) it is necessary to define the tracksize for the next track before # the DVD is written. This is done via the -tsize option of cdrecord. Since # tsize takes its arguments in Bytes, the shell cannot compute the value # correctly anymore (value too high), so I use bc. # If you use growisofs which does not have the 10 second delay before burning # of cdrecord you may want to uncomment SLEEP="10" to ensure there is data # waiting on the fifo before burning starts FIFO="/tmp/dump.$$.fifo" #DISK_CAPACITY=10 # testing DISK_CAPACITY=4300 BSIZE="$(echo "$DISK_CAPACITY*1024" | bc -l )" TSIZE="$(echo "$DISK_CAPACITY*1024*1024" | bc -l )" #RECORD_BIN="dd of=/dev/null bs=1k if=" # testing #RECORD_BIN="/usr/bin/dvdrecord dev=0,0,0 fs=64M speed=2 -eject -dao -pad -tsize=$TSIZE -data " RECORD_BIN="/usr/bin/growisofs -Z /dev/dvd=" SLEEP="10" DUMP="/sbin/dump" cleanup() { rm -f $FIFO } error_exit() { retcode=$? echo >&2 "Error $retcode: exiting" exit $retcode } trap error_exit ERR write_output() { # supplied info from "dump -F": # $1 = filename # $2 = sequence number echo "Please insert disk No. $(($2+1))" ANSWER="" while [ "$ANSWER" != "y" ] ; do echo -n "Is the disk ready? (y/n) " read &2 "Usage: $0 " echo >&2 "See 'man dump' for dump options" echo >&2 "the dump options -F -f -B are not required and are overridden" exit 1 fi set -m # We need proper job control if [ "$#" = "2" ] && [ -p "$1" ]; then write_output "$@" || (kill $$ >/dev/null 2>&1; exit 1) exit 0 else mkfifo $FIFO trap cleanup EXIT if write_output "$FIFO" "0"; then if $DUMP "$@" -F "$0" -f "$FIFO" -B$BSIZE; then kill % >/dev/null 2>&1 # Kill the background writing process else wait % # Or wait for it to complete fi exit 0 else exit 1 fi fi