757661f4a1174dfd8dd06eda74c55987155b730e
[debian/amanda] / changer-src / chg-rait.sh
1 #!@SHELL@
2
3 # chg-rait
4 #
5 # This assumes we have rait-striped drives in several
6 # other amanda changer configs.
7 #
8 # so we have a changerfile that lists other changers and
9 # changer files.
10 #   nchangers=3
11 #   tpchanger_1="chg-mtx"
12 #   changerdev_1="/dev/mtx1"
13 #   changerfile_1="/some/file1"
14 #   tapedev_1="/some/dev"
15 #   tpchanger_2="chg-mtx"
16 #   changerdev_2="/dev/mtx2"
17 #   changerfile_2="/some/file2"
18 #   tapedev_2="/some/dev"
19 #   tpchanger_3="chg-mtx"
20 #   changerdev_3="/dev/mtx3"
21 #   changerfile_3="/some/file3"
22 #   tapedev_3="/some/dev"
23 #
24 # the tapedev_n entries are only needed if the changer script in question
25 # uses tapedev.
26 #
27
28 prefix="@prefix@"
29 exec_prefix="@exec_prefix@"
30 sbindir="@sbindir@"
31 amlibexecdir="@amlibexecdir@"
32 . "${amlibexecdir}/amanda-sh-lib.sh"
33
34 # add sbin and ucb dirs
35 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
36 export PATH 
37
38 #
39 # debugging...
40 #
41 if [ -d "@AMANDA_DBGDIR@" ]; then
42         DBGFILE=@AMANDA_DBGDIR@/rait-changer.debug
43         KIDDEBUG=@AMANDA_DBGDIR@/changer.debug
44         WORK=@AMANDA_DBGDIR@/chgwork$$
45 else
46         DBGFILE=/dev/null
47         KIDDEBUG=/dev/null
48         WORK=/tmp/chgwork$$
49 fi
50
51 exec 2>$DBGFILE
52 echo `_ "arguments: "` $0 $* >&2
53 set -x 
54
55 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
56 if test "$USE_VERSION_SUFFIXES" = "yes"; then
57         SUF="-@VERSION@";
58 else
59         SUF=
60 fi
61 getconf=$sbindir/amgetconf$SUF
62
63
64 changerfile=`$getconf changerfile`
65 . $changerfile
66
67 #
68 # get config items that other changers use to put in our
69 # fake amanda.conf files.
70 #
71 org=`$getconf ORG`
72 mailto=`$getconf mailto`
73
74 #
75 # make a working directory (with amanda.conf) for each changer, and start the
76 # changer script in background for each one
77 #
78
79 i=1
80 while [ $i -le $nchangers ]
81 do
82    eval tpchanger=\$tpchanger_$i
83    eval changerdev=\$changerdev_$i
84    eval changerfile=\$changerfile_$i
85    eval tapedev=\$tapedev_$i
86
87    mkdir -p $WORK/$i
88    cd $WORK/$i
89
90    cat >> amanda.conf <<EOF
91 org             "$ORG"
92 mailto          "$mailto"
93 tpchanger       "$tpchanger"
94 changerdev      "$changerdev"
95 changerfile     "$changerfile"
96 tapedev         "$tapedev"
97
98 define tapetype EXABYTE {
99     comment "default tapetype"
100     length 4200 mbytes
101     filemark 48 kbytes
102     speed 474 kbytes                    
103 }
104 EOF
105
106     (
107         $tpchanger "$@"
108         echo "$?"> exitcode 
109     )  > stdout 2>stderr &
110
111    i=`expr $i + 1`
112 done
113
114 wait
115
116 #
117 # once they've all finished, collect up the results
118 #
119
120 myexit=0
121 myslot=-1
122 mymax=65536
123 myflag=1
124 mydev=""
125 mysep="{"
126
127 case x$1 in
128 x-slot|x-reset|x-eject|x-search|x-label)
129
130     #
131     # read slot number and device from each
132     # slot numbers must match(?!), and is our resulting slot number
133     # resulting device is {dev1,dev2,...} from each one
134     #
135     i=1
136     while [ $i -le $nchangers ]
137     do
138         read exitcode < $WORK/$i/exitcode
139         read n dev < $WORK/$i/stdout
140         echo -------------- >&2
141         cat $WORK/$i/stderr >&2
142         cat $KIDDEBUG >&2
143         echo -------------- >&2
144
145         if [ "$exitcode" != 0 ]
146         then
147             myexit=$exitcode
148         fi
149         if [ $myslot = -1 ]
150         then
151             myslot=$n
152         fi
153         if [ $n != $myslot ]
154         then
155              # synch error!
156             myexit=1
157             echo `_ 'stackers are out of synch, issue a reset'` >&2
158         fi
159         mydev="$mydev$mysep$dev"
160         mysep=","
161
162         i=`expr $i + 1`
163     done
164     mydev="rait:$mydev}"
165     echo $myslot $mydev
166     ;;
167 x-info)
168     #
169     # read info from each
170     # slot numbers must match(?!), and is our resulting slot number
171     # minimum max slots is our resulting max slots
172     # if any can't go backwards, the aggregate can't either
173     #
174     i=1
175     while [ $i -le $nchangers ]
176     do
177         read exitcode < $WORK/$i/exitcode
178         read n max flag < $WORK/$i/stdout
179         echo -------------- >&2
180         cat $WORK/$i/stderr >&2
181         cat $KIDDEBUG >&2
182         echo -------------- >&2
183
184         if [ "$exitcode" != 0 ]
185         then
186              myexit=$exitcode
187         fi
188         if [ $myslot = -1 ]
189         then
190             myslot=$n
191         fi
192         if [ $n != $myslot ]
193         then
194              # synch error!
195             myexit=1
196             echo `_ 'stackers are out of synch, issue a -reset'` >&2
197         fi
198         if [ $max -lt $mymax ]
199         then
200             mymax=$max
201         fi
202         if [ $flag = 0 ]
203         then
204             myflag=0
205         fi
206         i=`expr $i + 1`
207     done
208     echo $myslot $mymax $myflag
209
210 esac
211
212 #
213 # clean up work directories
214 #
215 rm -rf $WORK
216
217 exit $myexit