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()
477 _do_create_dumpdir_fill
481 _create_dumpdir_fill2()
485 _do_create_dumpdir_fill
489 _create_dumpdir_fill_perm()
493 _do_create_dumpdir_fill
500 # Append a subset of the fill'ed files
501 # So we can see if just these get dumped on an incremental
503 _append_dumpdir_fill()
506 cat <<End-of-File >$tmp.config
516 sed -e '/^#/d' $tmp.config \
519 echo 'Extra text' >>$file
525 _do_create_dump_symlinks()
527 echo "Creating directory system of symlinks to dump."
529 if mkdir -p $dump_dir
533 echo "Error: cannot mkdir \"$dump_dir\""
538 $verbose && echo -n "Setup "
539 sed -e '/^#/d' $tmp.config \
540 | while read file nbytes owner group owner2 group2 perms perms2
552 echo "Error: cannot mkdir \"$dir\""
560 # Do chmod on symlink using umask.
561 # This won't do the right thing as it subtracts permissions.
562 # However, I don't care, as long as I get some different perms
564 if [ -n "$perms2" ]; then
568 ln -s $file $file-link
569 if [ -n "$perms2" ]; then
573 if [ -n "$owner" -a -n "$group" ]; then
574 chown $owner.$group $file
576 if [ -n "$owner" -a -n "$group" ]; then
577 chown -h $owner.$group $file-link
579 if [ -n "$perms" ]; then
582 $verbose && echo -n "."
591 cat <<End-of-File >$tmp.config
592 # path size owner1 group1 owner2 group2 perm1 perm2
594 a 0 $nobody $nobody daemon sys 124 421
595 b 0 daemon sys bin bin 347 743
596 sub/a 0 bin bin $nobody sys 777 777
597 sub/b 0 $nobody sys $nobody $nobody 367 763
601 _create_dumpdir_symlinks()
605 _do_create_dump_symlinks
611 # Filter out dates on symlinks
615 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
617 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
622 # Filter out the non-deterministic dump msgs from
623 # xfsdump and xfsrestore
628 -e "s/`hostname`/HOSTNAME/" \
629 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
630 -e "s#$dumptape#TAPE_DEV#" \
631 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
632 -e "s#$dump_file#DUMP_FILE#" \
633 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
634 -e 's/time:[ ].*/time: TIME/' \
635 -e 's/date:[ ].*/date: DATE/' \
636 -e 's/dump begun .*/dump begun DATE/' \
637 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
638 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
639 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
640 -e '/media file size/s/[1-9][0-9]*/NUM/' \
642 -e '/inventory session uuid/d' \
650 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
651 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
652 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
653 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
660 -e "s#$dump_file#DUMP_FILE#" \
661 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
662 -e "s#$dumptape#TAPE_DEV#" \
663 -e "s#$dump_dir#DUMP_DIR#g" \
664 -e "s#$restore_dir#RESTORE_DIR#g" \
665 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
666 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
667 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
675 while getopts "f:FL:o" c $*
680 [ -z "$OPTARG" ] && _error "missing argument for -f"
684 [ -z "$OPTARG" ] && _error "missing argument for -L"
685 session_label=$OPTARG
688 dump_args="$dump_args -o"
691 dump_args="$dump_args -F"
694 _error "invalid argument"
708 echo "Dumping to tape..."
709 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
710 echo "xfsdump $opts" | _dir_filter
711 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
715 # Do full level 0 dump
721 echo "Dumping to tape..."
722 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
723 echo "xfsdump $opts" | _dir_filter
724 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
729 # Do full dump with -m
735 echo "Dumping to tape..."
737 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
738 echo "xfsdump $opts" | _dir_filter
739 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
743 # Do level 1 incremental dump
745 _do_dump_incremental()
749 echo "Dumping incrementally to tape..."
750 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
751 echo "xfsdump $opts" | _dir_filter
752 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
756 # Do full dump to file
762 echo "Dumping to file..."
763 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
764 echo "xfsdump $opts" | _dir_filter
765 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
769 _prepare_restore_dir()
772 if ! mkdir $restore_dir; then
773 echo " failed to mkdir $restore_dir"
781 # Get tape ready and restore dir
787 echo "Rewinding tape"
792 # Restore the tape into $restore_dir
800 echo "Restoring from tape..."
801 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
802 echo "xfsrestore $opts" | _dir_filter
803 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
807 # Restore the tape into $restore_dir using -m
814 echo "Restoring from tape..."
816 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
817 echo "xfsrestore $opts" | _dir_filter
818 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
822 # Restore the tape from a dump file
829 echo "Restoring from file..."
830 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
831 echo "xfsrestore $opts" | _dir_filter
832 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
836 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
838 # Use -s as we want to dump and restore to the same xfs partition
844 echo "xfsdump|xfsrestore ..."
845 restore_opts="$_restore_debug - $restore_dir"
846 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
847 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
848 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
849 _dump_filter <$tmp.dump.mlog
853 # Compare dumped subdirectory with restored dir
855 # Thus no contents are compared but permissions, sizes,
856 # owners, etc... are.
861 # verify we got back what we dumped
863 echo "Comparing listing of dump directory with restore directory"
864 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
865 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
866 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
868 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
873 # Compare using recursive diff the files of the dumped
875 # This one will compare the contents.
879 echo "Comparing dump directory with restore directory"
880 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
884 # Compare using recursive diff the files of the dumped
889 echo "Comparing dump directory with restore directory"
890 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
894 # Check out the dump inventory
898 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
902 # Do the xfsinvutil cmd with debug and filters
903 # Need to set variable: "$middate" to the invutil date
908 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
909 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
910 | tee -a $seq.full | _invutil_filter
913 # make sure this script returns success