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 out of workareas
47 PATH="../dump/dump:../dump/restore:../dump/invutil:$PATH"
50 # status returned for not run tests
53 # name those directories
54 dump_dir=$SCRATCH_MNT/dump.$$
55 dump_file=$tmp.dumpfile
57 restore_dir=$SCRATCH_MNT/restore.$$
58 restore_sdir=restore.$$
61 media_label="stress_tape_media"
62 session_label="stress_$seq"
64 nobody=4 # define this uid/gid as a number
69 trap "_cleanup; exit \$status" 0 1 2 3 15
71 # start inventory from a known base - move it aside for test
72 if [ -d /var/xfsdump/inventory ]; then
73 if [ -d /var/xfsdump/inventory.$seq ]; then
74 rm -rf /var/xfsdump/inventory.$seq
76 mv /var/xfsdump/inventory /var/xfsdump/inventory.$seq
81 # do a remote/local mt
88 _rmthost=`echo $dumptape | awk -F: '{print $1}'`
89 _rmtdev=`echo $dumptape | awk -F: '{print $2}'`
90 rsh -n $_rmthost "mt -t $_rmtdev $op"
101 while [ $i -lt $_limit ]; do
102 echo "Checking online..." >>$seq.full
103 if _mt status >$tmp.status 2>&1; then
112 if [ $i -eq $_limit ]; then
113 echo "ERROR: mt -f $dumptape failed"
116 echo "mt -f $dumptape failed" >$seq.notrun
122 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
125 echo "ERROR: $dumptape is not online"
128 echo "dumptape, $dumptape, is not online" >$seq.notrun
136 echo "Wait for tape, $dumptape, ..." >>$seq.full
139 while [ $i -lt 20 ]; do
140 echo "Checking status..." >>$seq.full
141 if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
151 # Keep trying so we know we really have rewound
155 echo "Initiate rewind..." >>$seq.full
157 _mt rewind >/dev/null
162 # Do a custom erase because:
163 # (i) some machines don't support it
164 # (ii) some machines take forever to do it
168 echo "Erasing tape" | tee -a $seq.full
176 echo "Erasing tape" | tee -a $seq.full
182 echo $dumptape | grep ':' >/dev/null
194 echo "Put scsi tape driver into variable block size mode"
195 mt -f $dumptape setblk 0
201 if [ $# -eq 0 ]; then
207 if [ -z "$dumptape" ]; then
208 echo "This test requires a dump tape - none was specified"
209 echo "No dump tape specified" >$seq.notrun
220 echo "Error: $*" | tee -a $seq.full
221 echo "(see $seq.full for details)"
230 mkfs -t xfs -f $SCRATCH_DEV >>$seq.full ||\
233 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
234 _error "mount failed"
238 # Cleanup created dirs and files
246 if [ -n "$DEBUGDUMP" ]; then
247 # save it for inspection
248 tar -zcvf $seq.inventory.tgz /var/xfsdump/inventory
249 ls -lR /var/xfsdump/inventory >$seq.inventory.ls
252 # put inventory dir back
253 if [ -d /var/xfsdump/inventory.$seq ]; then
254 rm -rf /var/xfsdump/inventory # get rid of new one
255 mv /var/xfsdump/inventory.$seq /var/xfsdump/inventory
258 if [ $status -ne $NOTRUNSTS ]; then
259 # Sleep added to stop _check_fs from complaining that the
260 # scratch_dev is still busy
263 _check_fs $SCRATCH_DEV
269 # umount $SCRATCH_MNT >/dev/null
270 # mount $SCRATCH_MNT >/dev/null
275 # Run src/fsstress to create a mixture of
276 # files,dirs,links,symlinks
278 # Pinched from test 013.
280 _create_dumpdir_stress()
282 echo "Creating directory system to dump using src/fsstress."
286 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
289 if ! mkdir $dump_dir; then
290 echo " failed to mkdir $dump_dir"
295 echo "-----------------------------------------------"
296 echo "fsstress : $_param"
297 echo "-----------------------------------------------"
298 if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
300 echo " fsstress (count=$_count) returned $? - see $seq.full"
302 echo "--------------------------------------" >>$here/$seq.full
303 echo "output from fsstress:" >>$here/$seq.full
304 echo "--------------------------------------" >>$here/$seq.full
305 cat $tmp.out >>$here/$seq.full
314 cat <<End-of-File >$tmp.config
315 # pathname size in bytes owner group
317 small 10 $nobody $nobody
318 big 102400 daemon sys
320 sub/big 102400 $nobody sys
322 sub/a 1 $nobody $nobody
323 sub/b 2 $nobody $nobody
324 sub/c 4 $nobody $nobody
325 sub/d 8 $nobody $nobody
326 sub/e 16 $nobody $nobody
327 sub/f 32 $nobody $nobody
328 sub/g 64 $nobody $nobody
329 sub/h 128 $nobody $nobody
330 sub/i 256 $nobody $nobody
331 sub/j 512 $nobody $nobody
332 sub/k 1024 $nobody $nobody
333 sub/l 2048 $nobody $nobody
334 sub/m 4096 $nobody $nobody
335 sub/n 8192 $nobody $nobody
337 sub/a00 100 $nobody $nobody
338 sub/b00 200 $nobody $nobody
339 sub/c00 400 $nobody $nobody
340 sub/d00 800 $nobody $nobody
341 sub/e00 1600 $nobody $nobody
342 sub/f00 3200 $nobody $nobody
343 sub/g00 6400 $nobody $nobody
344 sub/h00 12800 $nobody $nobody
345 sub/i00 25600 $nobody $nobody
346 sub/j00 51200 $nobody $nobody
347 sub/k00 102400 $nobody $nobody
348 sub/l00 204800 $nobody $nobody
349 sub/m00 409600 $nobody $nobody
350 sub/n00 819200 $nobody $nobody
352 sub/a000 1000 $nobody $nobody
353 sub/e000 16000 $nobody $nobody
354 sub/h000 128000 $nobody $nobody
355 sub/k000 1024000 $nobody $nobody
361 cat <<End-of-File >$tmp.config
362 # pathname size in bytes
364 smalll 10 $nobody $nobody
365 biggg 102400 $nobody $nobody
366 sub/smalll 10 $nobody $nobody
367 sub/biggg 102400 $nobody $nobody
372 # Create a bunch of directories/files of different sizes
375 # Pinched from test 001.
377 _do_create_dumpdir_fill()
379 echo "Creating directory system to dump using src/fill."
381 if mkdir -p $dump_dir
385 echo "Error: cannot mkdir \"$dump_dir\""
390 $verbose && echo -n "Setup "
391 sed -e '/^#/d' $tmp.config \
392 | while read file nbytes owner group perms
404 echo "Error: cannot mkdir \"$dir\""
410 if $here/src/fill $file $file $nbytes
415 echo "Error: cannot create \"$file\""
418 if [ -n "$owner" -a -n "$group" ]; then
419 chown $owner.$group $file
421 if [ -n "$perms" ]; then
424 $verbose && echo -n "."
432 _create_dumpdir_fill()
436 _do_create_dumpdir_fill
440 _create_dumpdir_fill2()
444 _do_create_dumpdir_fill
451 # Append a subset of the fill'ed files
452 # So we can see if just these get dumped on an incremental
454 _append_dumpdir_fill()
457 cat <<End-of-File >$tmp.config
467 sed -e '/^#/d' $tmp.config \
470 echo 'Extra text' >>$file
476 _do_create_dump_symlinks()
478 echo "Creating directory system of symlinks to dump."
480 if mkdir -p $dump_dir
484 echo "Error: cannot mkdir \"$dump_dir\""
489 $verbose && echo -n "Setup "
490 sed -e '/^#/d' $tmp.config \
491 | while read file nbytes owner group owner2 group2 perms perms2
503 echo "Error: cannot mkdir \"$dir\""
511 # Do chmod on symlink using umask.
512 # This won't do the right thing as it subtracts permissions.
513 # However, I don't care, as long as I get some different perms
515 if [ -n "$perms2" ]; then
519 ln -s $file $file-link
520 if [ -n "$perms2" ]; then
524 if [ -n "$owner" -a -n "$group" ]; then
525 chown $owner.$group $file
527 if [ -n "$owner" -a -n "$group" ]; then
528 chown -h $owner.$group $file-link
530 if [ -n "$perms" ]; then
533 $verbose && echo -n "."
542 cat <<End-of-File >$tmp.config
543 # path size owner1 group1 owner2 group2 perm1 perm2
545 a 0 $nobody $nobody daemon sys 124 421
546 b 0 daemon sys bin bin 347 743
547 sub/a 0 bin bin $nobody sys 777 777
548 sub/b 0 $nobody sys $nobody $nobody 367 763
552 _create_dumpdir_symlinks()
556 _do_create_dump_symlinks
562 # Filter out dates on symlinks
566 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
568 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
573 # Filter out the non-deterministic dump msgs from
574 # xfsdump and xfsrestore
579 -e "s/`hostname`/HOSTNAME/" \
580 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
581 -e "s#$dumptape#TAPE_DEV#" \
582 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
583 -e "s#$dump_file#DUMP_FILE#" \
584 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
585 -e 's/time:[ ].*/time: TIME/' \
586 -e 's/date:[ ].*/date: DATE/' \
587 -e 's/dump begun .*/dump begun DATE/' \
588 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
589 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
590 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
591 -e '/media file size/s/[1-9][0-9]*/NUM/' \
593 -e '/inventory session uuid/d' \
601 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
602 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
603 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
604 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
611 -e "s#$dump_file#DUMP_FILE#" \
612 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
613 -e "s#$dumptape#TAPE_DEV#" \
614 -e "s#$dump_dir#DUMP_DIR#g" \
615 -e "s#$restore_dir#RESTORE_DIR#g" \
616 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
617 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
618 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
626 while getopts "f:FL:o" c $*
631 [ -z "$OPTARG" ] && _error "missing argument for -f"
635 [ -z "$OPTARG" ] && _error "missing argument for -L"
636 session_label=$OPTARG
639 dump_args="$dump_args -o"
642 dump_args="$dump_args -F"
645 _error "invalid argument"
659 echo "Dumping to tape..."
660 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
661 echo "xfsdump $opts" | _dir_filter
662 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
666 # Do full level 0 dump
672 echo "Dumping to tape..."
673 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
674 echo "xfsdump $opts" | _dir_filter
675 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
680 # Do full dump with -m
686 echo "Dumping to tape..."
688 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
689 echo "xfsdump $opts" | _dir_filter
690 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
694 # Do level 1 incremental dump
696 _do_dump_incremental()
700 echo "Dumping incrementally to tape..."
701 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
702 echo "xfsdump $opts" | _dir_filter
703 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
707 # Do full dump to file
713 echo "Dumping to file..."
714 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
715 echo "xfsdump $opts" | _dir_filter
716 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
720 _prepare_restore_dir()
723 if ! mkdir $restore_dir; then
724 echo " failed to mkdir $restore_dir"
732 # Get tape ready and restore dir
738 echo "Rewinding tape"
743 # Restore the tape into $restore_dir
751 echo "Restoring from tape..."
752 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
753 echo "xfsrestore $opts" | _dir_filter
754 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
758 # Restore the tape into $restore_dir using -m
765 echo "Restoring from tape..."
767 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
768 echo "xfsrestore $opts" | _dir_filter
769 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
773 # Restore the tape from a dump file
780 echo "Restoring from file..."
781 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
782 echo "xfsrestore $opts" | _dir_filter
783 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
787 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
789 # Use -s as we want to dump and restore to the same xfs partition
795 echo "xfsdump|xfsrestore ..."
796 restore_opts="$_restore_debug - $restore_dir"
797 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
798 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
799 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
800 _dump_filter <$tmp.dump.mlog
804 # Compare dumped subdirectory with restored dir
806 # Thus no contents are compared but permissions, sizes,
807 # owners, etc... are.
812 # verify we got back what we dumped
814 echo "Comparing listing of dump directory with restore directory"
815 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
816 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
817 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
819 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
824 # Compare using recursive diff the files of the dumped
826 # This one will compare the contents.
830 echo "Comparing dump directory with restore directory"
831 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
835 # Compare using recursive diff the files of the dumped
840 echo "Comparing dump directory with restore directory"
841 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
845 # Check out the dump inventory
849 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
853 # Do the xfsinvutil cmd with debug and filters
854 # Need to set variable: "$middate" to the invutil date
859 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
860 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
861 | tee -a $seq.full | _invutil_filter
864 # make sure this script returns success