merge up to 2.4.12
[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 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
75     if [ -d $dir ]; then
76         [ -d $dir.$seq ] && rm -rf $dir.$seq
77         mv $dir $dir.$seq
78     fi
79 done
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         for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
255             [ -d $dir ] || continue
256             tar -zcvf $seq.inventory.tgz $dir
257             ls -lR $dir >$seq.inventory.ls
258         done
259     fi
260
261     # put inventory dir back
262     for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
263         [ -d $dir.$seq ] || continue
264         rm -rf $dir             # get rid of new one
265         mv $dir.$seq $dir
266     done
267
268     if [ $status -ne $NOTRUNSTS ]; then
269         # Sleep added to stop _check_fs from complaining that the
270         # scratch_dev is still busy
271         sleep 10
272
273         _check_fs $SCRATCH_DEV
274     fi
275 }
276
277 _stable_fs()
278 {
279     umount $SCRATCH_MNT >>$seq.full ||\
280         _error "unmount failed"
281     mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
282         _error "mount failed"
283 }
284
285 #
286 # Run src/fsstress to create a mixture of 
287 # files,dirs,links,symlinks
288 #
289 # Pinched from test 013.
290 #
291 _create_dumpdir_stress()
292 {
293     echo "Creating directory system to dump using src/fsstress."
294
295     _wipe_fs
296     _setup_seq_out
297
298     _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
299     _count=200
300     rm -rf $dump_dir
301     if ! mkdir $dump_dir; then
302         echo "    failed to mkdir $dump_dir"
303         status=1
304         exit
305     fi
306     echo ""
307     echo "-----------------------------------------------"
308     echo "fsstress : $_param"
309     echo "-----------------------------------------------"
310     if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
311     then
312         echo "    fsstress (count=$_count) returned $? - see $seq.full"
313         
314         echo "--------------------------------------"       >>$here/$seq.full
315         echo "output from fsstress:"                        >>$here/$seq.full
316         echo "--------------------------------------"       >>$here/$seq.full
317         cat $tmp.out                                        >>$here/$seq.full
318         status=1
319     fi
320
321     _stable_fs
322 }
323
324 _mk_fillconfig1()
325 {
326     cat <<End-of-File >$tmp.config
327 # pathname      size in bytes   owner   group
328 #
329 small           10      $nobody $nobody
330 big             102400  daemon  sys
331 sub/small       10      bin     bin
332 sub/big         102400  $nobody sys
333 #
334 sub/a           1       $nobody $nobody
335 sub/b           2       $nobody $nobody
336 sub/c           4       $nobody $nobody
337 sub/d           8       $nobody $nobody
338 sub/e           16      $nobody $nobody
339 sub/f           32      $nobody $nobody
340 sub/g           64      $nobody $nobody
341 sub/h           128     $nobody $nobody
342 sub/i           256     $nobody $nobody
343 sub/j           512     $nobody $nobody
344 sub/k           1024    $nobody $nobody
345 sub/l           2048    $nobody $nobody
346 sub/m           4096    $nobody $nobody
347 sub/n           8192    $nobody $nobody
348 #
349 sub/a00         100     $nobody $nobody
350 sub/b00         200     $nobody $nobody
351 sub/c00         400     $nobody $nobody
352 sub/d00         800     $nobody $nobody
353 sub/e00         1600    $nobody $nobody
354 sub/f00         3200    $nobody $nobody
355 sub/g00         6400    $nobody $nobody
356 sub/h00         12800   $nobody $nobody
357 sub/i00         25600   $nobody $nobody
358 sub/j00         51200   $nobody $nobody
359 sub/k00         102400  $nobody $nobody
360 sub/l00         204800  $nobody $nobody
361 sub/m00         409600  $nobody $nobody
362 sub/n00         819200  $nobody $nobody
363 #
364 sub/a000        1000    $nobody $nobody
365 sub/e000        16000   $nobody $nobody
366 sub/h000        128000  $nobody $nobody
367 sub/k000        1024000 $nobody $nobody
368 End-of-File
369 }
370
371 _mk_fillconfig2()
372 {
373     cat <<End-of-File >$tmp.config
374 # pathname      size in bytes
375 #
376 smalll          10      $nobody $nobody
377 biggg           102400  $nobody $nobody
378 sub/smalll      10      $nobody $nobody
379 sub/biggg       102400  $nobody $nobody
380 End-of-File
381 }
382
383 _mk_fillconfig_perm()
384 {
385     # dir_guid: ugo=rwx,g+s on dir is for IRIX chmod(1)
386
387     cat <<End-of-File >$tmp.config
388 # pathname      size/dir  user group mode
389 #
390 file_suid       10      $nobody $nobody 04777
391 file_guid       10      $nobody $nobody 02777
392 file_sticky     10      $nobody $nobody 01777
393 file_mix1       10      $nobody $nobody 761
394 file_mix2       10      $nobody $nobody 642
395 dir_suid        d       $nobody $nobody 04777
396 dir_guid        d       $nobody $nobody ugo=rwx,g+s
397 dir_sticky      d       $nobody $nobody 01777
398 dir_mix1        d       $nobody $nobody 761
399 dir_mix2        d       $nobody $nobody 642
400 End-of-File
401 }
402
403 #
404 # Create a bunch of directories/files of different sizes
405 # filled with data.
406 #
407 # Pinched from test 001.
408 #
409 _do_create_dumpdir_fill()
410 {
411     echo "Creating directory system to dump using src/fill."
412
413     if mkdir -p $dump_dir
414     then
415         :
416     else
417         echo "Error: cannot mkdir \"$dump_dir\""
418         exit 1
419     fi
420     cd $dump_dir
421
422     $verbose && echo -n "Setup "
423     sed -e '/^#/d' $tmp.config \
424     | while read file nbytes owner group perms
425     do
426         if [ $nbytes = "d" ]; then
427             # create a directory
428             dir=$file   
429             if [ ! -d $dir ]
430             then
431                 if mkdir $dir
432                 then
433                     :
434                 else
435                     $verbose && echo
436                     echo "Error: cannot mkdir \"$dir\""
437                     exit 1
438                 fi
439             fi
440         else
441             # create a directory/file
442             dir=`dirname $file`
443             if [ "$dir" != "." ]
444             then
445                 if [ ! -d $dir ]
446                 then
447                     if mkdir $dir
448                     then
449                         :
450                     else
451                         $verbose && echo
452                         echo "Error: cannot mkdir \"$dir\""
453                         exit 1
454                     fi
455                 fi
456             fi
457             rm -f $file
458             if $here/src/fill $file $file $nbytes
459             then
460                 :
461             else
462                 $verbose && echo
463                 echo "Error: cannot create \"$file\""
464                 exit 1
465             fi
466         fi
467         if [ -n "$owner" -a -n "$group" ]; then
468             chown $owner.$group $file
469         fi
470         if [ -n "$perms" ]; then
471             chmod $perms $file
472         fi
473         $verbose && echo -n "."
474     done
475     $verbose && echo
476
477     cd $here
478 }
479
480
481 _create_dumpdir_fill()
482 {
483     _wipe_fs
484     _setup_seq_out
485     _mk_fillconfig1
486     _do_create_dumpdir_fill
487     _stable_fs
488 }       
489
490 _create_dumpdir_fill2()
491 {
492     _wipe_fs
493     _setup_seq_out
494     _mk_fillconfig2
495     _do_create_dumpdir_fill
496     _stable_fs
497 }       
498
499 _create_dumpdir_fill_perm()
500 {
501     _wipe_fs
502     _setup_seq_out
503     _mk_fillconfig_perm
504     _do_create_dumpdir_fill
505     _stable_fs
506 }       
507
508
509
510 #
511 # Append a subset of the fill'ed files
512 # So we can see if just these get dumped on an incremental
513 #
514 _append_dumpdir_fill()
515 {
516     cd $dump_dir
517     cat <<End-of-File >$tmp.config
518 # pathname
519 #
520 small   
521 sub/big 
522 #
523 sub/a
524 sub/c
525 sub/e
526 End-of-File
527     sed -e '/^#/d' $tmp.config \
528     | while read file
529     do
530         echo 'Extra text' >>$file
531     done
532
533     cd $here
534     _stable_fs
535 }
536
537 _do_create_dump_symlinks()
538 {
539     echo "Creating directory system of symlinks to dump."
540
541     if mkdir -p $dump_dir
542     then
543         :
544     else
545         echo "Error: cannot mkdir \"$dump_dir\""
546         exit 1
547     fi
548     cd $dump_dir
549
550     $verbose && echo -n "Setup "
551     sed -e '/^#/d' $tmp.config \
552     | while read file nbytes owner group owner2 group2 perms perms2
553     do
554         dir=`dirname $file`
555         if [ "$dir" != "." ]
556         then
557             if [ ! -d $dir ]
558             then
559                 if mkdir $dir
560                 then
561                     :
562                 else
563                     $verbose && echo
564                     echo "Error: cannot mkdir \"$dir\""
565                     exit 1
566                 fi
567             fi
568         fi
569         rm -f $file
570         touch $file
571
572         # Do chmod on symlink using umask.
573         # This won't do the right thing as it subtracts permissions.
574         # However, I don't care, as long as I get some different perms
575         # for testing.
576         if [ -n "$perms2" ]; then
577             omask=`umask`
578             umask $perms2
579         fi
580         ln -s $file $file-link
581         if [ -n "$perms2" ]; then
582             umask $omask        
583         fi
584
585         if [ -n "$owner" -a -n "$group" ]; then
586             chown $owner.$group $file
587         fi
588         if [ -n "$owner" -a -n "$group" ]; then
589             chown -h $owner.$group $file-link
590         fi
591         if [ -n "$perms" ]; then
592             chmod $perms $file
593         fi
594         $verbose && echo -n "."
595     done
596     $verbose && echo
597
598     cd $here
599 }
600
601 _mk_symlink_config()
602 {
603     cat <<End-of-File >$tmp.config
604 # path  size    owner1  group1  owner2  group2  perm1   perm2 
605 #
606 a       0       $nobody $nobody daemon  sys     124     421
607 b       0       daemon  sys     bin     bin     347     743
608 sub/a   0       bin     bin     $nobody sys     777     777
609 sub/b   0       $nobody sys     $nobody $nobody 367     763
610 End-of-File
611 }
612
613 _create_dumpdir_symlinks()
614 {
615     _wipe_fs
616     _setup_seq_out
617     _mk_symlink_config
618     _do_create_dump_symlinks
619     _stable_fs
620 }       
621
622 #
623 # Filter for ls
624 # Filter out dates on symlinks
625 #
626 _ls_filter()
627 {
628   $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
629         {print}' \
630   | sed -e 's/total [0-9][0-9]*/total TOTAL/'
631 }
632
633
634
635 # Filter out the non-deterministic dump msgs from
636 # xfsdump and xfsrestore
637 #
638 _dump_filter()
639 {
640   sed \
641       -e "s/`hostname`/HOSTNAME/"   \
642       -e "s#$SCRATCH_DEV#SCRATCH_DEV#"    \
643       -e "s#$dumptape#TAPE_DEV#"    \
644       -e "s#$SCRATCH_MNT#SCRATCH_MNT#"    \
645       -e "s#$dump_file#DUMP_FILE#"  \
646       -e 's/id:[        ]*[0-9a-f-]*/id: ID/'  \
647       -e 's/time:[      ].*/time: TIME/'       \
648       -e 's/date:[      ].*/date: DATE/'       \
649       -e 's/dump begun .*/dump begun DATE/'    \
650       -e 's/[0-9][0-9]* seconds/SECS seconds/' \
651       -e 's/ino [0-9][0-9]*/ino INO/' \
652       -e '/: dump size/s/[1-9][0-9]*/NUM/'     \
653       -e '/dump size:/s/[1-9][0-9]*/NUM/'      \
654       -e '/media file size/s/[1-9][0-9]*/NUM/' \
655       -e '/mfile size:[  ]*/s/[1-9][0-9]*/NUM/' \
656       -e '/\/dev\/tty/d' \
657       -e '/inventory session uuid/d' \
658       -e 's#/var/lib/xfsdump#/var/xfsdump#' \
659
660 }
661
662 _invutil_filter()
663 {
664   _dump_filter \
665   | sed \
666         -e 's/UUID[     ]*:[    ][0-9a-f-]*/UUID                :       ID/' \
667         -e 's/TIME OF DUMP[     ]*:.*/TIME OF DUMP      :       TIME/' \
668         -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
669         -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
670
671 }
672
673 _dir_filter()
674 {
675   sed \
676     -e "s#$dump_file#DUMP_FILE#"      \
677     -e "s#$SCRATCH_DEV#SCRATCH_DEV#"        \
678     -e "s#$dumptape#TAPE_DEV#"         \
679     -e "s#$dump_dir#DUMP_DIR#g"       \
680     -e "s#$restore_dir#RESTORE_DIR#g" \
681     -e "s#$SCRATCH_MNT#SCRATCH_MNT#g"       \
682     -e "s#$dump_sdir#DUMP_SUBDIR#g"   \
683     -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
684
685 }
686
687 _parse_args()
688 {
689     OPTIND=0
690     dump_args=""
691     while getopts "f:FL:o" c $*
692     do
693         case $c
694         in
695         f)
696             [ -z "$OPTARG" ] && _error "missing argument for -f"
697             dumptape=$OPTARG    
698             ;;
699         L)
700             [ -z "$OPTARG" ] && _error "missing argument for -L"
701             session_label=$OPTARG       
702             ;;
703         o)
704             dump_args="$dump_args -o"
705             ;;
706         F)
707             dump_args="$dump_args -F"
708             ;;
709         \?)
710             _error "invalid argument"
711             ;;
712         esac
713     done
714 }
715
716
717 #
718 # Dump a subdir
719 #
720 _do_dump_sub()
721 {
722     _parse_args $*
723
724     echo "Dumping to tape..."
725     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
726     echo "xfsdump $opts" | _dir_filter  
727     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
728 }
729
730 #
731 # Do full level 0 dump
732 #
733 _do_dump()
734 {
735     _parse_args $*
736
737     echo "Dumping to tape..."
738     opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
739     echo "xfsdump $opts" | _dir_filter  
740     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
741 }
742
743
744 #
745 # Do full dump with -m
746 #
747 _do_dump_min()
748 {
749     _parse_args $*
750
751     echo "Dumping to tape..."
752     onemeg=1048576
753     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
754     echo "xfsdump $opts" | _dir_filter  
755     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
756 }
757
758 #
759 # Do level 1 incremental dump
760 #
761 _do_dump_incremental()
762 {
763     _parse_args $*
764
765     echo "Dumping incrementally to tape..."
766     opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
767     echo "xfsdump $opts" | _dir_filter  
768     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
769 }
770
771 #
772 # Do full dump to file
773 #
774 _do_dump_file()
775 {
776     _parse_args $*
777
778     echo "Dumping to file..."
779     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
780     echo "xfsdump $opts" | _dir_filter  
781     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
782 }
783
784
785 _prepare_restore_dir()
786 {
787     rm -rf $restore_dir
788     if ! mkdir $restore_dir; then
789         echo "    failed to mkdir $restore_dir"
790         status=1
791         exit
792     fi
793 }
794
795
796 #
797 # Get tape ready and restore dir
798 #
799 _prepare_restore()
800 {
801     _prepare_restore_dir
802
803     echo "Rewinding tape"
804     _rewind
805 }
806
807 #
808 # Restore the tape into $restore_dir
809 #
810 _do_restore()
811 {
812     _parse_args $*
813     _prepare_restore
814
815
816     echo "Restoring from tape..."
817     opts="$_restore_debug$dump_args -f $dumptape  -L $session_label $restore_dir"
818     echo "xfsrestore $opts" | _dir_filter  
819     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
820 }
821
822 #
823 # Restore the tape into $restore_dir using -m
824 #
825 _do_restore_min()
826 {
827     _parse_args $*
828     _prepare_restore
829
830     echo "Restoring from tape..."
831     onemeg=1048576
832     opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
833     echo "xfsrestore $opts" | _dir_filter  
834     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
835 }
836
837 #
838 # Restore the tape from a dump file
839 #
840 _do_restore_file()
841 {
842     _parse_args $*
843     _prepare_restore_dir
844
845     echo "Restoring from file..."
846     opts="$_restore_debug$dump_args -f $dump_file  -L $session_label $restore_dir"
847     echo "xfsrestore $opts" | _dir_filter  
848     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
849 }
850
851 #
852 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
853 #
854 # Use -s as we want to dump and restore to the same xfs partition
855 #
856 _do_dump_restore()
857 {
858     _parse_args $*
859     _prepare_restore_dir
860     echo "xfsdump|xfsrestore ..."
861     restore_opts="$_restore_debug - $restore_dir"
862     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
863     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter  
864     xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
865     _dump_filter <$tmp.dump.mlog
866 }
867
868 #
869 # Compare dumped subdirectory with restored dir
870 # using ls -lR.
871 # Thus no contents are compared but permissions, sizes,
872 # owners, etc... are.
873 #
874 _ls_compare_sub()
875 {
876     #
877     # verify we got back what we dumped
878     #
879     echo "Comparing listing of dump directory with restore directory"
880     ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
881     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
882     | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
883
884     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
885 }
886
887 #
888 # filter out the date fields
889 #
890 _ls_nodate_filter()
891 {
892     $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
893 }
894
895 #
896 # _ls_compare_sub but don't compare dates
897 _ls_nodate_compare_sub()
898 {
899     #
900     # verify we got back what we dumped
901     #
902     echo "Comparing listing of dump directory with restore directory"
903     ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
904     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
905     | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
906
907     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
908 }
909
910
911 #
912 # Compare using recursive diff the files of the dumped
913 # subdirectory.
914 # This one will compare the contents.
915 #
916 _diff_compare_sub()
917 {
918     echo "Comparing dump directory with restore directory"
919     diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
920 }
921
922 #
923 # Compare using recursive diff the files of the dumped
924 # filesystem
925 #
926 _diff_compare()
927 {
928     echo "Comparing dump directory with restore directory"
929     diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
930 }
931
932 #
933 # Check out the dump inventory
934 #
935 _dump_inventory()
936 {
937     xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter 
938 }
939
940 #
941 # Do the xfsinvutil cmd with debug and filters
942 # Need to set variable: "$middate" to the invutil date 
943 #
944 _do_invutil()
945 {
946     host=`hostname`
947     echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
948     xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
949     | tee -a $seq.full | _invutil_filter
950 }
951
952 # make sure this script returns success
953 /bin/true