4 # Functions useful for xfsdump/xfsrestore tests
6 # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
27 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 # Mountain View, CA 94043, or:
32 # For further information regarding this notice, see:
34 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 # --- initializations ---
40 if [ -n "$DEBUGDUMP" ]; then
46 # Use dump/restore in qa directory for debugging
52 # status returned for not run tests
55 # name those directories
56 dump_file=$tmp.dumpfile
58 dump_dir=$SCRATCH_MNT/$dump_sdir
59 restore_sdir=restoredir
60 restore_dir=$SCRATCH_MNT/$restore_sdir
63 media_label="stress_tape_media"
64 session_label="stress_$seq"
66 nobody=4 # define this uid/gid as a number
71 trap "_cleanup; exit \$status" 0 1 2 3 15
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
78 mv /var/xfsdump/inventory /var/xfsdump/inventory.$seq
83 # do a remote/local mt
90 _rmtdev=`echo $dumptape | $AWK_PROG -F: '{print $2}'`
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"
98 _rmthost=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
99 rsh -n $_rmthost "mt -t $_rmtdev $op"
111 while [ $i -lt $_limit ]; do
112 echo "Checking online..." >>$seq.full
113 if _mt status >$tmp.status 2>&1; then
122 if [ $i -eq $_limit ]; then
123 echo "ERROR: mt -f $dumptape failed"
126 echo "mt -f $dumptape failed" >$seq.notrun
132 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
135 echo "ERROR: $dumptape is not online"
138 echo "dumptape, $dumptape, is not online" >$seq.notrun
146 echo "Wait for tape, $dumptape, ..." >>$seq.full
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
161 # Keep trying so we know we really have rewound
165 echo "Initiate rewind..." >>$seq.full
167 _mt rewind >/dev/null
172 # Do a custom erase because:
173 # (i) some machines don't support it
174 # (ii) some machines take forever to do it
178 echo "Erasing tape" | tee -a $seq.full
186 echo "Erasing tape" | tee -a $seq.full
192 echo $dumptape | grep ':' >/dev/null
204 echo "Put scsi tape driver into variable block size mode"
205 mt -f $dumptape setblk 0
213 if [ -z "$dumptape" ]; then
214 echo "This test requires a dump tape - none was specified"
215 echo "No dump tape specified" >$seq.notrun
226 echo "Error: $*" | tee -a $seq.full
227 echo "(see $seq.full for details)"
236 mkfs -t xfs -f $SCRATCH_DEV >>$seq.full ||\
239 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
240 _error "mount failed"
244 # Cleanup created dirs and files
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
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
264 if [ $status -ne $NOTRUNSTS ]; then
265 # Sleep added to stop _check_fs from complaining that the
266 # scratch_dev is still busy
269 _check_fs $SCRATCH_DEV
275 umount $SCRATCH_MNT >>$seq.full ||\
276 _error "unmount failed"
277 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
278 _error "mount failed"
282 # Run src/fsstress to create a mixture of
283 # files,dirs,links,symlinks
285 # Pinched from test 013.
287 _create_dumpdir_stress()
289 echo "Creating directory system to dump using src/fsstress."
294 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
297 if ! mkdir $dump_dir; then
298 echo " failed to mkdir $dump_dir"
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
308 echo " fsstress (count=$_count) returned $? - see $seq.full"
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
322 cat <<End-of-File >$tmp.config
323 # pathname size in bytes owner group
325 small 10 $nobody $nobody
326 big 102400 daemon sys
328 sub/big 102400 $nobody sys
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
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
360 sub/a000 1000 $nobody $nobody
361 sub/e000 16000 $nobody $nobody
362 sub/h000 128000 $nobody $nobody
363 sub/k000 1024000 $nobody $nobody
369 cat <<End-of-File >$tmp.config
370 # pathname size in bytes
372 smalll 10 $nobody $nobody
373 biggg 102400 $nobody $nobody
374 sub/smalll 10 $nobody $nobody
375 sub/biggg 102400 $nobody $nobody
379 _mk_fillconfig_perm()
381 # dir_guid: ugo=rwx,g+s on dir is for IRIX chmod(1)
383 cat <<End-of-File >$tmp.config
384 # pathname size/dir user group mode
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
400 # Create a bunch of directories/files of different sizes
403 # Pinched from test 001.
405 _do_create_dumpdir_fill()
407 echo "Creating directory system to dump using src/fill."
409 if mkdir -p $dump_dir
413 echo "Error: cannot mkdir \"$dump_dir\""
418 $verbose && echo -n "Setup "
419 sed -e '/^#/d' $tmp.config \
420 | while read file nbytes owner group perms
422 if [ $nbytes = "d" ]; then
432 echo "Error: cannot mkdir \"$dir\""
437 # create a directory/file
448 echo "Error: cannot mkdir \"$dir\""
454 if $here/src/fill $file $file $nbytes
459 echo "Error: cannot create \"$file\""
463 if [ -n "$owner" -a -n "$group" ]; then
464 chown $owner.$group $file
466 if [ -n "$perms" ]; then
469 $verbose && echo -n "."
477 _create_dumpdir_fill()
482 _do_create_dumpdir_fill
486 _create_dumpdir_fill2()
491 _do_create_dumpdir_fill
495 _create_dumpdir_fill_perm()
500 _do_create_dumpdir_fill
507 # Append a subset of the fill'ed files
508 # So we can see if just these get dumped on an incremental
510 _append_dumpdir_fill()
513 cat <<End-of-File >$tmp.config
523 sed -e '/^#/d' $tmp.config \
526 echo 'Extra text' >>$file
533 _do_create_dump_symlinks()
535 echo "Creating directory system of symlinks to dump."
537 if mkdir -p $dump_dir
541 echo "Error: cannot mkdir \"$dump_dir\""
546 $verbose && echo -n "Setup "
547 sed -e '/^#/d' $tmp.config \
548 | while read file nbytes owner group owner2 group2 perms perms2
560 echo "Error: cannot mkdir \"$dir\""
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
572 if [ -n "$perms2" ]; then
576 ln -s $file $file-link
577 if [ -n "$perms2" ]; then
581 if [ -n "$owner" -a -n "$group" ]; then
582 chown $owner.$group $file
584 if [ -n "$owner" -a -n "$group" ]; then
585 chown -h $owner.$group $file-link
587 if [ -n "$perms" ]; then
590 $verbose && echo -n "."
599 cat <<End-of-File >$tmp.config
600 # path size owner1 group1 owner2 group2 perm1 perm2
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
609 _create_dumpdir_symlinks()
614 _do_create_dump_symlinks
620 # Filter out dates on symlinks
624 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
626 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
631 # Filter out the non-deterministic dump msgs from
632 # xfsdump and xfsrestore
637 -e "s/`hostname`/HOSTNAME/" \
638 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
639 -e "s#$dumptape#TAPE_DEV#" \
640 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
641 -e "s#$dump_file#DUMP_FILE#" \
642 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
643 -e 's/time:[ ].*/time: TIME/' \
644 -e 's/date:[ ].*/date: DATE/' \
645 -e 's/dump begun .*/dump begun DATE/' \
646 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
647 -e 's/restore.[0-9][0-9]*/restore.PID/' \
648 -e 's/ino [0-9][0-9]*/ino INO/' \
649 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
650 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
651 -e '/media file size/s/[1-9][0-9]*/NUM/' \
652 -e '/mfile size:[ ]*/s/[1-9][0-9]*/NUM/' \
654 -e '/inventory session uuid/d' \
662 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
663 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
664 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
665 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
672 -e "s#$dump_file#DUMP_FILE#" \
673 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
674 -e "s#$dumptape#TAPE_DEV#" \
675 -e "s#$dump_dir#DUMP_DIR#g" \
676 -e "s#$restore_dir#RESTORE_DIR#g" \
677 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
678 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
679 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
687 while getopts "f:FL:o" c $*
692 [ -z "$OPTARG" ] && _error "missing argument for -f"
696 [ -z "$OPTARG" ] && _error "missing argument for -L"
697 session_label=$OPTARG
700 dump_args="$dump_args -o"
703 dump_args="$dump_args -F"
706 _error "invalid argument"
720 echo "Dumping to tape..."
721 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
722 echo "xfsdump $opts" | _dir_filter
723 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
727 # Do full level 0 dump
733 echo "Dumping to tape..."
734 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
735 echo "xfsdump $opts" | _dir_filter
736 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
741 # Do full dump with -m
747 echo "Dumping to tape..."
749 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
750 echo "xfsdump $opts" | _dir_filter
751 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
755 # Do level 1 incremental dump
757 _do_dump_incremental()
761 echo "Dumping incrementally to tape..."
762 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
763 echo "xfsdump $opts" | _dir_filter
764 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
768 # Do full dump to file
774 echo "Dumping to file..."
775 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
776 echo "xfsdump $opts" | _dir_filter
777 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
781 _prepare_restore_dir()
784 if ! mkdir $restore_dir; then
785 echo " failed to mkdir $restore_dir"
793 # Get tape ready and restore dir
799 echo "Rewinding tape"
804 # Restore the tape into $restore_dir
812 echo "Restoring from tape..."
813 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
814 echo "xfsrestore $opts" | _dir_filter
815 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
819 # Restore the tape into $restore_dir using -m
826 echo "Restoring from tape..."
828 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
829 echo "xfsrestore $opts" | _dir_filter
830 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
834 # Restore the tape from a dump file
841 echo "Restoring from file..."
842 opts="$_restore_debug$dump_args -f $dump_file -L $session_label $restore_dir"
843 echo "xfsrestore $opts" | _dir_filter
844 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
848 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
850 # Use -s as we want to dump and restore to the same xfs partition
856 echo "xfsdump|xfsrestore ..."
857 restore_opts="$_restore_debug - $restore_dir"
858 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
859 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
860 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
861 _dump_filter <$tmp.dump.mlog
865 # Compare dumped subdirectory with restored dir
867 # Thus no contents are compared but permissions, sizes,
868 # owners, etc... are.
873 # verify we got back what we dumped
875 echo "Comparing listing of dump directory with restore directory"
876 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
877 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
878 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
880 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
884 # filter out the date fields
888 $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
892 # _ls_compare_sub but don't compare dates
893 _ls_nodate_compare_sub()
896 # verify we got back what we dumped
898 echo "Comparing listing of dump directory with restore directory"
899 ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
900 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
901 | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
903 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
908 # Compare using recursive diff the files of the dumped
910 # This one will compare the contents.
914 echo "Comparing dump directory with restore directory"
915 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
919 # Compare using recursive diff the files of the dumped
924 echo "Comparing dump directory with restore directory"
925 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
929 # Check out the dump inventory
933 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
937 # Do the xfsinvutil cmd with debug and filters
938 # Need to set variable: "$middate" to the invutil date
943 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
944 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
945 | tee -a $seq.full | _invutil_filter
948 # make sure this script returns success