Cover V02, I05
Article
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6

sep93.tar


Listing 5: restore.bu v2.0--Fast restore utility

1   # @(#) Listing 5 restore.bu v2.0    Fast Restore Utility
2   # Authors: Jon Alder/Ed Schaefer
3   ########################################################################
4   # This program is used to manipulate a backup tape created by fast backup.
5   # This script reads in the file with the tape directory and prepares a menu
6   # for the user.
7
8   # set video variables
9   HI=`tput smso`
10  LO=`tput rmso`
11  CLS=`tput clear`
12  BLINK=`tput blink`
13  TFS=''
14  CDIR=''
15
16  umask 000
17  # Usage Help
18  if [ $1 = "-z" ]; then
19     echo "usage: restore.bu -c [config file]" >&2
20     exit 1
21  fi
22
23
24  ########################################################################
25  # Set variables
26  ########################################################################
27  trap 'echo "Returning tape to the directory.\c";restart' 1 2
28
29  # The program requires the existence of a configuration file that tells
30  # it what commands to use for your version of UNIX as well as where to
31  # put work files.
32
33  if [ $# -lt 1 ] > /dev/null 1>&2
34  then
35     CONFIG=$PWD/config
36     echo "\nSetting CONFIG to $CONFIG and continuing."
37     echo "Hope this is ok.";echo "Type restore.bu -z for help.";sleep 2
38  else
39     while [ $# -gt 0 ]
40     do
41       case $1 in
42          -c)     shift;CONFIG=$1
43                  shift
44                  ;;
45
46          -c*)    CONFIG=`echo $1|cut -c3-`
47                  shift
48                   ;;
49
50          -*)     echo "Usage error"
51                  echo "Usage: restore.bu  -c [config file]" >&2
52                  exit
53                  shift
54                  ;;
55          *)      echo "Usage error"
56                  echo "Usage: restore.bu  -c [config file]" >&2
57                  exit
58                  shift
59                  ;;
60          esac
61     done
62  fi                                                     ;export CONFIG
63
64  if [ -r "$CONFIG" ]; then
65     continue
66  else
67     echo "The config file \"$CONFIG\" was not found. "
68     echo "Check to make sure that the path is correct and re-start."
69     echo "Exiting Restore.bu.";sleep 1;exit 1
70  fi
71
72  ########################################################################
73  # Set variables
74  ########################################################################
75  CURSOR=`grep cursor $CONFIG|cut -d : -f2`            ;export CURSOR
76  FORWARD=`grep forward $CONFIG|cut -d : -f2`          ;export FORWARD
77  NICE=`grep nice $CONFIG|cut -d : -f2`                ;export NICE
78  CPIO_IN=`grep cpio_in $CONFIG|cut -d : -f2`          ;export CPIO_IN
79  CPIO_INL=`grep cpio_inl $CONFIG|cut -d : -f2`        ;export CPIO_INL
80  CPIO_INU=`grep cpio_inu $CONFIG|cut -d : -f2`        ;export CPIO_INU
81  CPIO_OUT=`grep cpio_out $CONFIG|cut -d : -f2`        ;export CPIO_OUT
82  REVERSE=`grep reverse $CONFIG|cut -d : -f2`          ;export REVERSE
83  REWIND=`grep rewind $CONFIG|cut -d : -f2`            ;export REWIND
84  TAPE_CTRL=`grep tapecntrl $CONFIG|cut -d : -f2`      ;export TAPE_CTRL
85  TAPE_DRIVE=`grep tapedevr $CONFIG|cut -d : -f2`      ;export TAPE_DRIVE
86  TAPE_DRIVEN=`grep tapedevn $CONFIG|cut -d : -f2`     ;export TAPE_DRIVEN
87  WORKING_DIR=`grep working_dir $CONFIG|cut -d : -f2`  ;export WORKING_DIR
88
89  ########################################################################
90  # Prepare system and files
91  ########################################################################
92  echo "$CLS$HI...........................Reading in tape directory............................$LO"
93
94  $TAPE_CTRL $TAPE_DRIVE $REWIND 2>/dev/null
95  cd $WORKING_DIR
96  $CPIO_INU<$TAPE_DRIVEN "tape.directory" 2>/dev/null
97
98  pr -3 -a -t -n $WORKING_DIR/tape.directory>$WORKING_DIR/tape.rchoices
99  pr -t -n $WORKING_DIR/tape.directory>$WORKING_DIR/tape.choices
100
101 ########################################################################
102 # This function displays the tape directory
103 ########################################################################
104 DIS_dir() {
105 CDAY=`ls -l $WORKING_DIR/tape.directory|cut -c42-48`
106 CTIME=`ls -l $WORKING_DIR/tape.directory|cut -c49-53`
107
108 echo "$CLS$HI...............Current Tape Directory Created on $CDAY at $CTIME...............$LO"
109 cat $WORKING_DIR/tape.rchoices
110 }
111
112 ########################################################################
113 # This function asks which Tape File System is wanted
114 ########################################################################
115 FTS_dir() {
116 # valid choice loop.
117 while true
118 do
119    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
120         {
121         printf "%d", $1 + 2
122         } '` 0
123
124    echo "$HI Choose the $BLINK NUMBER $LO$HI of a Tape File System to access or X to exit:
$LO\c"
125    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
126         {
127         printf "%d", $1 + 2
128         } '` 66
129    read TFS;export TFS
130
131    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
132         {
133         printf "%d", $1 + 1
134         } '` 69
135    echo "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
136
137    # Check to make see if they want to quit.
138    if [ "$TFS" = "X" -o "$TFS" = "x" ]; then
139       clear_bottom;$CURSOR 16 0;echo "Quiting now.";rewind 2>/dev/null;exit
140     fi
141
142     # find the highest available choice.
143     for i in `cat $WORKING_DIR/tape.choices| awk '{ print $1 }'`
144     do
145        echo $i>$WORKING_DIR/HIGH_CHOICE
146     done
147
148     HC=`cat $WORKING_DIR/HIGH_CHOICE`;export HC
149     # check to make sure their choice is either >=1 or <= $HC
150     if [ "$TFS" -lt 1 -o "$TFS" -gt "$HC" ]; then
151        clear_bottom;$CURSOR 16 0
152        echo "Please choose the $HI$BLINK NUMBER $LO representing your choice."
153        sleep 2
154      else
155        break
156      fi
157 done
158
159 CDIR=`awk '
160    {
161    if ($1 == x)
162       printf "%s\n", $2
163    }
164    ' x=$TFS tape.choices `
165
166 SFB_NUM=`echo $TFS|awk '{ print x-1 }' x="$TFS"`
167 echo "Fast Forwarding $SFB_NUM Tape Sections">$WORKING_DIR/tape.sfb_num
168
169 echo "\n"
170 echo "`cat $WORKING_DIR/tape.sfb_num`\c"
171 echo " to: $CDIR\c"
172 echo "\n"
173
174 $TAPE_CTRL $TAPE_DRIVEN $FORWARD $SFB_NUM 2>/dev/null
175 }
176
177 ########################################################################
178 # This function is the main menu for nrestore
179 ########################################################################
180 nrestore_menu() {
181 while true
182 do
183    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
184         {
185         printf "%d", $1 + 2
186         } '` 0
187    echo "$HI...........................Tape Management Main Menu............................$LO\n"
188    clear_bottom
189    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
190         {
191         printf "%d", $1 + 3
192         } '` 29
193    echo "$HI Working on TFS No.$TFS $LO"
194    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
195         {
196         printf "%d", $1 + 4
197         } '` 35
198    echo "$HI$BLINK $CDIR $LO"
199    echo "$HI 1 $LO View file system files                                 "
200    echo "                                                                 "
201    echo "$HI 2 $LO Restore a file                                         "
202    echo "                                                                 "
203    echo "$HI 3 $LO Rewind Tape Drive and Exit                             "
204    echo "                                                                 "
205    echo "$HI 4 $LO Choose another Tape File System                        "
206    echo "                                                                 "
207    echo "$HI 5 $LO Exit (Leaving tape at current position)                "
208    echo "                                                                 "
209    $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
210         {
211         printf "%d", $1 + 7
212         } '` 51
213    echo "$HI Your Choice? $LO\c"
214   read RESP
215   case $RESP in
216     1) clear_bottom;$CURSOR 16 0;echo "Viewing files";sleep 1;echo "$CLS"
217        echo "A list of the files in TFS $CDIR will be saved in $WORKING_DIR/tfs_list"
218        sleep 2
219     $CPIO_INL<$TAPE_DRIVEN|tee $WORKING_DIR/tfs_list|pg -nsp "Pg %d> Type q to
quit:"
220     restart
221     ;;
222     2) clear_bottom;$CURSOR 16 0;echo "Going to Restoring Files Menu"
223     sleep 1;RF_menu;;
224     3) clear_bottom;$CURSOR 16 0;echo "Rewinding tape";rewind 2>/dev/null
225     echo "Done!";exit;;
226     4) clear_bottom;$CURSOR 16 0;echo "Going to the Top";sleep 1
227     restart
228     ;;
229     5) clear_bottom;$CURSOR 16 0;echo "Leaving";exit;;
230     *)$CURSOR 20 30;echo "$HI Invalid Choice.$LO"
231     sleep 1;$CURSOR 20 30;echo "                        ";;
232   esac
233 done
234 }
235
236 ########################################################################
237 # This function displays the file restore menu
238 ########################################################################
239 RF_menu() {
240 $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
241         {
242         printf "%d", $1 + 2
243         } '` 0
244 echo "$HI..........................Tape Management Restore Menu..........................$LO\n"
245 clear_bottom
246 $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
247         {
248         printf "%d", $1 + 3
249         } '` 29
250 echo "$HI$BLINK Working on TFS No.$TFS $LO"
251 echo "                                                                 \n"
252 echo "$HI Please enter the complete restore path:$LO  \c"
253 read REST
254 echo "\n$HI Do you want to overwrite existing files if found?$LO \c"
255 read OV
256 case $OV in
257    [Yy]*) SW="-icavBmud";;
258    [Nn]*) SW="-icavBmd";;
259 esac
260 echo "\n$HI Is this a high priority restore?$LO \c"
261 read HP
262 case $HP in
263   [Yy]*) CPIO="$NICE cpio";;
264   [Nn]*) CPIO="cpio";;
265 esac
266 cd /
267 echo "$CLS"
268 echo "$HI..........................Restoring files. Please wait..........................$LO\n"
269 echo "\n$HI$BLINK Starting restore on $REST. Press Break to abort.$LO"
270 sleep 3
271 $CPIO $SW < $TAPE_DRIVEN "$REST"
272 cd $WORKING_DIR
273 restart
274 }
275
276 ########################################################################
277 # This function clears to the bottom of screen
278 ########################################################################
279 clear_bottom() {
280 $CURSOR `wc $WORKING_DIR/tape.rchoices|awk '
281         {
282         printf "%d", $1 + 3
283         } '` 0
284
285 CROW=`wc $WORKING_DIR/tape.rchoices|awk '
286         {
287         printf "%d", 20 - $1
288         } '`
289
290 while [ "$CROW" -gt 0 ]
291 do
292   echo "                                                                              "
293   CROW=`expr $CROW - 1`
294 done>$WORKING_DIR/tape.clear_bot
295 cat $WORKING_DIR/tape.clear_bot
296 }
297
298 ########################################################################
299 # This function rewinds the tape to physical beginning and then forwards to volume
300 # one skipping volume 0
301 ########################################################################
302 restart() {
303 echo "$HI Rewinding tape.$LO"
304 $TAPE_CTRL $TAPE_DRIVE $REWIND 2>/dev/null
305 $TAPE_CTRL $TAPE_DRIVEN $FORWARD 1 2>/dev/null
306 DIS_dir
307 FTS_dir
308 }
309
310 ########################################################################
311 # This function rewinds the tape to the physcial beginning
312 ########################################################################
313 rewind() {
314 $TAPE_CTRL $TAPE_DRIVE $REWIND 2>/dev/null
315 }
316
317 #######################################################################
318 # The main program...
319 #######################################################################
320 DIS_dir
321 FTS_dir
322 nrestore_menu