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."
293 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
296 if ! mkdir $dump_dir; then
297 echo " failed to mkdir $dump_dir"
302 echo "-----------------------------------------------"
303 echo "fsstress : $_param"
304 echo "-----------------------------------------------"
305 if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
307 echo " fsstress (count=$_count) returned $? - see $seq.full"
309 echo "--------------------------------------" >>$here/$seq.full
310 echo "output from fsstress:" >>$here/$seq.full
311 echo "--------------------------------------" >>$here/$seq.full
312 cat $tmp.out >>$here/$seq.full
321 cat <<End-of-File >$tmp.config
322 # pathname size in bytes owner group
324 small 10 $nobody $nobody
325 big 102400 daemon sys
327 sub/big 102400 $nobody sys
329 sub/a 1 $nobody $nobody
330 sub/b 2 $nobody $nobody
331 sub/c 4 $nobody $nobody
332 sub/d 8 $nobody $nobody
333 sub/e 16 $nobody $nobody
334 sub/f 32 $nobody $nobody
335 sub/g 64 $nobody $nobody
336 sub/h 128 $nobody $nobody
337 sub/i 256 $nobody $nobody
338 sub/j 512 $nobody $nobody
339 sub/k 1024 $nobody $nobody
340 sub/l 2048 $nobody $nobody
341 sub/m 4096 $nobody $nobody
342 sub/n 8192 $nobody $nobody
344 sub/a00 100 $nobody $nobody
345 sub/b00 200 $nobody $nobody
346 sub/c00 400 $nobody $nobody
347 sub/d00 800 $nobody $nobody
348 sub/e00 1600 $nobody $nobody
349 sub/f00 3200 $nobody $nobody
350 sub/g00 6400 $nobody $nobody
351 sub/h00 12800 $nobody $nobody
352 sub/i00 25600 $nobody $nobody
353 sub/j00 51200 $nobody $nobody
354 sub/k00 102400 $nobody $nobody
355 sub/l00 204800 $nobody $nobody
356 sub/m00 409600 $nobody $nobody
357 sub/n00 819200 $nobody $nobody
359 sub/a000 1000 $nobody $nobody
360 sub/e000 16000 $nobody $nobody
361 sub/h000 128000 $nobody $nobody
362 sub/k000 1024000 $nobody $nobody
368 cat <<End-of-File >$tmp.config
369 # pathname size in bytes
371 smalll 10 $nobody $nobody
372 biggg 102400 $nobody $nobody
373 sub/smalll 10 $nobody $nobody
374 sub/biggg 102400 $nobody $nobody
378 _mk_fillconfig_perm()
380 cat <<End-of-File >$tmp.config
381 # pathname size/dir user group mode
383 file_suid 10 $nobody $nobody 04777
384 file_guid 10 $nobody $nobody 02777
385 file_sticky 10 $nobody $nobody 01777
386 file_mix1 10 $nobody $nobody 761
387 file_mix2 10 $nobody $nobody 642
388 dir_suid d $nobody $nobody 04777
389 dir_guid d $nobody $nobody 02777
390 dir_sticky d $nobody $nobody 01777
391 dir_mix1 d $nobody $nobody 761
392 dir_mix2 d $nobody $nobody 642
397 # Create a bunch of directories/files of different sizes
400 # Pinched from test 001.
402 _do_create_dumpdir_fill()
404 echo "Creating directory system to dump using src/fill."
406 if mkdir -p $dump_dir
410 echo "Error: cannot mkdir \"$dump_dir\""
415 $verbose && echo -n "Setup "
416 sed -e '/^#/d' $tmp.config \
417 | while read file nbytes owner group perms
419 if [ $nbytes = "d" ]; then
429 echo "Error: cannot mkdir \"$dir\""
434 # create a directory/file
445 echo "Error: cannot mkdir \"$dir\""
451 if $here/src/fill $file $file $nbytes
456 echo "Error: cannot create \"$file\""
460 if [ -n "$owner" -a -n "$group" ]; then
461 chown $owner.$group $file
463 if [ -n "$perms" ]; then
466 $verbose && echo -n "."
474 _create_dumpdir_fill()
479 _do_create_dumpdir_fill
483 _create_dumpdir_fill2()
488 _do_create_dumpdir_fill
492 _create_dumpdir_fill_perm()
497 _do_create_dumpdir_fill
504 # Append a subset of the fill'ed files
505 # So we can see if just these get dumped on an incremental
507 _append_dumpdir_fill()
510 cat <<End-of-File >$tmp.config
520 sed -e '/^#/d' $tmp.config \
523 echo 'Extra text' >>$file
529 _do_create_dump_symlinks()
531 echo "Creating directory system of symlinks to dump."
533 if mkdir -p $dump_dir
537 echo "Error: cannot mkdir \"$dump_dir\""
542 $verbose && echo -n "Setup "
543 sed -e '/^#/d' $tmp.config \
544 | while read file nbytes owner group owner2 group2 perms perms2
556 echo "Error: cannot mkdir \"$dir\""
564 # Do chmod on symlink using umask.
565 # This won't do the right thing as it subtracts permissions.
566 # However, I don't care, as long as I get some different perms
568 if [ -n "$perms2" ]; then
572 ln -s $file $file-link
573 if [ -n "$perms2" ]; then
577 if [ -n "$owner" -a -n "$group" ]; then
578 chown $owner.$group $file
580 if [ -n "$owner" -a -n "$group" ]; then
581 chown -h $owner.$group $file-link
583 if [ -n "$perms" ]; then
586 $verbose && echo -n "."
595 cat <<End-of-File >$tmp.config
596 # path size owner1 group1 owner2 group2 perm1 perm2
598 a 0 $nobody $nobody daemon sys 124 421
599 b 0 daemon sys bin bin 347 743
600 sub/a 0 bin bin $nobody sys 777 777
601 sub/b 0 $nobody sys $nobody $nobody 367 763
605 _create_dumpdir_symlinks()
610 _do_create_dump_symlinks
616 # Filter out dates on symlinks
620 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
622 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
627 # Filter out the non-deterministic dump msgs from
628 # xfsdump and xfsrestore
633 -e "s/`hostname`/HOSTNAME/" \
634 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
635 -e "s#$dumptape#TAPE_DEV#" \
636 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
637 -e "s#$dump_file#DUMP_FILE#" \
638 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
639 -e 's/time:[ ].*/time: TIME/' \
640 -e 's/date:[ ].*/date: DATE/' \
641 -e 's/dump begun .*/dump begun DATE/' \
642 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
643 -e 's/restore.[0-9][0-9]*/restore.PID/' \
644 -e 's/ino [0-9][0-9]*/ino INO/' \
645 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
646 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
647 -e '/media file size/s/[1-9][0-9]*/NUM/' \
648 -e '/mfile size:[ ]*/s/[1-9][0-9]*/NUM/' \
650 -e '/inventory session uuid/d' \
658 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
659 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
660 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
661 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
668 -e "s#$dump_file#DUMP_FILE#" \
669 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
670 -e "s#$dumptape#TAPE_DEV#" \
671 -e "s#$dump_dir#DUMP_DIR#g" \
672 -e "s#$restore_dir#RESTORE_DIR#g" \
673 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
674 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
675 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
683 while getopts "f:FL:o" c $*
688 [ -z "$OPTARG" ] && _error "missing argument for -f"
692 [ -z "$OPTARG" ] && _error "missing argument for -L"
693 session_label=$OPTARG
696 dump_args="$dump_args -o"
699 dump_args="$dump_args -F"
702 _error "invalid argument"
716 echo "Dumping to tape..."
717 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -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 # Do full level 0 dump
729 echo "Dumping to tape..."
730 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
731 echo "xfsdump $opts" | _dir_filter
732 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
737 # Do full dump with -m
743 echo "Dumping to tape..."
745 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
746 echo "xfsdump $opts" | _dir_filter
747 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
751 # Do level 1 incremental dump
753 _do_dump_incremental()
757 echo "Dumping incrementally to tape..."
758 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
759 echo "xfsdump $opts" | _dir_filter
760 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
764 # Do full dump to file
770 echo "Dumping to file..."
771 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
772 echo "xfsdump $opts" | _dir_filter
773 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
777 _prepare_restore_dir()
780 if ! mkdir $restore_dir; then
781 echo " failed to mkdir $restore_dir"
789 # Get tape ready and restore dir
795 echo "Rewinding tape"
800 # Restore the tape into $restore_dir
808 echo "Restoring from tape..."
809 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
810 echo "xfsrestore $opts" | _dir_filter
811 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
815 # Restore the tape into $restore_dir using -m
822 echo "Restoring from tape..."
824 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
825 echo "xfsrestore $opts" | _dir_filter
826 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
830 # Restore the tape from a dump file
837 echo "Restoring from file..."
838 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
839 echo "xfsrestore $opts" | _dir_filter
840 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
844 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
846 # Use -s as we want to dump and restore to the same xfs partition
852 echo "xfsdump|xfsrestore ..."
853 restore_opts="$_restore_debug - $restore_dir"
854 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
855 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
856 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
857 _dump_filter <$tmp.dump.mlog
861 # Compare dumped subdirectory with restored dir
863 # Thus no contents are compared but permissions, sizes,
864 # owners, etc... are.
869 # verify we got back what we dumped
871 echo "Comparing listing of dump directory with restore directory"
872 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
873 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
874 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
876 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
881 # Compare using recursive diff the files of the dumped
883 # This one will compare the contents.
887 echo "Comparing dump directory with restore directory"
888 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
892 # Compare using recursive diff the files of the dumped
897 echo "Comparing dump directory with restore directory"
898 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
902 # Check out the dump inventory
906 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
910 # Do the xfsinvutil cmd with debug and filters
911 # Need to set variable: "$middate" to the invutil date
916 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
917 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
918 | tee -a $seq.full | _invutil_filter
921 # make sure this script returns success