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"
91 # Would have used src/testrmt but get
92 # permission denied from linux to linux for erase !?!
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
173 # src/testrmt -f $dumptape write
179 echo "Erasing tape" | tee -a $seq.full
185 echo $dumptape | grep ':' >/dev/null
197 echo "Put scsi tape driver into variable block size mode"
198 mt -f $dumptape setblk 0
204 if [ $# -eq 0 ]; then
210 if [ -z "$dumptape" ]; then
211 echo "This test requires a dump tape - none was specified"
212 echo "No dump tape specified" >$seq.notrun
223 echo "Error: $*" | tee -a $seq.full
224 echo "(see $seq.full for details)"
233 mkfs -t xfs -f $SCRATCH_DEV >>$seq.full ||\
236 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
237 _error "mount failed"
241 # Cleanup created dirs and files
249 if [ -n "$DEBUGDUMP" ]; then
250 # save it for inspection
251 tar -zcvf $seq.inventory.tgz /var/xfsdump/inventory
252 ls -lR /var/xfsdump/inventory >$seq.inventory.ls
255 # put inventory dir back
256 if [ -d /var/xfsdump/inventory.$seq ]; then
257 rm -rf /var/xfsdump/inventory # get rid of new one
258 mv /var/xfsdump/inventory.$seq /var/xfsdump/inventory
261 if [ $status -ne $NOTRUNSTS ]; then
262 # Sleep added to stop _check_fs from complaining that the
263 # scratch_dev is still busy
266 _check_fs $SCRATCH_DEV
272 # umount $SCRATCH_MNT >/dev/null
273 # mount $SCRATCH_MNT >/dev/null
278 # Run stress/src/fsstress to create a mixture of
279 # files,dirs,links,symlinks
281 # Pinched from stress/013.
283 _create_dumpdir_stress()
285 echo "Creating directory system to dump using src/fsstress."
289 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
292 if ! mkdir $dump_dir; then
293 echo " failed to mkdir $dump_dir"
298 echo "-----------------------------------------------"
299 echo "fsstress : $_param"
300 echo "-----------------------------------------------"
301 if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
303 echo " fsstress (count=$_count) returned $? - see $seq.full"
305 echo "--------------------------------------" >>$here/$seq.full
306 echo "output from fsstress:" >>$here/$seq.full
307 echo "--------------------------------------" >>$here/$seq.full
308 cat $tmp.out >>$here/$seq.full
317 cat <<End-of-File >$tmp.config
318 # pathname size in bytes owner group
320 small 10 $nobody $nobody
321 big 102400 daemon sys
323 sub/big 102400 $nobody sys
325 sub/a 1 $nobody $nobody
326 sub/b 2 $nobody $nobody
327 sub/c 4 $nobody $nobody
328 sub/d 8 $nobody $nobody
329 sub/e 16 $nobody $nobody
330 sub/f 32 $nobody $nobody
331 sub/g 64 $nobody $nobody
332 sub/h 128 $nobody $nobody
333 sub/i 256 $nobody $nobody
334 sub/j 512 $nobody $nobody
335 sub/k 1024 $nobody $nobody
336 sub/l 2048 $nobody $nobody
337 sub/m 4096 $nobody $nobody
338 sub/n 8192 $nobody $nobody
340 sub/a00 100 $nobody $nobody
341 sub/b00 200 $nobody $nobody
342 sub/c00 400 $nobody $nobody
343 sub/d00 800 $nobody $nobody
344 sub/e00 1600 $nobody $nobody
345 sub/f00 3200 $nobody $nobody
346 sub/g00 6400 $nobody $nobody
347 sub/h00 12800 $nobody $nobody
348 sub/i00 25600 $nobody $nobody
349 sub/j00 51200 $nobody $nobody
350 sub/k00 102400 $nobody $nobody
351 sub/l00 204800 $nobody $nobody
352 sub/m00 409600 $nobody $nobody
353 sub/n00 819200 $nobody $nobody
355 sub/a000 1000 $nobody $nobody
356 sub/e000 16000 $nobody $nobody
357 sub/h000 128000 $nobody $nobody
358 sub/k000 1024000 $nobody $nobody
364 cat <<End-of-File >$tmp.config
365 # pathname size in bytes
367 smalll 10 $nobody $nobody
368 biggg 102400 $nobody $nobody
369 sub/smalll 10 $nobody $nobody
370 sub/biggg 102400 $nobody $nobody
375 # Create a bunch of directories/files of different sizes
378 # Pinched from stress/001.
380 _do_create_dumpdir_fill()
382 echo "Creating directory system to dump using src/fill."
384 if mkdir -p $dump_dir
388 echo "Error: cannot mkdir \"$dump_dir\""
393 $verbose && echo -n "Setup "
394 sed -e '/^#/d' $tmp.config \
395 | while read file nbytes owner group perms
407 echo "Error: cannot mkdir \"$dir\""
413 if $here/src/fill $file $file $nbytes
418 echo "Error: cannot create \"$file\""
421 if [ -n "$owner" -a -n "$group" ]; then
422 chown $owner.$group $file
424 if [ -n "$perms" ]; then
427 $verbose && echo -n "."
435 _create_dumpdir_fill()
439 _do_create_dumpdir_fill
443 _create_dumpdir_fill2()
447 _do_create_dumpdir_fill
454 # Append a subset of the fill'ed files
455 # So we can see if just these get dumped on an incremental
457 _append_dumpdir_fill()
460 cat <<End-of-File >$tmp.config
470 sed -e '/^#/d' $tmp.config \
473 echo 'Extra text' >>$file
479 _do_create_dump_symlinks()
481 echo "Creating directory system of symlinks to dump."
483 if mkdir -p $dump_dir
487 echo "Error: cannot mkdir \"$dump_dir\""
492 $verbose && echo -n "Setup "
493 sed -e '/^#/d' $tmp.config \
494 | while read file nbytes owner group owner2 group2 perms perms2
506 echo "Error: cannot mkdir \"$dir\""
514 # Do chmod on symlink using umask.
515 # This won't do the right thing as it subtracts permissions.
516 # However, I don't care, as long as I get some different perms
518 if [ -n "$perms2" ]; then
522 ln -s $file $file-link
523 if [ -n "$perms2" ]; then
527 if [ -n "$owner" -a -n "$group" ]; then
528 chown $owner.$group $file
530 if [ -n "$owner" -a -n "$group" ]; then
531 chown -h $owner.$group $file-link
533 if [ -n "$perms" ]; then
536 $verbose && echo -n "."
545 cat <<End-of-File >$tmp.config
546 # path size owner1 group1 owner2 group2 perm1 perm2
548 a 0 $nobody $nobody daemon sys 124 421
549 b 0 daemon sys bin bin 347 743
550 sub/a 0 bin bin $nobody sys 777 777
551 sub/b 0 $nobody sys $nobody $nobody 367 763
555 _create_dumpdir_symlinks()
559 _do_create_dump_symlinks
565 # Filter out dates on symlinks
569 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
571 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
576 # Filter out the non-deterministic dump msgs from
577 # xfsdump and xfsrestore
582 -e "s/`hostname`/HOSTNAME/" \
583 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
584 -e "s#$dumptape#TAPE_DEV#" \
585 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
586 -e "s#$dump_file#DUMP_FILE#" \
587 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
588 -e 's/time:[ ].*/time: TIME/' \
589 -e 's/date:[ ].*/date: DATE/' \
590 -e 's/dump begun .*/dump begun DATE/' \
591 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
592 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
593 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
594 -e '/media file size/s/[1-9][0-9]*/NUM/' \
596 -e '/inventory session uuid/d' \
604 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
605 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
606 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
607 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
614 -e "s#$dump_file#DUMP_FILE#" \
615 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
616 -e "s#$dumptape#TAPE_DEV#" \
617 -e "s#$dump_dir#DUMP_DIR#g" \
618 -e "s#$restore_dir#RESTORE_DIR#g" \
619 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
620 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
621 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
629 while getopts "f:FL:o" c $*
634 [ -z "$OPTARG" ] && _error "missing argument for -f"
638 [ -z "$OPTARG" ] && _error "missing argument for -L"
639 session_label=$OPTARG
642 dump_args="$dump_args -o"
645 dump_args="$dump_args -F"
648 _error "invalid argument"
662 echo "Dumping to tape..."
663 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
664 echo "xfsdump $opts" | _dir_filter
665 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
669 # Do full level 0 dump
675 echo "Dumping to tape..."
676 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
677 echo "xfsdump $opts" | _dir_filter
678 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
683 # Do full dump with -m
689 echo "Dumping to tape..."
691 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
692 echo "xfsdump $opts" | _dir_filter
693 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
697 # Do level 1 incremental dump
699 _do_dump_incremental()
703 echo "Dumping incrementally to tape..."
704 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
705 echo "xfsdump $opts" | _dir_filter
706 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
710 # Do full dump to file
716 echo "Dumping to file..."
717 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
718 echo "xfsdump $opts" | _dir_filter
719 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
723 _prepare_restore_dir()
726 if ! mkdir $restore_dir; then
727 echo " failed to mkdir $restore_dir"
735 # Get tape ready and restore dir
741 echo "Rewinding tape"
746 # Restore the tape into $restore_dir
754 echo "Restoring from tape..."
755 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
756 echo "xfsrestore $opts" | _dir_filter
757 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
761 # Restore the tape into $restore_dir using -m
768 echo "Restoring from tape..."
770 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
771 echo "xfsrestore $opts" | _dir_filter
772 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
776 # Restore the tape from a dump file
783 echo "Restoring from file..."
784 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
785 echo "xfsrestore $opts" | _dir_filter
786 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
790 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
792 # Use -s as we want to dump and restore to the same xfs partition
798 echo "xfsdump|xfsrestore ..."
799 restore_opts="$_restore_debug - $restore_dir"
800 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
801 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
802 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
803 _dump_filter <$tmp.dump.mlog
807 # Compare dumped subdirectory with restored dir
809 # Thus no contents are compared but permissions, sizes,
810 # owners, etc... are.
815 # verify we got back what we dumped
817 echo "Comparing listing of dump directory with restore directory"
818 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
819 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
820 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
822 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
827 # Compare using recursive diff the files of the dumped
829 # This one will compare the contents.
833 echo "Comparing dump directory with restore directory"
834 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
838 # Compare using recursive diff the files of the dumped
843 echo "Comparing dump directory with restore directory"
844 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
848 # Check out the dump inventory
852 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
856 # Do the xfsinvutil cmd with debug and filters
857 # Need to set variable: "$middate" to the invutil date
862 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
863 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
864 | tee -a $seq.full | _invutil_filter
867 # make sure this script returns success