Only need 1 out file as the quota output is now checked
[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 do_quota_check=true # do quota check if quotas enabled
68
69 _need_to_be_root
70
71 # install our cleaner
72 trap "_cleanup; exit \$status" 0 1 2 3 15
73
74 # start inventory from a known base - move it aside for test
75 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
76     if [ -d $dir ]; then
77         [ -d $dir.$seq ] && rm -rf $dir.$seq
78         mv $dir $dir.$seq
79     fi
80 done
81
82
83 #
84 # do a remote/local mt
85 #
86 _mt()
87 {
88     op=$1
89     if _isrmt; then  
90         # REMOTE
91         _rmtdev=`echo $dumptape | $AWK_PROG -F: '{print $2}'`
92
93         if echo $dumptape | grep '@' >/dev/null; then
94             _spec=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
95             _rmtuser=`echo $_spec | $AWK_PROG -F@ '{print $1}'`
96             _rmthost=`echo $_spec | $AWK_PROG -F@ '{print $2}'`
97             rsh -n -l $_rmtuser $_rmthost "mt -t $_rmtdev $op"
98         else
99             _rmthost=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
100             rsh -n $_rmthost "mt -t $_rmtdev $op"
101         fi
102     else
103         #LOCAL
104         mt -t $dumptape $op
105     fi
106 }
107
108 _check_onl()
109 {
110     _limit=10
111     i=0
112     while [ $i -lt $_limit ]; do  
113         echo "Checking online..." >>$seq.full
114         if _mt status >$tmp.status 2>&1; then
115             break; 
116         else
117             sleep 2 
118         fi
119         i=`expr $i + 1`
120     done
121
122
123     if [ $i -eq $_limit ]; then
124         echo "ERROR: mt -f $dumptape failed"
125         cat $tmp.status
126
127         echo "mt -f $dumptape failed" >$seq.notrun 
128         status=$NOTRUNSTS
129         exit
130     fi 
131
132
133     if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
134         :
135     else
136         echo "ERROR: $dumptape is not online"
137         cat $tmp.status
138
139         echo "dumptape, $dumptape, is not online" >$seq.notrun 
140         status=$NOTRUNSTS
141         exit
142     fi
143 }
144
145 _wait_tape()
146 {
147     echo "Wait for tape, $dumptape, ..." >>$seq.full
148
149     i=0
150     while [ $i -lt 20 ]; do  
151         echo "Checking status..." >>$seq.full
152         if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
153             break; 
154         else
155             sleep 2 
156         fi
157         i=`expr $i + 1`
158     done
159 }
160
161 #
162 # Keep trying so we know we really have rewound
163 #
164 _rewind()
165 {
166     echo "Initiate rewind..." >>$seq.full
167     _wait_tape
168     _mt rewind >/dev/null
169     _wait_tape
170 }
171
172 #
173 # Do a custom erase because: 
174 # (i) some machines don't support it
175 # (ii) some machines take forever to do it
176 #
177 _erase_soft()
178 {
179     echo "Erasing tape" | tee -a $seq.full
180     _rewind
181     _mt weof 3
182     _rewind
183 }
184
185 _erase_hard()
186 {
187     echo "Erasing tape" | tee -a $seq.full
188     _mt erase
189 }
190
191 _isrmt()
192 {
193     echo $dumptape | grep ':' >/dev/null
194 }
195
196 #
197 # Get tape ready
198 #
199 _set_variable()
200 {
201     if _isrmt; then
202         :
203     else
204         # LOCAL
205         echo "Put scsi tape driver into variable block size mode"
206         mt -f $dumptape setblk 0
207     fi  
208 }
209
210 _require_tape()
211 {
212     dumptape=$1
213
214     if [ -z "$dumptape" ]; then
215         echo "This test requires a dump tape - none was specified"
216         echo "No dump tape specified" >$seq.notrun 
217         status=$NOTRUNSTS
218         exit
219     fi
220
221     _check_onl
222     _set_variable
223 }
224
225 _error()
226 {
227     echo "Error: $*" | tee -a $seq.full
228     echo "(see $seq.full for details)"
229     status=1
230     exit
231 }
232
233 _wipe_fs()
234 {
235     _require_scratch
236
237     mkfs -t xfs -f $SCRATCH_DEV >>$seq.full  ||\
238         _error "mkfs failed"
239       
240     mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
241         _error "mount failed"
242 }
243
244
245 # Cleanup created dirs and files
246 # Called by trap
247 #
248 _cleanup()
249 {
250     cd $here
251     rm -f $tmp.*
252
253     if [ -n "$DEBUGDUMP" ]; then
254         # save it for inspection
255         for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
256             [ -d $dir ] || continue
257             tar -zcvf $seq.inventory.tgz $dir
258             ls -lR $dir >$seq.inventory.ls
259         done
260     fi
261
262     # put inventory dir back
263     for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
264         [ -d $dir.$seq ] || continue
265         rm -rf $dir             # get rid of new one
266         mv $dir.$seq $dir
267     done
268
269     if [ $status -ne $NOTRUNSTS ]; then
270         # Sleep added to stop _check_fs from complaining that the
271         # scratch_dev is still busy
272         sleep 10
273
274         _check_fs $SCRATCH_DEV
275     fi
276 }
277
278 _stable_fs()
279 {
280     umount $SCRATCH_MNT >>$seq.full ||\
281         _error "unmount failed"
282     mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
283         _error "mount failed"
284 }
285
286 #
287 # Run src/fsstress to create a mixture of 
288 # files,dirs,links,symlinks
289 #
290 # Pinched from test 013.
291 #
292 _create_dumpdir_stress()
293 {
294     echo "Creating directory system to dump using src/fsstress."
295
296     _wipe_fs
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     _mk_fillconfig1
485     _do_create_dumpdir_fill
486     _stable_fs
487 }       
488
489 _create_dumpdir_fill2()
490 {
491     _wipe_fs
492     _mk_fillconfig2
493     _do_create_dumpdir_fill
494     _stable_fs
495 }       
496
497 _create_dumpdir_fill_perm()
498 {
499     _wipe_fs
500     _mk_fillconfig_perm
501     _do_create_dumpdir_fill
502     _stable_fs
503 }       
504
505
506
507 #
508 # Append a subset of the fill'ed files
509 # So we can see if just these get dumped on an incremental
510 #
511 _append_dumpdir_fill()
512 {
513     cd $dump_dir
514     cat <<End-of-File >$tmp.config
515 # pathname
516 #
517 small   
518 sub/big 
519 #
520 sub/a
521 sub/c
522 sub/e
523 End-of-File
524     sed -e '/^#/d' $tmp.config \
525     | while read file
526     do
527         echo 'Extra text' >>$file
528     done
529
530     cd $here
531     _stable_fs
532 }
533
534 _do_create_dump_symlinks()
535 {
536     echo "Creating directory system of symlinks to dump."
537
538     if mkdir -p $dump_dir
539     then
540         :
541     else
542         echo "Error: cannot mkdir \"$dump_dir\""
543         exit 1
544     fi
545     cd $dump_dir
546
547     $verbose && echo -n "Setup "
548     sed -e '/^#/d' $tmp.config \
549     | while read file nbytes owner group owner2 group2 perms perms2
550     do
551         dir=`dirname $file`
552         if [ "$dir" != "." ]
553         then
554             if [ ! -d $dir ]
555             then
556                 if mkdir $dir
557                 then
558                     :
559                 else
560                     $verbose && echo
561                     echo "Error: cannot mkdir \"$dir\""
562                     exit 1
563                 fi
564             fi
565         fi
566         rm -f $file
567         touch $file
568
569         # Do chmod on symlink using umask.
570         # This won't do the right thing as it subtracts permissions.
571         # However, I don't care, as long as I get some different perms
572         # for testing.
573         if [ -n "$perms2" ]; then
574             omask=`umask`
575             umask $perms2
576         fi
577         ln -s $file $file-link
578         if [ -n "$perms2" ]; then
579             umask $omask        
580         fi
581
582         if [ -n "$owner" -a -n "$group" ]; then
583             chown $owner.$group $file
584         fi
585         if [ -n "$owner" -a -n "$group" ]; then
586             chown -h $owner.$group $file-link
587         fi
588         if [ -n "$perms" ]; then
589             chmod $perms $file
590         fi
591         $verbose && echo -n "."
592     done
593     $verbose && echo
594
595     cd $here
596 }
597
598 _mk_symlink_config()
599 {
600     cat <<End-of-File >$tmp.config
601 # path  size    owner1  group1  owner2  group2  perm1   perm2 
602 #
603 a       0       $nobody $nobody daemon  sys     124     421
604 b       0       daemon  sys     bin     bin     347     743
605 sub/a   0       bin     bin     $nobody sys     777     777
606 sub/b   0       $nobody sys     $nobody $nobody 367     763
607 End-of-File
608 }
609
610 _create_dumpdir_symlinks()
611 {
612     _wipe_fs
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_main()
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/[0-9][0-9]*/NUM/'     \
649       -e '/dump size:/s/[0-9][0-9]*/NUM/'      \
650       -e '/media file size/s/[0-9][0-9]*/NUM/' \
651       -e '/mfile size:[  ]*/s/[0-9][0-9]*/NUM/' \
652       -e '/\/dev\/tty/d' \
653       -e '/inventory session uuid/d' \
654       -e 's#/var/lib/xfsdump#/var/xfsdump#' \
655
656 }
657
658 _dump_filter()
659 {
660   if $do_quota_check
661   then
662       _dump_filter_main | _check_quota_dumprestore
663   else
664       _dump_filter_main
665   fi
666 }
667
668 _invutil_filter()
669 {
670   _dump_filter_main \
671   | sed \
672         -e 's/UUID[     ]*:[    ][0-9a-f-]*/UUID                :       ID/' \
673         -e 's/TIME OF DUMP[     ]*:.*/TIME OF DUMP      :       TIME/' \
674         -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
675         -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
676
677 }
678
679 _dir_filter()
680 {
681   sed \
682     -e "s#$dump_file#DUMP_FILE#"      \
683     -e "s#$SCRATCH_DEV#SCRATCH_DEV#"        \
684     -e "s#$dumptape#TAPE_DEV#"         \
685     -e "s#$dump_dir#DUMP_DIR#g"       \
686     -e "s#$restore_dir#RESTORE_DIR#g" \
687     -e "s#$SCRATCH_MNT#SCRATCH_MNT#g"       \
688     -e "s#$dump_sdir#DUMP_SUBDIR#g"   \
689     -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
690
691 }
692
693 _parse_args()
694 {
695     OPTIND=0
696     dump_args=""
697     while getopts "f:FL:oqQ" c $*
698     do
699         case $c
700         in
701         f)
702             [ -z "$OPTARG" ] && _error "missing argument for -f"
703             dumptape=$OPTARG    
704             ;;
705         L)
706             [ -z "$OPTARG" ] && _error "missing argument for -L"
707             session_label=$OPTARG       
708             ;;
709         o)
710             dump_args="$dump_args -o"
711             ;;
712         F)
713             dump_args="$dump_args -F"
714             ;;
715         q)
716             do_quota_check=true
717             ;;
718         Q)
719             do_quota_check=false
720             ;;
721         \?)
722             _error "invalid argument"
723             ;;
724         esac
725     done
726 }
727
728
729 #
730 # Dump a subdir
731 #
732 _do_dump_sub()
733 {
734     _parse_args $*
735
736     echo "Dumping to tape..."
737     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
738     echo "xfsdump $opts" | _dir_filter  
739     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
740 }
741
742 #
743 # Do full level 0 dump
744 #
745 _do_dump()
746 {
747     _parse_args $*
748
749     echo "Dumping to tape..."
750     opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
751     echo "xfsdump $opts" | _dir_filter  
752     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
753 }
754
755
756 #
757 # Do full dump with -m
758 #
759 _do_dump_min()
760 {
761     _parse_args $*
762
763     echo "Dumping to tape..."
764     onemeg=1048576
765     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
766     echo "xfsdump $opts" | _dir_filter  
767     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
768 }
769
770 #
771 # Do level 1 incremental dump
772 #
773 _do_dump_incremental()
774 {
775     _parse_args $*
776
777     echo "Dumping incrementally to tape..."
778     opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
779     echo "xfsdump $opts" | _dir_filter  
780     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
781 }
782
783 #
784 # Do full dump to file
785 #
786 _do_dump_file()
787 {
788     _parse_args $*
789
790     echo "Dumping to file..."
791     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
792     echo "xfsdump $opts" | _dir_filter  
793     xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
794 }
795
796
797 _prepare_restore_dir()
798 {
799     rm -rf $restore_dir
800     if ! mkdir $restore_dir; then
801         echo "    failed to mkdir $restore_dir"
802         status=1
803         exit
804     fi
805 }
806
807
808 #
809 # Get tape ready and restore dir
810 #
811 _prepare_restore()
812 {
813     _prepare_restore_dir
814
815     echo "Rewinding tape"
816     _rewind
817 }
818
819 #
820 # Restore the tape into $restore_dir
821 #
822 _do_restore()
823 {
824     _parse_args $*
825     _prepare_restore
826
827
828     echo "Restoring from tape..."
829     opts="$_restore_debug$dump_args -f $dumptape  -L $session_label $restore_dir"
830     echo "xfsrestore $opts" | _dir_filter  
831     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
832 }
833
834 #
835 # Restore the tape into $restore_dir using -m
836 #
837 _do_restore_min()
838 {
839     _parse_args $*
840     _prepare_restore
841
842     echo "Restoring from tape..."
843     onemeg=1048576
844     opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
845     echo "xfsrestore $opts" | _dir_filter  
846     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
847 }
848
849 #
850 # Restore the tape from a dump file
851 #
852 _do_restore_file()
853 {
854     _parse_args $*
855     _prepare_restore_dir
856
857     echo "Restoring from file..."
858     opts="$_restore_debug$dump_args -f $dump_file  -L $session_label $restore_dir"
859     echo "xfsrestore $opts" | _dir_filter  
860     xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
861 }
862
863 #
864 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
865 #
866 # Use -s as we want to dump and restore to the same xfs partition
867 #
868 _do_dump_restore()
869 {
870     _parse_args $*
871     _prepare_restore_dir
872     echo "xfsdump|xfsrestore ..."
873     restore_opts="$_restore_debug - $restore_dir"
874     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
875     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter  
876     xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
877     _dump_filter <$tmp.dump.mlog
878 }
879
880 #
881 # Compare dumped subdirectory with restored dir
882 # using ls -lR.
883 # Thus no contents are compared but permissions, sizes,
884 # owners, etc... are.
885 #
886 _ls_compare_sub()
887 {
888     #
889     # verify we got back what we dumped
890     #
891     echo "Comparing listing of dump directory with restore directory"
892     ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
893     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
894     | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
895
896     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
897 }
898
899 #
900 # filter out the date fields
901 #
902 _ls_nodate_filter()
903 {
904     $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
905 }
906
907 #
908 # _ls_compare_sub but don't compare dates
909 _ls_nodate_compare_sub()
910 {
911     #
912     # verify we got back what we dumped
913     #
914     echo "Comparing listing of dump directory with restore directory"
915     ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
916     ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
917     | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
918
919     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
920 }
921
922
923 #
924 # Compare using recursive diff the files of the dumped
925 # subdirectory.
926 # This one will compare the contents.
927 #
928 _diff_compare_sub()
929 {
930     echo "Comparing dump directory with restore directory"
931     diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
932 }
933
934 #
935 # Compare using recursive diff the files of the dumped
936 # filesystem
937 #
938 _diff_compare()
939 {
940     echo "Comparing dump directory with restore directory"
941     diff -rs $SCRATCH_MNT $restore_dir | _dir_filter | _check_quota_diff
942 }
943
944 #
945 # Check out the dump inventory
946 #
947 _dump_inventory()
948 {
949     xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter_main
950 }
951
952 #
953 # Do the xfsinvutil cmd with debug and filters
954 # Need to set variable: "$middate" to the invutil date 
955 #
956 _do_invutil()
957 {
958     host=`hostname`
959     echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
960     xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
961     | tee -a $seq.full | _invutil_filter
962 }
963
964 #
965 # Look for:
966 # xfsdump: saving user quota information for: SCRATCH_MNT
967 # xfsdump: saving group quota information for: SCRATCH_MNT
968 # xfsrestore: user quota information written to ...'
969 # xfsrestore: group quota information written to ...'
970 #
971 _check_quota_dumprestore()
972 {
973     uquota=0
974     gquota=0 
975     src/feature -U $SCRATCH_DEV && uquota=1
976     src/feature -G $SCRATCH_DEV && gquota=1
977
978     $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v full=$seq.full '
979         /user quota information/ {
980                         print "Found user quota:", $0 >>full
981                         found_uquota = 1
982                         if (!uquota) {
983                             print "Found extra:", $0
984                         }
985                         next
986         }
987         /group quota information/ {
988                         print "Found group quota:", $0 >>full
989                         found_gquota = 1
990                         if (!gquota) {
991                             print "Found extra:", $0
992                         }
993                         next
994         }
995                         { print }
996         END {
997                 if (uquota && !found_uquota) {
998                     print "Missing saving/restoring uquota msg"
999                 }
1000                 if (gquota && !found_gquota) {
1001                     print "Missing saving/restoring gquota msg"
1002                 }
1003         }
1004     '
1005 }
1006
1007 #
1008 # Look for:
1009 # Only in RESTORE_DIR: xfsdump_quotas
1010 # Only in RESTORE_DIR: xfsdump_quotas_group
1011 #
1012
1013 _check_quota_diff()
1014 {
1015     uquota=0
1016     gquota=0 
1017     src/feature -U $SCRATCH_DEV && uquota=1
1018     src/feature -G $SCRATCH_DEV && gquota=1
1019
1020     $AWK_PROG -v uquota=$uquota -v gquota=$gquota '
1021         /Only in RESTORE_DIR: xfsdump_quotas_group/ {
1022                         found_gquota = 1
1023                         if (!gquota) {
1024                             print "Found extra:", $0
1025                         }
1026                         next
1027         }
1028         /Only in RESTORE_DIR: xfsdump_quotas/ {
1029                         found_uquota = 1
1030                         if (!uquota) {
1031                             print "Found extra:", $0
1032                         }
1033                         next
1034         }
1035                         { print }
1036         END {
1037                 if (uquota && !found_uquota) {
1038                     print "Missing xfsdump_quotas msg"
1039                 }
1040                 if (gquota && !found_gquota) {
1041                     print "Missing xfsdump_quotas_group msg"
1042                 }
1043         }
1044     '
1045 }
1046
1047 # make sure this script returns success
1048 /bin/true