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_dir=$SCRATCH_MNT/dump.$$
57 dump_file=$tmp.dumpfile
59 restore_dir=$SCRATCH_MNT/restore.$$
60 restore_sdir=restore.$$
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 -F: '{print $2}'`
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"
98 _rmthost=`echo $dumptape | awk -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 >/dev/null
276 # mount $SCRATCH_MNT >/dev/null
281 # Run src/fsstress to create a mixture of
282 # files,dirs,links,symlinks
284 # Pinched from test 013.
286 _create_dumpdir_stress()
288 echo "Creating directory system to dump using src/fsstress."
292 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
295 if ! mkdir $dump_dir; then
296 echo " failed to mkdir $dump_dir"
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
306 echo " fsstress (count=$_count) returned $? - see $seq.full"
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
320 cat <<End-of-File >$tmp.config
321 # pathname size in bytes owner group
323 small 10 $nobody $nobody
324 big 102400 daemon sys
326 sub/big 102400 $nobody sys
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
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
358 sub/a000 1000 $nobody $nobody
359 sub/e000 16000 $nobody $nobody
360 sub/h000 128000 $nobody $nobody
361 sub/k000 1024000 $nobody $nobody
367 cat <<End-of-File >$tmp.config
368 # pathname size in bytes
370 smalll 10 $nobody $nobody
371 biggg 102400 $nobody $nobody
372 sub/smalll 10 $nobody $nobody
373 sub/biggg 102400 $nobody $nobody
377 _mk_fillconfig_perm()
379 cat <<End-of-File >$tmp.config
380 # pathname size/dir user group mode
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
396 # Create a bunch of directories/files of different sizes
399 # Pinched from test 001.
401 _do_create_dumpdir_fill()
403 echo "Creating directory system to dump using src/fill."
405 if mkdir -p $dump_dir
409 echo "Error: cannot mkdir \"$dump_dir\""
414 $verbose && echo -n "Setup "
415 sed -e '/^#/d' $tmp.config \
416 | while read file nbytes owner group perms
418 if [ $nbytes = "d" ]; then
428 echo "Error: cannot mkdir \"$dir\""
433 # create a directory/file
444 echo "Error: cannot mkdir \"$dir\""
450 if $here/src/fill $file $file $nbytes
455 echo "Error: cannot create \"$file\""
459 if [ -n "$owner" -a -n "$group" ]; then
460 chown $owner.$group $file
462 if [ -n "$perms" ]; then
465 $verbose && echo -n "."
473 _create_dumpdir_fill()
478 _do_create_dumpdir_fill
482 _create_dumpdir_fill2()
487 _do_create_dumpdir_fill
491 _create_dumpdir_fill_perm()
496 _do_create_dumpdir_fill
503 # Append a subset of the fill'ed files
504 # So we can see if just these get dumped on an incremental
506 _append_dumpdir_fill()
509 cat <<End-of-File >$tmp.config
519 sed -e '/^#/d' $tmp.config \
522 echo 'Extra text' >>$file
528 _do_create_dump_symlinks()
530 echo "Creating directory system of symlinks to dump."
532 if mkdir -p $dump_dir
536 echo "Error: cannot mkdir \"$dump_dir\""
541 $verbose && echo -n "Setup "
542 sed -e '/^#/d' $tmp.config \
543 | while read file nbytes owner group owner2 group2 perms perms2
555 echo "Error: cannot mkdir \"$dir\""
563 # Do chmod on symlink using umask.
564 # This won't do the right thing as it subtracts permissions.
565 # However, I don't care, as long as I get some different perms
567 if [ -n "$perms2" ]; then
571 ln -s $file $file-link
572 if [ -n "$perms2" ]; then
576 if [ -n "$owner" -a -n "$group" ]; then
577 chown $owner.$group $file
579 if [ -n "$owner" -a -n "$group" ]; then
580 chown -h $owner.$group $file-link
582 if [ -n "$perms" ]; then
585 $verbose && echo -n "."
594 cat <<End-of-File >$tmp.config
595 # path size owner1 group1 owner2 group2 perm1 perm2
597 a 0 $nobody $nobody daemon sys 124 421
598 b 0 daemon sys bin bin 347 743
599 sub/a 0 bin bin $nobody sys 777 777
600 sub/b 0 $nobody sys $nobody $nobody 367 763
604 _create_dumpdir_symlinks()
608 _do_create_dump_symlinks
614 # Filter out dates on symlinks
618 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
620 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
625 # Filter out the non-deterministic dump msgs from
626 # xfsdump and xfsrestore
631 -e "s/`hostname`/HOSTNAME/" \
632 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
633 -e "s#$dumptape#TAPE_DEV#" \
634 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
635 -e "s#$dump_file#DUMP_FILE#" \
636 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
637 -e 's/time:[ ].*/time: TIME/' \
638 -e 's/date:[ ].*/date: DATE/' \
639 -e 's/dump begun .*/dump begun DATE/' \
640 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
641 -e 's/restore.[0-9][0-9]*/restore.PID/' \
642 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
643 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
644 -e '/media file size/s/[1-9][0-9]*/NUM/' \
646 -e '/inventory session uuid/d' \
654 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
655 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
656 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
657 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
664 -e "s#$dump_file#DUMP_FILE#" \
665 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
666 -e "s#$dumptape#TAPE_DEV#" \
667 -e "s#$dump_dir#DUMP_DIR#g" \
668 -e "s#$restore_dir#RESTORE_DIR#g" \
669 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
670 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
671 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
679 while getopts "f:FL:o" c $*
684 [ -z "$OPTARG" ] && _error "missing argument for -f"
688 [ -z "$OPTARG" ] && _error "missing argument for -L"
689 session_label=$OPTARG
692 dump_args="$dump_args -o"
695 dump_args="$dump_args -F"
698 _error "invalid argument"
712 echo "Dumping to tape..."
713 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
714 echo "xfsdump $opts" | _dir_filter
715 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
719 # Do full level 0 dump
725 echo "Dumping to tape..."
726 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
727 echo "xfsdump $opts" | _dir_filter
728 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
733 # Do full dump with -m
739 echo "Dumping to tape..."
741 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
742 echo "xfsdump $opts" | _dir_filter
743 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
747 # Do level 1 incremental dump
749 _do_dump_incremental()
753 echo "Dumping incrementally to tape..."
754 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
755 echo "xfsdump $opts" | _dir_filter
756 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
760 # Do full dump to file
766 echo "Dumping to file..."
767 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
768 echo "xfsdump $opts" | _dir_filter
769 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
773 _prepare_restore_dir()
776 if ! mkdir $restore_dir; then
777 echo " failed to mkdir $restore_dir"
785 # Get tape ready and restore dir
791 echo "Rewinding tape"
796 # Restore the tape into $restore_dir
804 echo "Restoring from tape..."
805 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
806 echo "xfsrestore $opts" | _dir_filter
807 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
811 # Restore the tape into $restore_dir using -m
818 echo "Restoring from tape..."
820 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
821 echo "xfsrestore $opts" | _dir_filter
822 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
826 # Restore the tape from a dump file
833 echo "Restoring from file..."
834 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
835 echo "xfsrestore $opts" | _dir_filter
836 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
840 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
842 # Use -s as we want to dump and restore to the same xfs partition
848 echo "xfsdump|xfsrestore ..."
849 restore_opts="$_restore_debug - $restore_dir"
850 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
851 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
852 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
853 _dump_filter <$tmp.dump.mlog
857 # Compare dumped subdirectory with restored dir
859 # Thus no contents are compared but permissions, sizes,
860 # owners, etc... are.
865 # verify we got back what we dumped
867 echo "Comparing listing of dump directory with restore directory"
868 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
869 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
870 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
872 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
877 # Compare using recursive diff the files of the dumped
879 # This one will compare the contents.
883 echo "Comparing dump directory with restore directory"
884 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
888 # Compare using recursive diff the files of the dumped
893 echo "Comparing dump directory with restore directory"
894 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
898 # Check out the dump inventory
902 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
906 # Do the xfsinvutil cmd with debug and filters
907 # Need to set variable: "$middate" to the invutil date
912 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
913 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
914 | tee -a $seq.full | _invutil_filter
917 # make sure this script returns success