9ba942d5a7d4ad35e7cb06c1214c07fdad58f3ab
[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/ino [0-9][0-9]*/ino INO/' \
648       -e '/: dump size/s/[1-9][0-9]*/NUM/'     \
649       -e '/dump size:/s/[1-9][0-9]*/NUM/'      \
650       -e '/media file size/s/[1-9][0-9]*/NUM/' \
651       -e '/mfile size:[  ]*/s/[1-9][0-9]*/NUM/' \
652       -e '/\/dev\/tty/d' \
653       -e '/inventory session uuid/d' \
654
655 }
656
657 _invutil_filter()
658 {
659   _dump_filter \
660   | sed \
661         -e 's/UUID[     ]*:[    ][0-9a-f-]*/UUID                :       ID/' \
662         -e 's/TIME OF DUMP[     ]*:.*/TIME OF DUMP      :       TIME/' \
663         -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
664         -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
665
666 }
667
668 _dir_filter()
669 {
670   sed \
671     -e "s#$dump_file#DUMP_FILE#"      \
672     -e "s#$SCRATCH_DEV#SCRATCH_DEV#"        \
673     -e "s#$dumptape#TAPE_DEV#"         \
674     -e "s#$dump_dir#DUMP_DIR#g"       \
675     -e "s#$restore_dir#RESTORE_DIR#g" \
676     -e "s#$SCRATCH_MNT#SCRATCH_MNT#g"       \
677     -e "s#$dump_sdir#DUMP_SUBDIR#g"   \
678     -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
679
680 }
681
682 _parse_args()
683 {
684     OPTIND=0
685     dump_args=""
686     while getopts "f:FL:o" c $*
687     do
688         case $c
689         in
690         f)
691             [ -z "$OPTARG" ] && _error "missing argument for -f"
692             dumptape=$OPTARG    
693             ;;
694         L)
695             [ -z "$OPTARG" ] && _error "missing argument for -L"
696             session_label=$OPTARG       
697             ;;
698         o)
699             dump_args="$dump_args -o"
700             ;;
701         F)
702             dump_args="$dump_args -F"
703             ;;
704         \?)
705             _error "invalid argument"
706             ;;
707         esac
708     done
709 }
710
711
712 #
713 # Dump a subdir
714 #
715 _do_dump_sub()
716 {
717     _parse_args $*
718
719     echo "Dumping to tape..."
720     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
721     echo "xfsdump $opts" | _dir_filter  
722     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
723 }
724
725 #
726 # Do full level 0 dump
727 #
728 _do_dump()
729 {
730     _parse_args $*
731
732     echo "Dumping to tape..."
733     opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
734     echo "xfsdump $opts" | _dir_filter  
735     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
736 }
737
738
739 #
740 # Do full dump with -m
741 #
742 _do_dump_min()
743 {
744     _parse_args $*
745
746     echo "Dumping to tape..."
747     onemeg=1048576
748     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
749     echo "xfsdump $opts" | _dir_filter  
750     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
751 }
752
753 #
754 # Do level 1 incremental dump
755 #
756 _do_dump_incremental()
757 {
758     _parse_args $*
759
760     echo "Dumping incrementally to tape..."
761     opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
762     echo "xfsdump $opts" | _dir_filter  
763     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
764 }
765
766 #
767 # Do full dump to file
768 #
769 _do_dump_file()
770 {
771     _parse_args $*
772
773     echo "Dumping to file..."
774     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
775     echo "xfsdump $opts" | _dir_filter  
776     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
777 }
778
779
780 _prepare_restore_dir()
781 {
782     rm -rf $restore_dir
783     if ! mkdir $restore_dir; then
784         echo "    failed to mkdir $restore_dir"
785         status=1
786         exit
787     fi
788 }
789
790
791 #
792 # Get tape ready and restore dir
793 #
794 _prepare_restore()
795 {
796     _prepare_restore_dir
797
798     echo "Rewinding tape"
799     _rewind
800 }
801
802 #
803 # Restore the tape into $restore_dir
804 #
805 _do_restore()
806 {
807     _parse_args $*
808     _prepare_restore
809
810
811     echo "Restoring from tape..."
812     opts="$_restore_debug$dump_args -f $dumptape  -L $session_label $restore_dir"
813     echo "xfsrestore $opts" | _dir_filter  
814     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
815 }
816
817 #
818 # Restore the tape into $restore_dir using -m
819 #
820 _do_restore_min()
821 {
822     _parse_args $*
823     _prepare_restore
824
825     echo "Restoring from tape..."
826     onemeg=1048576
827     opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
828     echo "xfsrestore $opts" | _dir_filter  
829     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
830 }
831
832 #
833 # Restore the tape from a dump file
834 #
835 _do_restore_file()
836 {
837     _parse_args $*
838     _prepare_restore_dir
839
840     echo "Restoring from file..."
841     opts="$_restore_debug$dump_args -f $dump_file  -L $session_label $restore_dir"
842     echo "xfsrestore $opts" | _dir_filter  
843     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
844 }
845
846 #
847 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
848 #
849 # Use -s as we want to dump and restore to the same xfs partition
850 #
851 _do_dump_restore()
852 {
853     _parse_args $*
854     _prepare_restore_dir
855     echo "xfsdump|xfsrestore ..."
856     restore_opts="$_restore_debug - $restore_dir"
857     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
858     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter  
859     xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
860     _dump_filter <$tmp.dump.mlog
861 }
862
863 #
864 # Compare dumped subdirectory with restored dir
865 # using ls -lR.
866 # Thus no contents are compared but permissions, sizes,
867 # owners, etc... are.
868 #
869 _ls_compare_sub()
870 {
871     #
872     # verify we got back what we dumped
873     #
874     echo "Comparing listing of dump directory with restore directory"
875     ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
876     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
877     | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
878
879     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
880 }
881
882 #
883 # filter out the date fields
884 #
885 _ls_nodate_filter()
886 {
887     $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
888 }
889
890 #
891 # _ls_compare_sub but don't compare dates
892 _ls_nodate_compare_sub()
893 {
894     #
895     # verify we got back what we dumped
896     #
897     echo "Comparing listing of dump directory with restore directory"
898     ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
899     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
900     | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
901
902     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
903 }
904
905
906 #
907 # Compare using recursive diff the files of the dumped
908 # subdirectory.
909 # This one will compare the contents.
910 #
911 _diff_compare_sub()
912 {
913     echo "Comparing dump directory with restore directory"
914     diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
915 }
916
917 #
918 # Compare using recursive diff the files of the dumped
919 # filesystem
920 #
921 _diff_compare()
922 {
923     echo "Comparing dump directory with restore directory"
924     diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
925 }
926
927 #
928 # Check out the dump inventory
929 #
930 _dump_inventory()
931 {
932     xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter 
933 }
934
935 #
936 # Do the xfsinvutil cmd with debug and filters
937 # Need to set variable: "$middate" to the invutil date 
938 #
939 _do_invutil()
940 {
941     host=`hostname`
942     echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
943     xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
944     | tee -a $seq.full | _invutil_filter
945 }
946
947 # make sure this script returns success
948 /bin/true