b221b7a8445a3a3f87f2960ea075476b38c8a483
[dump.git] / examples / dump_on_cd_3 / dump_disk
1 #!/bin/sh
2
3 # This script dumps the specified Filesystem via dump on a CD/DVD
4 # DISK_CAPACITY defines the capacity in MB per disk.
5 # The script's own name $0 is passed via the -F option of dump
6 # When using cdrecord/dvdrecord and at least for my DVD-Recorder (a PHILIPS
7 # DVR-A03) it is necessary to define the tracksize for the next track before
8 # the DVD is written. This is done via the -tsize option of cdrecord. Since
9 # tsize takes its arguments in Bytes, the shell cannot compute the value
10 # correctly anymore (value too high), so I use bc.
11
12 # If you use growisofs which does not have the 10 second delay before burning
13 # of cdrecord you may want to uncomment SLEEP="10" to ensure there is data
14 # waiting on the fifo before burning starts
15
16 FIFO="/tmp/dump.$$.fifo"
17 #DISK_CAPACITY=10 # testing
18 DISK_CAPACITY=4300
19 BSIZE="$(echo "$DISK_CAPACITY*1024" | bc -l )"
20 TSIZE="$(echo "$DISK_CAPACITY*1024*1024" | bc -l )"
21 #RECORD_BIN="dd of=/dev/null bs=1k if=" # testing
22 #RECORD_BIN="/usr/bin/dvdrecord dev=0,0,0 fs=64M speed=2 -eject -dao -pad -tsize=$TSIZE -data "
23 RECORD_BIN="/usr/bin/growisofs -Z /dev/dvd="
24 SLEEP="10"
25 DUMP="/sbin/dump"
26
27 cleanup() {
28 rm -f $FIFO
29 }
30
31 error_exit() {
32 retcode=$?
33 echo >&2 "Error $retcode: exiting"
34 exit $retcode
35 }
36
37 trap error_exit ERR
38
39 write_output() {
40 # supplied info from "dump -F":
41 # $1 = filename
42 # $2 = sequence number
43 echo "Please insert disk No. $(($2+1))"
44 ANSWER=""
45 while [ "$ANSWER" != "y" ] ; do
46 echo -n "Is the disk ready? (y/n) "
47 read </dev/tty ANSWER
48 if [ "$ANSWER" == "y" ] ; then
49 ([ -n "$SLEEP" ] && sleep $SLEEP; ${RECORD_BIN}${1}) &
50 return 0
51 elif [ "$ANSWER" == "n" ] ; then
52 EXIT=""
53 echo -n "Do you really want to exit? (y/n) "
54 read </dev/tty EXIT
55 if [ "$EXIT" == "y" ] ; then
56 return 1
57 fi
58 fi
59 done
60 }
61
62 if [ "$#" = "0" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
63 echo >&2 "Usage: $0 <dump options>"
64 echo >&2 "See 'man dump' for dump options"
65 echo >&2 "the dump options -F -f -B are not required and are overridden"
66 exit 1
67 fi
68
69 set -m # We need proper job control
70
71 if [ "$#" = "2" ] && [ -p "$1" ]; then
72 write_output "$@" || (kill $$ >/dev/null 2>&1; exit 1)
73 exit 0
74 else
75 mkfifo $FIFO
76 trap cleanup EXIT
77 if write_output "$FIFO" "0"; then
78 if $DUMP "$@" -F "$0" -f "$FIFO" -B$BSIZE; then
79 kill % >/dev/null 2>&1 # Kill the background writing process
80 else
81 wait % # Or wait for it to complete
82 fi
83 exit 0
84 else
85 exit 1
86 fi
87 fi