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 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
76 [ -d $dir.$seq ] && rm -rf $dir.$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 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
255 [ -d $dir ] || continue
256 tar -zcvf $seq.inventory.tgz $dir
257 ls -lR $dir >$seq.inventory.ls
261 # put inventory dir back
262 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
263 [ -d $dir.$seq ] || continue
264 rm -rf $dir # get rid of new one
268 if [ $status -ne $NOTRUNSTS ]; then
269 # Sleep added to stop _check_fs from complaining that the
270 # scratch_dev is still busy
273 _check_fs $SCRATCH_DEV
279 umount $SCRATCH_MNT >>$seq.full ||\
280 _error "unmount failed"
281 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
282 _error "mount failed"
286 # Run src/fsstress to create a mixture of
287 # files,dirs,links,symlinks
289 # Pinched from test 013.
291 _create_dumpdir_stress()
293 echo "Creating directory system to dump using src/fsstress."
298 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
301 if ! mkdir $dump_dir; then
302 echo " failed to mkdir $dump_dir"
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
312 echo " fsstress (count=$_count) returned $? - see $seq.full"
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
326 cat <<End-of-File >$tmp.config
327 # pathname size in bytes owner group
329 small 10 $nobody $nobody
330 big 102400 daemon sys
332 sub/big 102400 $nobody sys
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
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
364 sub/a000 1000 $nobody $nobody
365 sub/e000 16000 $nobody $nobody
366 sub/h000 128000 $nobody $nobody
367 sub/k000 1024000 $nobody $nobody
373 cat <<End-of-File >$tmp.config
374 # pathname size in bytes
376 smalll 10 $nobody $nobody
377 biggg 102400 $nobody $nobody
378 sub/smalll 10 $nobody $nobody
379 sub/biggg 102400 $nobody $nobody
383 _mk_fillconfig_perm()
385 # dir_guid: ugo=rwx,g+s on dir is for IRIX chmod(1)
387 cat <<End-of-File >$tmp.config
388 # pathname size/dir user group mode
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
404 # Create a bunch of directories/files of different sizes
407 # Pinched from test 001.
409 _do_create_dumpdir_fill()
411 echo "Creating directory system to dump using src/fill."
413 if mkdir -p $dump_dir
417 echo "Error: cannot mkdir \"$dump_dir\""
422 $verbose && echo -n "Setup "
423 sed -e '/^#/d' $tmp.config \
424 | while read file nbytes owner group perms
426 if [ $nbytes = "d" ]; then
436 echo "Error: cannot mkdir \"$dir\""
441 # create a directory/file
452 echo "Error: cannot mkdir \"$dir\""
458 if $here/src/fill $file $file $nbytes
463 echo "Error: cannot create \"$file\""
467 if [ -n "$owner" -a -n "$group" ]; then
468 chown $owner.$group $file
470 if [ -n "$perms" ]; then
473 $verbose && echo -n "."
481 _create_dumpdir_fill()
486 _do_create_dumpdir_fill
490 _create_dumpdir_fill2()
495 _do_create_dumpdir_fill
499 _create_dumpdir_fill_perm()
504 _do_create_dumpdir_fill
511 # Append a subset of the fill'ed files
512 # So we can see if just these get dumped on an incremental
514 _append_dumpdir_fill()
517 cat <<End-of-File >$tmp.config
527 sed -e '/^#/d' $tmp.config \
530 echo 'Extra text' >>$file
537 _do_create_dump_symlinks()
539 echo "Creating directory system of symlinks to dump."
541 if mkdir -p $dump_dir
545 echo "Error: cannot mkdir \"$dump_dir\""
550 $verbose && echo -n "Setup "
551 sed -e '/^#/d' $tmp.config \
552 | while read file nbytes owner group owner2 group2 perms perms2
564 echo "Error: cannot mkdir \"$dir\""
572 # Do chmod on symlink using umask.
573 # This won't do the right thing as it subtracts permissions.
574 # However, I don't care, as long as I get some different perms
576 if [ -n "$perms2" ]; then
580 ln -s $file $file-link
581 if [ -n "$perms2" ]; then
585 if [ -n "$owner" -a -n "$group" ]; then
586 chown $owner.$group $file
588 if [ -n "$owner" -a -n "$group" ]; then
589 chown -h $owner.$group $file-link
591 if [ -n "$perms" ]; then
594 $verbose && echo -n "."
603 cat <<End-of-File >$tmp.config
604 # path size owner1 group1 owner2 group2 perm1 perm2
606 a 0 $nobody $nobody daemon sys 124 421
607 b 0 daemon sys bin bin 347 743
608 sub/a 0 bin bin $nobody sys 777 777
609 sub/b 0 $nobody sys $nobody $nobody 367 763
613 _create_dumpdir_symlinks()
618 _do_create_dump_symlinks
624 # Filter out dates on symlinks
628 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
630 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
635 # Filter out the non-deterministic dump msgs from
636 # xfsdump and xfsrestore
641 -e "s/`hostname`/HOSTNAME/" \
642 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
643 -e "s#$dumptape#TAPE_DEV#" \
644 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
645 -e "s#$dump_file#DUMP_FILE#" \
646 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
647 -e 's/time:[ ].*/time: TIME/' \
648 -e 's/date:[ ].*/date: DATE/' \
649 -e 's/dump begun .*/dump begun DATE/' \
650 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
651 -e 's/ino [0-9][0-9]*/ino INO/' \
652 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
653 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
654 -e '/media file size/s/[1-9][0-9]*/NUM/' \
655 -e '/mfile size:[ ]*/s/[1-9][0-9]*/NUM/' \
657 -e '/inventory session uuid/d' \
658 -e 's#/var/lib/xfsdump#/var/xfsdump#' \
666 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
667 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
668 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
669 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
676 -e "s#$dump_file#DUMP_FILE#" \
677 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
678 -e "s#$dumptape#TAPE_DEV#" \
679 -e "s#$dump_dir#DUMP_DIR#g" \
680 -e "s#$restore_dir#RESTORE_DIR#g" \
681 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
682 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
683 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
691 while getopts "f:FL:o" c $*
696 [ -z "$OPTARG" ] && _error "missing argument for -f"
700 [ -z "$OPTARG" ] && _error "missing argument for -L"
701 session_label=$OPTARG
704 dump_args="$dump_args -o"
707 dump_args="$dump_args -F"
710 _error "invalid argument"
724 echo "Dumping to tape..."
725 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
726 echo "xfsdump $opts" | _dir_filter
727 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
731 # Do full level 0 dump
737 echo "Dumping to tape..."
738 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
739 echo "xfsdump $opts" | _dir_filter
740 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
745 # Do full dump with -m
751 echo "Dumping to tape..."
753 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
754 echo "xfsdump $opts" | _dir_filter
755 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
759 # Do level 1 incremental dump
761 _do_dump_incremental()
765 echo "Dumping incrementally to tape..."
766 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
767 echo "xfsdump $opts" | _dir_filter
768 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
772 # Do full dump to file
778 echo "Dumping to file..."
779 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
780 echo "xfsdump $opts" | _dir_filter
781 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
785 _prepare_restore_dir()
788 if ! mkdir $restore_dir; then
789 echo " failed to mkdir $restore_dir"
797 # Get tape ready and restore dir
803 echo "Rewinding tape"
808 # Restore the tape into $restore_dir
816 echo "Restoring from tape..."
817 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
818 echo "xfsrestore $opts" | _dir_filter
819 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
823 # Restore the tape into $restore_dir using -m
830 echo "Restoring from tape..."
832 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
833 echo "xfsrestore $opts" | _dir_filter
834 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
838 # Restore the tape from a dump file
845 echo "Restoring from file..."
846 opts="$_restore_debug$dump_args -f $dump_file -L $session_label $restore_dir"
847 echo "xfsrestore $opts" | _dir_filter
848 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
852 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
854 # Use -s as we want to dump and restore to the same xfs partition
860 echo "xfsdump|xfsrestore ..."
861 restore_opts="$_restore_debug - $restore_dir"
862 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
863 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
864 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
865 _dump_filter <$tmp.dump.mlog
869 # Compare dumped subdirectory with restored dir
871 # Thus no contents are compared but permissions, sizes,
872 # owners, etc... are.
877 # verify we got back what we dumped
879 echo "Comparing listing of dump directory with restore directory"
880 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
881 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
882 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
884 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
888 # filter out the date fields
892 $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
896 # _ls_compare_sub but don't compare dates
897 _ls_nodate_compare_sub()
900 # verify we got back what we dumped
902 echo "Comparing listing of dump directory with restore directory"
903 ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
904 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
905 | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
907 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
912 # Compare using recursive diff the files of the dumped
914 # This one will compare the contents.
918 echo "Comparing dump directory with restore directory"
919 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
923 # Compare using recursive diff the files of the dumped
928 echo "Comparing dump directory with restore directory"
929 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
933 # Check out the dump inventory
937 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
941 # Do the xfsinvutil cmd with debug and filters
942 # Need to set variable: "$middate" to the invutil date
947 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
948 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
949 | tee -a $seq.full | _invutil_filter
952 # make sure this script returns success