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