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 _rmthost=`echo $dumptape | awk -F: '{print $1}'`
91 _rmtdev=`echo $dumptape | awk -F: '{print $2}'`
92 rsh -n $_rmthost "mt -t $_rmtdev $op"
103 while [ $i -lt $_limit ]; do
104 echo "Checking online..." >>$seq.full
105 if _mt status >$tmp.status 2>&1; then
114 if [ $i -eq $_limit ]; then
115 echo "ERROR: mt -f $dumptape failed"
118 echo "mt -f $dumptape failed" >$seq.notrun
124 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
127 echo "ERROR: $dumptape is not online"
130 echo "dumptape, $dumptape, is not online" >$seq.notrun
138 echo "Wait for tape, $dumptape, ..." >>$seq.full
141 while [ $i -lt 20 ]; do
142 echo "Checking status..." >>$seq.full
143 if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
153 # Keep trying so we know we really have rewound
157 echo "Initiate rewind..." >>$seq.full
159 _mt rewind >/dev/null
164 # Do a custom erase because:
165 # (i) some machines don't support it
166 # (ii) some machines take forever to do it
170 echo "Erasing tape" | tee -a $seq.full
178 echo "Erasing tape" | tee -a $seq.full
184 echo $dumptape | grep ':' >/dev/null
196 echo "Put scsi tape driver into variable block size mode"
197 mt -f $dumptape setblk 0
205 if [ -z "$dumptape" ]; then
206 echo "This test requires a dump tape - none was specified"
207 echo "No dump tape specified" >$seq.notrun
218 echo "Error: $*" | tee -a $seq.full
219 echo "(see $seq.full for details)"
228 mkfs -t xfs -f $SCRATCH_DEV >>$seq.full ||\
231 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
232 _error "mount failed"
236 # Cleanup created dirs and files
244 if [ -n "$DEBUGDUMP" ]; then
245 # save it for inspection
246 tar -zcvf $seq.inventory.tgz /var/xfsdump/inventory
247 ls -lR /var/xfsdump/inventory >$seq.inventory.ls
250 # put inventory dir back
251 if [ -d /var/xfsdump/inventory.$seq ]; then
252 rm -rf /var/xfsdump/inventory # get rid of new one
253 mv /var/xfsdump/inventory.$seq /var/xfsdump/inventory
256 if [ $status -ne $NOTRUNSTS ]; then
257 # Sleep added to stop _check_fs from complaining that the
258 # scratch_dev is still busy
261 _check_fs $SCRATCH_DEV
267 # umount $SCRATCH_MNT >/dev/null
268 # mount $SCRATCH_MNT >/dev/null
273 # Run src/fsstress to create a mixture of
274 # files,dirs,links,symlinks
276 # Pinched from test 013.
278 _create_dumpdir_stress()
280 echo "Creating directory system to dump using src/fsstress."
284 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
287 if ! mkdir $dump_dir; then
288 echo " failed to mkdir $dump_dir"
293 echo "-----------------------------------------------"
294 echo "fsstress : $_param"
295 echo "-----------------------------------------------"
296 if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
298 echo " fsstress (count=$_count) returned $? - see $seq.full"
300 echo "--------------------------------------" >>$here/$seq.full
301 echo "output from fsstress:" >>$here/$seq.full
302 echo "--------------------------------------" >>$here/$seq.full
303 cat $tmp.out >>$here/$seq.full
312 cat <<End-of-File >$tmp.config
313 # pathname size in bytes owner group
315 small 10 $nobody $nobody
316 big 102400 daemon sys
318 sub/big 102400 $nobody sys
320 sub/a 1 $nobody $nobody
321 sub/b 2 $nobody $nobody
322 sub/c 4 $nobody $nobody
323 sub/d 8 $nobody $nobody
324 sub/e 16 $nobody $nobody
325 sub/f 32 $nobody $nobody
326 sub/g 64 $nobody $nobody
327 sub/h 128 $nobody $nobody
328 sub/i 256 $nobody $nobody
329 sub/j 512 $nobody $nobody
330 sub/k 1024 $nobody $nobody
331 sub/l 2048 $nobody $nobody
332 sub/m 4096 $nobody $nobody
333 sub/n 8192 $nobody $nobody
335 sub/a00 100 $nobody $nobody
336 sub/b00 200 $nobody $nobody
337 sub/c00 400 $nobody $nobody
338 sub/d00 800 $nobody $nobody
339 sub/e00 1600 $nobody $nobody
340 sub/f00 3200 $nobody $nobody
341 sub/g00 6400 $nobody $nobody
342 sub/h00 12800 $nobody $nobody
343 sub/i00 25600 $nobody $nobody
344 sub/j00 51200 $nobody $nobody
345 sub/k00 102400 $nobody $nobody
346 sub/l00 204800 $nobody $nobody
347 sub/m00 409600 $nobody $nobody
348 sub/n00 819200 $nobody $nobody
350 sub/a000 1000 $nobody $nobody
351 sub/e000 16000 $nobody $nobody
352 sub/h000 128000 $nobody $nobody
353 sub/k000 1024000 $nobody $nobody
359 cat <<End-of-File >$tmp.config
360 # pathname size in bytes
362 smalll 10 $nobody $nobody
363 biggg 102400 $nobody $nobody
364 sub/smalll 10 $nobody $nobody
365 sub/biggg 102400 $nobody $nobody
370 # Create a bunch of directories/files of different sizes
373 # Pinched from test 001.
375 _do_create_dumpdir_fill()
377 echo "Creating directory system to dump using src/fill."
379 if mkdir -p $dump_dir
383 echo "Error: cannot mkdir \"$dump_dir\""
388 $verbose && echo -n "Setup "
389 sed -e '/^#/d' $tmp.config \
390 | while read file nbytes owner group perms
402 echo "Error: cannot mkdir \"$dir\""
408 if $here/src/fill $file $file $nbytes
413 echo "Error: cannot create \"$file\""
416 if [ -n "$owner" -a -n "$group" ]; then
417 chown $owner.$group $file
419 if [ -n "$perms" ]; then
422 $verbose && echo -n "."
430 _create_dumpdir_fill()
434 _do_create_dumpdir_fill
438 _create_dumpdir_fill2()
442 _do_create_dumpdir_fill
449 # Append a subset of the fill'ed files
450 # So we can see if just these get dumped on an incremental
452 _append_dumpdir_fill()
455 cat <<End-of-File >$tmp.config
465 sed -e '/^#/d' $tmp.config \
468 echo 'Extra text' >>$file
474 _do_create_dump_symlinks()
476 echo "Creating directory system of symlinks to dump."
478 if mkdir -p $dump_dir
482 echo "Error: cannot mkdir \"$dump_dir\""
487 $verbose && echo -n "Setup "
488 sed -e '/^#/d' $tmp.config \
489 | while read file nbytes owner group owner2 group2 perms perms2
501 echo "Error: cannot mkdir \"$dir\""
509 # Do chmod on symlink using umask.
510 # This won't do the right thing as it subtracts permissions.
511 # However, I don't care, as long as I get some different perms
513 if [ -n "$perms2" ]; then
517 ln -s $file $file-link
518 if [ -n "$perms2" ]; then
522 if [ -n "$owner" -a -n "$group" ]; then
523 chown $owner.$group $file
525 if [ -n "$owner" -a -n "$group" ]; then
526 chown -h $owner.$group $file-link
528 if [ -n "$perms" ]; then
531 $verbose && echo -n "."
540 cat <<End-of-File >$tmp.config
541 # path size owner1 group1 owner2 group2 perm1 perm2
543 a 0 $nobody $nobody daemon sys 124 421
544 b 0 daemon sys bin bin 347 743
545 sub/a 0 bin bin $nobody sys 777 777
546 sub/b 0 $nobody sys $nobody $nobody 367 763
550 _create_dumpdir_symlinks()
554 _do_create_dump_symlinks
560 # Filter out dates on symlinks
564 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
566 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
571 # Filter out the non-deterministic dump msgs from
572 # xfsdump and xfsrestore
577 -e "s/`hostname`/HOSTNAME/" \
578 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
579 -e "s#$dumptape#TAPE_DEV#" \
580 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
581 -e "s#$dump_file#DUMP_FILE#" \
582 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
583 -e 's/time:[ ].*/time: TIME/' \
584 -e 's/date:[ ].*/date: DATE/' \
585 -e 's/dump begun .*/dump begun DATE/' \
586 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
587 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
588 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
589 -e '/media file size/s/[1-9][0-9]*/NUM/' \
591 -e '/inventory session uuid/d' \
599 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
600 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
601 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
602 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
609 -e "s#$dump_file#DUMP_FILE#" \
610 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
611 -e "s#$dumptape#TAPE_DEV#" \
612 -e "s#$dump_dir#DUMP_DIR#g" \
613 -e "s#$restore_dir#RESTORE_DIR#g" \
614 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
615 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
616 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
624 while getopts "f:FL:o" c $*
629 [ -z "$OPTARG" ] && _error "missing argument for -f"
633 [ -z "$OPTARG" ] && _error "missing argument for -L"
634 session_label=$OPTARG
637 dump_args="$dump_args -o"
640 dump_args="$dump_args -F"
643 _error "invalid argument"
657 echo "Dumping to tape..."
658 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
659 echo "xfsdump $opts" | _dir_filter
660 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
664 # Do full level 0 dump
670 echo "Dumping to tape..."
671 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
672 echo "xfsdump $opts" | _dir_filter
673 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
678 # Do full dump with -m
684 echo "Dumping to tape..."
686 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
687 echo "xfsdump $opts" | _dir_filter
688 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
692 # Do level 1 incremental dump
694 _do_dump_incremental()
698 echo "Dumping incrementally to tape..."
699 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
700 echo "xfsdump $opts" | _dir_filter
701 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
705 # Do full dump to file
711 echo "Dumping to file..."
712 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
713 echo "xfsdump $opts" | _dir_filter
714 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
718 _prepare_restore_dir()
721 if ! mkdir $restore_dir; then
722 echo " failed to mkdir $restore_dir"
730 # Get tape ready and restore dir
736 echo "Rewinding tape"
741 # Restore the tape into $restore_dir
749 echo "Restoring from tape..."
750 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
751 echo "xfsrestore $opts" | _dir_filter
752 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
756 # Restore the tape into $restore_dir using -m
763 echo "Restoring from tape..."
765 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
766 echo "xfsrestore $opts" | _dir_filter
767 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
771 # Restore the tape from a dump file
778 echo "Restoring from file..."
779 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
780 echo "xfsrestore $opts" | _dir_filter
781 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
785 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
787 # Use -s as we want to dump and restore to the same xfs partition
793 echo "xfsdump|xfsrestore ..."
794 restore_opts="$_restore_debug - $restore_dir"
795 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
796 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
797 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
798 _dump_filter <$tmp.dump.mlog
802 # Compare dumped subdirectory with restored dir
804 # Thus no contents are compared but permissions, sizes,
805 # owners, etc... are.
810 # verify we got back what we dumped
812 echo "Comparing listing of dump directory with restore directory"
813 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
814 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
815 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
817 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
822 # Compare using recursive diff the files of the dumped
824 # This one will compare the contents.
828 echo "Comparing dump directory with restore directory"
829 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
833 # Compare using recursive diff the files of the dumped
838 echo "Comparing dump directory with restore directory"
839 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
843 # Check out the dump inventory
847 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
851 # Do the xfsinvutil cmd with debug and filters
852 # Need to set variable: "$middate" to the invutil date
857 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
858 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
859 | tee -a $seq.full | _invutil_filter
862 # make sure this script returns success