oops...checked in some temporary changes from testing on ia64 box.
[xfstests-dev.git] / common.dump
1 ##/bin/sh
2
3 #
4 # Functions useful for xfsdump/xfsrestore tests
5 #
6 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
7
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of version 2 of the GNU General Public License as
10 # published by the Free Software Foundation.
11
12 # This program is distributed in the hope that it would be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 # Further, this software is distributed without any warranty that it is
17 # free of the rightful claim of any third person regarding infringement
18 # or the like.  Any license provided herein, whether implied or
19 # otherwise, applies only to this software file.  Patent licenses, if
20 # any, provided herein do not apply to combinations of this program with
21 # other software, or any other product whatsoever.
22
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write the Free Software Foundation, Inc., 59
25 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
26
27 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 # Mountain View, CA  94043, or:
29
30 # http://www.sgi.com 
31
32 # For further information regarding this notice, see: 
33
34 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #
36
37 # --- initializations ---
38 rm -f $seq.full
39
40 if [ -n "$DEBUGDUMP" ]; then
41   _dump_debug=-v5
42   _restore_debug=-v5
43   _invutil_debug=-d
44 fi
45  
46 # Use dump/restore in qa directory for debugging
47 #PATH=".:$PATH"
48 #export PATH
49 #which xfsdump
50 #which xfsrestore
51
52 # status returned for not run tests
53 NOTRUNSTS=2
54
55 # name those directories
56 dump_file=$tmp.dumpfile
57 dump_sdir=dumpdir
58 dump_dir=$SCRATCH_MNT/$dump_sdir
59 restore_sdir=restoredir
60 restore_dir=$SCRATCH_MNT/$restore_sdir
61
62 dumptape=$TAPE_DEV
63 media_label="stress_tape_media"
64 session_label="stress_$seq"
65
66 nobody=4 # define this uid/gid as a number
67
68 _need_to_be_root
69
70 # install our cleaner
71 trap "_cleanup; exit \$status" 0 1 2 3 15
72
73 # start inventory from a known base - move it aside for test
74 if [ -d /var/xfsdump/inventory ]; then
75     if [ -d /var/xfsdump/inventory.$seq ]; then    
76         rm -rf /var/xfsdump/inventory.$seq
77     fi
78     mv /var/xfsdump/inventory /var/xfsdump/inventory.$seq
79 fi
80
81
82 #
83 # do a remote/local mt
84 #
85 _mt()
86 {
87     op=$1
88     if _isrmt; then  
89         # REMOTE
90         _rmtdev=`echo $dumptape | $AWK_PROG -F: '{print $2}'`
91
92         if echo $dumptape | grep '@' >/dev/null; then
93             _spec=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
94             _rmtuser=`echo $_spec | $AWK_PROG -F@ '{print $1}'`
95             _rmthost=`echo $_spec | $AWK_PROG -F@ '{print $2}'`
96             rsh -n -l $_rmtuser $_rmthost "mt -t $_rmtdev $op"
97         else
98             _rmthost=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
99             rsh -n $_rmthost "mt -t $_rmtdev $op"
100         fi
101     else
102         #LOCAL
103         mt -t $dumptape $op
104     fi
105 }
106
107 _check_onl()
108 {
109     _limit=10
110     i=0
111     while [ $i -lt $_limit ]; do  
112         echo "Checking online..." >>$seq.full
113         if _mt status >$tmp.status 2>&1; then
114             break; 
115         else
116             sleep 2 
117         fi
118         i=`expr $i + 1`
119     done
120
121
122     if [ $i -eq $_limit ]; then
123         echo "ERROR: mt -f $dumptape failed"
124         cat $tmp.status
125
126         echo "mt -f $dumptape failed" >$seq.notrun 
127         status=$NOTRUNSTS
128         exit
129     fi 
130
131
132     if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
133         :
134     else
135         echo "ERROR: $dumptape is not online"
136         cat $tmp.status
137
138         echo "dumptape, $dumptape, is not online" >$seq.notrun 
139         status=$NOTRUNSTS
140         exit
141     fi
142 }
143
144 _wait_tape()
145 {
146     echo "Wait for tape, $dumptape, ..." >>$seq.full
147
148     i=0
149     while [ $i -lt 20 ]; do  
150         echo "Checking status..." >>$seq.full
151         if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
152             break; 
153         else
154             sleep 2 
155         fi
156         i=`expr $i + 1`
157     done
158 }
159
160 #
161 # Keep trying so we know we really have rewound
162 #
163 _rewind()
164 {
165     echo "Initiate rewind..." >>$seq.full
166     _wait_tape
167     _mt rewind >/dev/null
168     _wait_tape
169 }
170
171 #
172 # Do a custom erase because: 
173 # (i) some machines don't support it
174 # (ii) some machines take forever to do it
175 #
176 _erase_soft()
177 {
178     echo "Erasing tape" | tee -a $seq.full
179     _rewind
180     _mt weof 3
181     _rewind
182 }
183
184 _erase_hard()
185 {
186     echo "Erasing tape" | tee -a $seq.full
187     _mt erase
188 }
189
190 _isrmt()
191 {
192     echo $dumptape | grep ':' >/dev/null
193 }
194
195 #
196 # Get tape ready
197 #
198 _set_variable()
199 {
200     if _isrmt; then
201         :
202     else
203         # LOCAL
204         echo "Put scsi tape driver into variable block size mode"
205         mt -f $dumptape setblk 0
206     fi  
207 }
208
209 _require_tape()
210 {
211     dumptape=$1
212
213     if [ -z "$dumptape" ]; then
214         echo "This test requires a dump tape - none was specified"
215         echo "No dump tape specified" >$seq.notrun 
216         status=$NOTRUNSTS
217         exit
218     fi
219
220     _check_onl
221     _set_variable
222 }
223
224 _error()
225 {
226     echo "Error: $*" | tee -a $seq.full
227     echo "(see $seq.full for details)"
228     status=1
229     exit
230 }
231
232 _wipe_fs()
233 {
234     _require_scratch
235
236     mkfs -t xfs -f $SCRATCH_DEV >>$seq.full  ||\
237         _error "mkfs failed"
238       
239     mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
240         _error "mount failed"
241 }
242
243
244 # Cleanup created dirs and files
245 # Called by trap
246 #
247 _cleanup()
248 {
249     cd $here
250     rm -f $tmp.*
251
252     if [ -n "$DEBUGDUMP" ]; then
253         # save it for inspection
254         tar -zcvf $seq.inventory.tgz /var/xfsdump/inventory
255         ls -lR /var/xfsdump/inventory >$seq.inventory.ls
256     fi
257
258     # put inventory dir back
259     if [ -d /var/xfsdump/inventory.$seq ]; then
260         rm -rf /var/xfsdump/inventory # get rid of new one
261         mv /var/xfsdump/inventory.$seq /var/xfsdump/inventory
262     fi
263
264     if [ $status -ne $NOTRUNSTS ]; then
265         # Sleep added to stop _check_fs from complaining that the
266         # scratch_dev is still busy
267         sleep 10
268
269         _check_fs $SCRATCH_DEV
270     fi
271 }
272
273 _stable_fs()
274 {
275     umount $SCRATCH_MNT >>$seq.full ||\
276         _error "unmount failed"
277     mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
278         _error "mount failed"
279 }
280
281 #
282 # Run src/fsstress to create a mixture of 
283 # files,dirs,links,symlinks
284 #
285 # Pinched from test 013.
286 #
287 _create_dumpdir_stress()
288 {
289     echo "Creating directory system to dump using src/fsstress."
290
291     _wipe_fs
292     _setup_seq_out
293
294     _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
295     _count=200
296     rm -rf $dump_dir
297     if ! mkdir $dump_dir; then
298         echo "    failed to mkdir $dump_dir"
299         status=1
300         exit
301     fi
302     echo ""
303     echo "-----------------------------------------------"
304     echo "fsstress : $_param"
305     echo "-----------------------------------------------"
306     if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
307     then
308         echo "    fsstress (count=$_count) returned $? - see $seq.full"
309         
310         echo "--------------------------------------"       >>$here/$seq.full
311         echo "output from fsstress:"                        >>$here/$seq.full
312         echo "--------------------------------------"       >>$here/$seq.full
313         cat $tmp.out                                        >>$here/$seq.full
314         status=1
315     fi
316
317     _stable_fs
318 }
319
320 _mk_fillconfig1()
321 {
322     cat <<End-of-File >$tmp.config
323 # pathname      size in bytes   owner   group
324 #
325 small           10      $nobody $nobody
326 big             102400  daemon  sys
327 sub/small       10      bin     bin
328 sub/big         102400  $nobody sys
329 #
330 sub/a           1       $nobody $nobody
331 sub/b           2       $nobody $nobody
332 sub/c           4       $nobody $nobody
333 sub/d           8       $nobody $nobody
334 sub/e           16      $nobody $nobody
335 sub/f           32      $nobody $nobody
336 sub/g           64      $nobody $nobody
337 sub/h           128     $nobody $nobody
338 sub/i           256     $nobody $nobody
339 sub/j           512     $nobody $nobody
340 sub/k           1024    $nobody $nobody
341 sub/l           2048    $nobody $nobody
342 sub/m           4096    $nobody $nobody
343 sub/n           8192    $nobody $nobody
344 #
345 sub/a00         100     $nobody $nobody
346 sub/b00         200     $nobody $nobody
347 sub/c00         400     $nobody $nobody
348 sub/d00         800     $nobody $nobody
349 sub/e00         1600    $nobody $nobody
350 sub/f00         3200    $nobody $nobody
351 sub/g00         6400    $nobody $nobody
352 sub/h00         12800   $nobody $nobody
353 sub/i00         25600   $nobody $nobody
354 sub/j00         51200   $nobody $nobody
355 sub/k00         102400  $nobody $nobody
356 sub/l00         204800  $nobody $nobody
357 sub/m00         409600  $nobody $nobody
358 sub/n00         819200  $nobody $nobody
359 #
360 sub/a000        1000    $nobody $nobody
361 sub/e000        16000   $nobody $nobody
362 sub/h000        128000  $nobody $nobody
363 sub/k000        1024000 $nobody $nobody
364 End-of-File
365 }
366
367 _mk_fillconfig2()
368 {
369     cat <<End-of-File >$tmp.config
370 # pathname      size in bytes
371 #
372 smalll          10      $nobody $nobody
373 biggg           102400  $nobody $nobody
374 sub/smalll      10      $nobody $nobody
375 sub/biggg       102400  $nobody $nobody
376 End-of-File
377 }
378
379 _mk_fillconfig_perm()
380 {
381     # dir_guid: ugo=rwx,g+s on dir is for IRIX chmod(1)
382
383     cat <<End-of-File >$tmp.config
384 # pathname      size/dir  user group mode
385 #
386 file_suid       10      $nobody $nobody 04777
387 file_guid       10      $nobody $nobody 02777
388 file_sticky     10      $nobody $nobody 01777
389 file_mix1       10      $nobody $nobody 761
390 file_mix2       10      $nobody $nobody 642
391 dir_suid        d       $nobody $nobody 04777
392 dir_guid        d       $nobody $nobody ugo=rwx,g+s
393 dir_sticky      d       $nobody $nobody 01777
394 dir_mix1        d       $nobody $nobody 761
395 dir_mix2        d       $nobody $nobody 642
396 End-of-File
397 }
398
399 #
400 # Create a bunch of directories/files of different sizes
401 # filled with data.
402 #
403 # Pinched from test 001.
404 #
405 _do_create_dumpdir_fill()
406 {
407     echo "Creating directory system to dump using src/fill."
408
409     if mkdir -p $dump_dir
410     then
411         :
412     else
413         echo "Error: cannot mkdir \"$dump_dir\""
414         exit 1
415     fi
416     cd $dump_dir
417
418     $verbose && echo -n "Setup "
419     sed -e '/^#/d' $tmp.config \
420     | while read file nbytes owner group perms
421     do
422         if [ $nbytes = "d" ]; then
423             # create a directory
424             dir=$file   
425             if [ ! -d $dir ]
426             then
427                 if mkdir $dir
428                 then
429                     :
430                 else
431                     $verbose && echo
432                     echo "Error: cannot mkdir \"$dir\""
433                     exit 1
434                 fi
435             fi
436         else
437             # create a directory/file
438             dir=`dirname $file`
439             if [ "$dir" != "." ]
440             then
441                 if [ ! -d $dir ]
442                 then
443                     if mkdir $dir
444                     then
445                         :
446                     else
447                         $verbose && echo
448                         echo "Error: cannot mkdir \"$dir\""
449                         exit 1
450                     fi
451                 fi
452             fi
453             rm -f $file
454             if $here/src/fill $file $file $nbytes
455             then
456                 :
457             else
458                 $verbose && echo
459                 echo "Error: cannot create \"$file\""
460                 exit 1
461             fi
462         fi
463         if [ -n "$owner" -a -n "$group" ]; then
464             chown $owner.$group $file
465         fi
466         if [ -n "$perms" ]; then
467             chmod $perms $file
468         fi
469         $verbose && echo -n "."
470     done
471     $verbose && echo
472
473     cd $here
474 }
475
476
477 _create_dumpdir_fill()
478 {
479     _wipe_fs
480     _setup_seq_out
481     _mk_fillconfig1
482     _do_create_dumpdir_fill
483     _stable_fs
484 }       
485
486 _create_dumpdir_fill2()
487 {
488     _wipe_fs
489     _setup_seq_out
490     _mk_fillconfig2
491     _do_create_dumpdir_fill
492     _stable_fs
493 }       
494
495 _create_dumpdir_fill_perm()
496 {
497     _wipe_fs
498     _setup_seq_out
499     _mk_fillconfig_perm
500     _do_create_dumpdir_fill
501     _stable_fs
502 }       
503
504
505
506 #
507 # Append a subset of the fill'ed files
508 # So we can see if just these get dumped on an incremental
509 #
510 _append_dumpdir_fill()
511 {
512     cd $dump_dir
513     cat <<End-of-File >$tmp.config
514 # pathname
515 #
516 small   
517 sub/big 
518 #
519 sub/a
520 sub/c
521 sub/e
522 End-of-File
523     sed -e '/^#/d' $tmp.config \
524     | while read file
525     do
526         echo 'Extra text' >>$file
527     done
528
529     cd $here
530     _stable_fs
531 }
532
533 _do_create_dump_symlinks()
534 {
535     echo "Creating directory system of symlinks to dump."
536
537     if mkdir -p $dump_dir
538     then
539         :
540     else
541         echo "Error: cannot mkdir \"$dump_dir\""
542         exit 1
543     fi
544     cd $dump_dir
545
546     $verbose && echo -n "Setup "
547     sed -e '/^#/d' $tmp.config \
548     | while read file nbytes owner group owner2 group2 perms perms2
549     do
550         dir=`dirname $file`
551         if [ "$dir" != "." ]
552         then
553             if [ ! -d $dir ]
554             then
555                 if mkdir $dir
556                 then
557                     :
558                 else
559                     $verbose && echo
560                     echo "Error: cannot mkdir \"$dir\""
561                     exit 1
562                 fi
563             fi
564         fi
565         rm -f $file
566         touch $file
567
568         # Do chmod on symlink using umask.
569         # This won't do the right thing as it subtracts permissions.
570         # However, I don't care, as long as I get some different perms
571         # for testing.
572         if [ -n "$perms2" ]; then
573             omask=`umask`
574             umask $perms2
575         fi
576         ln -s $file $file-link
577         if [ -n "$perms2" ]; then
578             umask $omask        
579         fi
580
581         if [ -n "$owner" -a -n "$group" ]; then
582             chown $owner.$group $file
583         fi
584         if [ -n "$owner" -a -n "$group" ]; then
585             chown -h $owner.$group $file-link
586         fi
587         if [ -n "$perms" ]; then
588             chmod $perms $file
589         fi
590         $verbose && echo -n "."
591     done
592     $verbose && echo
593
594     cd $here
595 }
596
597 _mk_symlink_config()
598 {
599     cat <<End-of-File >$tmp.config
600 # path  size    owner1  group1  owner2  group2  perm1   perm2 
601 #
602 a       0       $nobody $nobody daemon  sys     124     421
603 b       0       daemon  sys     bin     bin     347     743
604 sub/a   0       bin     bin     $nobody sys     777     777
605 sub/b   0       $nobody sys     $nobody $nobody 367     763
606 End-of-File
607 }
608
609 _create_dumpdir_symlinks()
610 {
611     _wipe_fs
612     _setup_seq_out
613     _mk_symlink_config
614     _do_create_dump_symlinks
615     _stable_fs
616 }       
617
618 #
619 # Filter for ls
620 # Filter out dates on symlinks
621 #
622 _ls_filter()
623 {
624   $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
625         {print}' \
626   | sed -e 's/total [0-9][0-9]*/total TOTAL/'
627 }
628
629
630
631 # Filter out the non-deterministic dump msgs from
632 # xfsdump and xfsrestore
633 #
634 _dump_filter()
635 {
636   sed \
637       -e "s/`hostname`/HOSTNAME/"   \
638       -e "s#$SCRATCH_DEV#SCRATCH_DEV#"    \
639       -e "s#$dumptape#TAPE_DEV#"    \
640       -e "s#$SCRATCH_MNT#SCRATCH_MNT#"    \
641       -e "s#$dump_file#DUMP_FILE#"  \
642       -e 's/id:[        ]*[0-9a-f-]*/id: ID/'  \
643       -e 's/time:[      ].*/time: TIME/'       \
644       -e 's/date:[      ].*/date: DATE/'       \
645       -e 's/dump begun .*/dump begun DATE/'    \
646       -e 's/[0-9][0-9]* seconds/SECS seconds/' \
647       -e 's/restore.[0-9][0-9]*/restore.PID/' \
648       -e 's/ino [0-9][0-9]*/ino INO/' \
649       -e '/: dump size/s/[1-9][0-9]*/NUM/'     \
650       -e '/dump size:/s/[1-9][0-9]*/NUM/'      \
651       -e '/media file size/s/[1-9][0-9]*/NUM/' \
652       -e '/mfile size:[  ]*/s/[1-9][0-9]*/NUM/' \
653       -e '/\/dev\/tty/d' \
654       -e '/inventory session uuid/d' \
655
656 }
657
658 _invutil_filter()
659 {
660   _dump_filter \
661   | sed \
662         -e 's/UUID[     ]*:[    ][0-9a-f-]*/UUID                :       ID/' \
663         -e 's/TIME OF DUMP[     ]*:.*/TIME OF DUMP      :       TIME/' \
664         -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
665         -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
666
667 }
668
669 _dir_filter()
670 {
671   sed \
672     -e "s#$dump_file#DUMP_FILE#"      \
673     -e "s#$SCRATCH_DEV#SCRATCH_DEV#"        \
674     -e "s#$dumptape#TAPE_DEV#"         \
675     -e "s#$dump_dir#DUMP_DIR#g"       \
676     -e "s#$restore_dir#RESTORE_DIR#g" \
677     -e "s#$SCRATCH_MNT#SCRATCH_MNT#g"       \
678     -e "s#$dump_sdir#DUMP_SUBDIR#g"   \
679     -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
680
681 }
682
683 _parse_args()
684 {
685     OPTIND=0
686     dump_args=""
687     while getopts "f:FL:o" c $*
688     do
689         case $c
690         in
691         f)
692             [ -z "$OPTARG" ] && _error "missing argument for -f"
693             dumptape=$OPTARG    
694             ;;
695         L)
696             [ -z "$OPTARG" ] && _error "missing argument for -L"
697             session_label=$OPTARG       
698             ;;
699         o)
700             dump_args="$dump_args -o"
701             ;;
702         F)
703             dump_args="$dump_args -F"
704             ;;
705         \?)
706             _error "invalid argument"
707             ;;
708         esac
709     done
710 }
711
712
713 #
714 # Dump a subdir
715 #
716 _do_dump_sub()
717 {
718     _parse_args $*
719
720     echo "Dumping to tape..."
721     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
722     echo "xfsdump $opts" | _dir_filter  
723     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
724 }
725
726 #
727 # Do full level 0 dump
728 #
729 _do_dump()
730 {
731     _parse_args $*
732
733     echo "Dumping to tape..."
734     opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
735     echo "xfsdump $opts" | _dir_filter  
736     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
737 }
738
739
740 #
741 # Do full dump with -m
742 #
743 _do_dump_min()
744 {
745     _parse_args $*
746
747     echo "Dumping to tape..."
748     onemeg=1048576
749     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
750     echo "xfsdump $opts" | _dir_filter  
751     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
752 }
753
754 #
755 # Do level 1 incremental dump
756 #
757 _do_dump_incremental()
758 {
759     _parse_args $*
760
761     echo "Dumping incrementally to tape..."
762     opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
763     echo "xfsdump $opts" | _dir_filter  
764     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
765 }
766
767 #
768 # Do full dump to file
769 #
770 _do_dump_file()
771 {
772     _parse_args $*
773
774     echo "Dumping to file..."
775     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
776     echo "xfsdump $opts" | _dir_filter  
777     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
778 }
779
780
781 _prepare_restore_dir()
782 {
783     rm -rf $restore_dir
784     if ! mkdir $restore_dir; then
785         echo "    failed to mkdir $restore_dir"
786         status=1
787         exit
788     fi
789 }
790
791
792 #
793 # Get tape ready and restore dir
794 #
795 _prepare_restore()
796 {
797     _prepare_restore_dir
798
799     echo "Rewinding tape"
800     _rewind
801 }
802
803 #
804 # Restore the tape into $restore_dir
805 #
806 _do_restore()
807 {
808     _parse_args $*
809     _prepare_restore
810
811
812     echo "Restoring from tape..."
813     opts="$_restore_debug$dump_args -f $dumptape  -L $session_label $restore_dir"
814     echo "xfsrestore $opts" | _dir_filter  
815     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
816 }
817
818 #
819 # Restore the tape into $restore_dir using -m
820 #
821 _do_restore_min()
822 {
823     _parse_args $*
824     _prepare_restore
825
826     echo "Restoring from tape..."
827     onemeg=1048576
828     opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
829     echo "xfsrestore $opts" | _dir_filter  
830     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
831 }
832
833 #
834 # Restore the tape from a dump file
835 #
836 _do_restore_file()
837 {
838     _parse_args $*
839     _prepare_restore_dir
840
841     echo "Restoring from file..."
842     opts="$_restore_debug$dump_args -f $dump_file  -L $session_label $restore_dir"
843     echo "xfsrestore $opts" | _dir_filter  
844     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
845 }
846
847 #
848 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
849 #
850 # Use -s as we want to dump and restore to the same xfs partition
851 #
852 _do_dump_restore()
853 {
854     _parse_args $*
855     _prepare_restore_dir
856     echo "xfsdump|xfsrestore ..."
857     restore_opts="$_restore_debug - $restore_dir"
858     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
859     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter  
860     xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
861     _dump_filter <$tmp.dump.mlog
862 }
863
864 #
865 # Compare dumped subdirectory with restored dir
866 # using ls -lR.
867 # Thus no contents are compared but permissions, sizes,
868 # owners, etc... are.
869 #
870 _ls_compare_sub()
871 {
872     #
873     # verify we got back what we dumped
874     #
875     echo "Comparing listing of dump directory with restore directory"
876     ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
877     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
878     | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
879
880     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
881 }
882
883 #
884 # filter out the date fields
885 #
886 _ls_nodate_filter()
887 {
888     $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
889 }
890
891 #
892 # _ls_compare_sub but don't compare dates
893 _ls_nodate_compare_sub()
894 {
895     #
896     # verify we got back what we dumped
897     #
898     echo "Comparing listing of dump directory with restore directory"
899     ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
900     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
901     | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
902
903     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
904 }
905
906
907 #
908 # Compare using recursive diff the files of the dumped
909 # subdirectory.
910 # This one will compare the contents.
911 #
912 _diff_compare_sub()
913 {
914     echo "Comparing dump directory with restore directory"
915     diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
916 }
917
918 #
919 # Compare using recursive diff the files of the dumped
920 # filesystem
921 #
922 _diff_compare()
923 {
924     echo "Comparing dump directory with restore directory"
925     diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
926 }
927
928 #
929 # Check out the dump inventory
930 #
931 _dump_inventory()
932 {
933     xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter 
934 }
935
936 #
937 # Do the xfsinvutil cmd with debug and filters
938 # Need to set variable: "$middate" to the invutil date 
939 #
940 _do_invutil()
941 {
942     host=`hostname`
943     echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
944     xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
945     | tee -a $seq.full | _invutil_filter
946 }
947
948 # make sure this script returns success
949 /bin/true