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_file=$tmp.dumpfile
58 dump_dir=$SCRATCH_MNT/$dump_sdir
59 restore_sdir=restoredir
60 restore_dir=$SCRATCH_MNT/$restore_sdir
63 media_label="stress_tape_media"
64 session_label="stress_$seq"
66 nobody=4 # define this uid/gid as a number
67 do_quota_check=true # do quota check if quotas enabled
72 trap "_cleanup; exit \$status" 0 1 2 3 15
74 # start inventory from a known base - move it aside for test
75 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
77 [ -d $dir.$seq ] && rm -rf $dir.$seq
84 # do a remote/local mt
91 _rmtdev=`echo $dumptape | $AWK_PROG -F: '{print $2}'`
93 if echo $dumptape | grep '@' >/dev/null; then
94 _spec=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
95 _rmtuser=`echo $_spec | $AWK_PROG -F@ '{print $1}'`
96 _rmthost=`echo $_spec | $AWK_PROG -F@ '{print $2}'`
97 rsh -n -l $_rmtuser $_rmthost "mt -t $_rmtdev $op"
99 _rmthost=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
100 rsh -n $_rmthost "mt -t $_rmtdev $op"
112 while [ $i -lt $_limit ]; do
113 echo "Checking online..." >>$seq.full
114 if _mt status >$tmp.status 2>&1; then
123 if [ $i -eq $_limit ]; then
124 echo "ERROR: mt -f $dumptape failed"
127 echo "mt -f $dumptape failed" >$seq.notrun
133 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
136 echo "ERROR: $dumptape is not online"
139 echo "dumptape, $dumptape, is not online" >$seq.notrun
147 echo "Wait for tape, $dumptape, ..." >>$seq.full
150 while [ $i -lt 20 ]; do
151 echo "Checking status..." >>$seq.full
152 if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
162 # Keep trying so we know we really have rewound
166 echo "Initiate rewind..." >>$seq.full
168 _mt rewind >/dev/null
173 # Do a custom erase because:
174 # (i) some machines don't support it
175 # (ii) some machines take forever to do it
179 echo "Erasing tape" | tee -a $seq.full
187 echo "Erasing tape" | tee -a $seq.full
193 echo $dumptape | grep ':' >/dev/null
205 echo "Put scsi tape driver into variable block size mode"
206 mt -f $dumptape setblk 0
214 if [ -z "$dumptape" ]; then
215 echo "This test requires a dump tape - none was specified"
216 echo "No dump tape specified" >$seq.notrun
227 echo "Error: $*" | tee -a $seq.full
228 echo "(see $seq.full for details)"
237 mkfs -t xfs -f $SCRATCH_DEV >>$seq.full ||\
240 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
241 _error "mount failed"
245 # Cleanup created dirs and files
253 if [ -n "$DEBUGDUMP" ]; then
254 # save it for inspection
255 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
256 [ -d $dir ] || continue
257 tar -zcvf $seq.inventory.tgz $dir
258 ls -lR $dir >$seq.inventory.ls
262 # put inventory dir back
263 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
264 [ -d $dir.$seq ] || continue
265 rm -rf $dir # get rid of new one
269 if [ $status -ne $NOTRUNSTS ]; then
270 # Sleep added to stop _check_fs from complaining that the
271 # scratch_dev is still busy
274 _check_fs $SCRATCH_DEV
280 umount $SCRATCH_MNT >>$seq.full ||\
281 _error "unmount failed"
282 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
283 _error "mount failed"
287 # Run src/fsstress to create a mixture of
288 # files,dirs,links,symlinks
290 # Pinched from test 013.
292 _create_dumpdir_stress()
294 echo "Creating directory system to dump using src/fsstress."
298 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
301 if ! mkdir $dump_dir; then
302 echo " failed to mkdir $dump_dir"
307 echo "-----------------------------------------------"
308 echo "fsstress : $_param"
309 echo "-----------------------------------------------"
310 if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
312 echo " fsstress (count=$_count) returned $? - see $seq.full"
314 echo "--------------------------------------" >>$here/$seq.full
315 echo "output from fsstress:" >>$here/$seq.full
316 echo "--------------------------------------" >>$here/$seq.full
317 cat $tmp.out >>$here/$seq.full
326 cat <<End-of-File >$tmp.config
327 # pathname size in bytes owner group
329 small 10 $nobody $nobody
330 big 102400 daemon sys
332 sub/big 102400 $nobody sys
334 sub/a 1 $nobody $nobody
335 sub/b 2 $nobody $nobody
336 sub/c 4 $nobody $nobody
337 sub/d 8 $nobody $nobody
338 sub/e 16 $nobody $nobody
339 sub/f 32 $nobody $nobody
340 sub/g 64 $nobody $nobody
341 sub/h 128 $nobody $nobody
342 sub/i 256 $nobody $nobody
343 sub/j 512 $nobody $nobody
344 sub/k 1024 $nobody $nobody
345 sub/l 2048 $nobody $nobody
346 sub/m 4096 $nobody $nobody
347 sub/n 8192 $nobody $nobody
349 sub/a00 100 $nobody $nobody
350 sub/b00 200 $nobody $nobody
351 sub/c00 400 $nobody $nobody
352 sub/d00 800 $nobody $nobody
353 sub/e00 1600 $nobody $nobody
354 sub/f00 3200 $nobody $nobody
355 sub/g00 6400 $nobody $nobody
356 sub/h00 12800 $nobody $nobody
357 sub/i00 25600 $nobody $nobody
358 sub/j00 51200 $nobody $nobody
359 sub/k00 102400 $nobody $nobody
360 sub/l00 204800 $nobody $nobody
361 sub/m00 409600 $nobody $nobody
362 sub/n00 819200 $nobody $nobody
364 sub/a000 1000 $nobody $nobody
365 sub/e000 16000 $nobody $nobody
366 sub/h000 128000 $nobody $nobody
367 sub/k000 1024000 $nobody $nobody
373 cat <<End-of-File >$tmp.config
374 # pathname size in bytes
376 smalll 10 $nobody $nobody
377 biggg 102400 $nobody $nobody
378 sub/smalll 10 $nobody $nobody
379 sub/biggg 102400 $nobody $nobody
383 _mk_fillconfig_perm()
385 # dir_guid: ugo=rwx,g+s on dir is for IRIX chmod(1)
387 cat <<End-of-File >$tmp.config
388 # pathname size/dir user group mode
390 file_suid 10 $nobody $nobody 04777
391 file_guid 10 $nobody $nobody 02777
392 file_sticky 10 $nobody $nobody 01777
393 file_mix1 10 $nobody $nobody 761
394 file_mix2 10 $nobody $nobody 642
395 dir_suid d $nobody $nobody 04777
396 dir_guid d $nobody $nobody ugo=rwx,g+s
397 dir_sticky d $nobody $nobody 01777
398 dir_mix1 d $nobody $nobody 761
399 dir_mix2 d $nobody $nobody 642
404 # Create a bunch of directories/files of different sizes
407 # Pinched from test 001.
409 _do_create_dumpdir_fill()
411 echo "Creating directory system to dump using src/fill."
413 if mkdir -p $dump_dir
417 echo "Error: cannot mkdir \"$dump_dir\""
422 $verbose && echo -n "Setup "
423 sed -e '/^#/d' $tmp.config \
424 | while read file nbytes owner group perms
426 if [ $nbytes = "d" ]; then
436 echo "Error: cannot mkdir \"$dir\""
441 # create a directory/file
452 echo "Error: cannot mkdir \"$dir\""
458 if $here/src/fill $file $file $nbytes
463 echo "Error: cannot create \"$file\""
467 if [ -n "$owner" -a -n "$group" ]; then
468 chown $owner.$group $file
470 if [ -n "$perms" ]; then
473 $verbose && echo -n "."
481 _create_dumpdir_fill()
485 _do_create_dumpdir_fill
489 _create_dumpdir_fill2()
493 _do_create_dumpdir_fill
497 _create_dumpdir_fill_perm()
501 _do_create_dumpdir_fill
508 # Append a subset of the fill'ed files
509 # So we can see if just these get dumped on an incremental
511 _append_dumpdir_fill()
514 cat <<End-of-File >$tmp.config
524 sed -e '/^#/d' $tmp.config \
527 echo 'Extra text' >>$file
534 _do_create_dump_symlinks()
536 echo "Creating directory system of symlinks to dump."
538 if mkdir -p $dump_dir
542 echo "Error: cannot mkdir \"$dump_dir\""
547 $verbose && echo -n "Setup "
548 sed -e '/^#/d' $tmp.config \
549 | while read file nbytes owner group owner2 group2 perms perms2
561 echo "Error: cannot mkdir \"$dir\""
569 # Do chmod on symlink using umask.
570 # This won't do the right thing as it subtracts permissions.
571 # However, I don't care, as long as I get some different perms
573 if [ -n "$perms2" ]; then
577 ln -s $file $file-link
578 if [ -n "$perms2" ]; then
582 if [ -n "$owner" -a -n "$group" ]; then
583 chown $owner.$group $file
585 if [ -n "$owner" -a -n "$group" ]; then
586 chown -h $owner.$group $file-link
588 if [ -n "$perms" ]; then
591 $verbose && echo -n "."
600 cat <<End-of-File >$tmp.config
601 # path size owner1 group1 owner2 group2 perm1 perm2
603 a 0 $nobody $nobody daemon sys 124 421
604 b 0 daemon sys bin bin 347 743
605 sub/a 0 bin bin $nobody sys 777 777
606 sub/b 0 $nobody sys $nobody $nobody 367 763
610 _create_dumpdir_symlinks()
614 _do_create_dump_symlinks
620 # Filter out dates on symlinks
624 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
626 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
631 # Filter out the non-deterministic dump msgs from
632 # xfsdump and xfsrestore
637 -e "s/`hostname`/HOSTNAME/" \
638 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
639 -e "s#$dumptape#TAPE_DEV#" \
640 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
641 -e "s#$dump_file#DUMP_FILE#" \
642 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
643 -e 's/time:[ ].*/time: TIME/' \
644 -e 's/date:[ ].*/date: DATE/' \
645 -e 's/dump begun .*/dump begun DATE/' \
646 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
647 -e 's/ino [0-9][0-9]*/ino INO/' \
648 -e '/: dump size/s/[0-9][0-9]*/NUM/' \
649 -e '/dump size:/s/[0-9][0-9]*/NUM/' \
650 -e '/media file size/s/[0-9][0-9]*/NUM/' \
651 -e '/mfile size:[ ]*/s/[0-9][0-9]*/NUM/' \
653 -e '/inventory session uuid/d' \
654 -e 's#/var/lib/xfsdump#/var/xfsdump#' \
662 _dump_filter_main | _check_quota_dumprestore
672 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
673 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
674 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
675 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
682 -e "s#$dump_file#DUMP_FILE#" \
683 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
684 -e "s#$dumptape#TAPE_DEV#" \
685 -e "s#$dump_dir#DUMP_DIR#g" \
686 -e "s#$restore_dir#RESTORE_DIR#g" \
687 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
688 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
689 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
697 while getopts "f:FL:oqQ" c $*
702 [ -z "$OPTARG" ] && _error "missing argument for -f"
706 [ -z "$OPTARG" ] && _error "missing argument for -L"
707 session_label=$OPTARG
710 dump_args="$dump_args -o"
713 dump_args="$dump_args -F"
722 _error "invalid argument"
736 echo "Dumping to tape..."
737 opts="$_dump_debug$dump_args -s $dump_sdir -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 full level 0 dump
749 echo "Dumping to tape..."
750 opts="$_dump_debug$dump_args -l0 -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
757 # Do full dump with -m
763 echo "Dumping to tape..."
765 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
766 echo "xfsdump $opts" | _dir_filter
767 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
771 # Do level 1 incremental dump
773 _do_dump_incremental()
777 echo "Dumping incrementally to tape..."
778 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
779 echo "xfsdump $opts" | _dir_filter
780 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
784 # Do full dump to file
790 echo "Dumping to file..."
791 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
792 echo "xfsdump $opts" | _dir_filter
793 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
797 _prepare_restore_dir()
800 if ! mkdir $restore_dir; then
801 echo " failed to mkdir $restore_dir"
809 # Get tape ready and restore dir
815 echo "Rewinding tape"
820 # Restore the tape into $restore_dir
828 echo "Restoring from tape..."
829 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
830 echo "xfsrestore $opts" | _dir_filter
831 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
835 # Restore the tape into $restore_dir using -m
842 echo "Restoring from tape..."
844 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
845 echo "xfsrestore $opts" | _dir_filter
846 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
850 # Restore the tape from a dump file
857 echo "Restoring from file..."
858 opts="$_restore_debug$dump_args -f $dump_file -L $session_label $restore_dir"
859 echo "xfsrestore $opts" | _dir_filter
860 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
864 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
866 # Use -s as we want to dump and restore to the same xfs partition
872 echo "xfsdump|xfsrestore ..."
873 restore_opts="$_restore_debug - $restore_dir"
874 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
875 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
876 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
877 _dump_filter <$tmp.dump.mlog
881 # Compare dumped subdirectory with restored dir
883 # Thus no contents are compared but permissions, sizes,
884 # owners, etc... are.
889 # verify we got back what we dumped
891 echo "Comparing listing of dump directory with restore directory"
892 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
893 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
894 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
896 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
900 # filter out the date fields
904 $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
908 # _ls_compare_sub but don't compare dates
909 _ls_nodate_compare_sub()
912 # verify we got back what we dumped
914 echo "Comparing listing of dump directory with restore directory"
915 ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
916 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
917 | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
919 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
924 # Compare using recursive diff the files of the dumped
926 # This one will compare the contents.
930 echo "Comparing dump directory with restore directory"
931 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
935 # Compare using recursive diff the files of the dumped
940 echo "Comparing dump directory with restore directory"
941 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter | _check_quota_diff
945 # Check out the dump inventory
949 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter_main
953 # Do the xfsinvutil cmd with debug and filters
954 # Need to set variable: "$middate" to the invutil date
959 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
960 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
961 | tee -a $seq.full | _invutil_filter
966 # xfsdump: saving user quota information for: SCRATCH_MNT
967 # xfsdump: saving group quota information for: SCRATCH_MNT
968 # xfsrestore: user quota information written to ...'
969 # xfsrestore: group quota information written to ...'
971 _check_quota_dumprestore()
975 src/feature -U $SCRATCH_DEV && uquota=1
976 src/feature -G $SCRATCH_DEV && gquota=1
978 $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v full=$seq.full '
979 /user quota information/ {
980 print "Found user quota:", $0 >>full
983 print "Found extra:", $0
987 /group quota information/ {
988 print "Found group quota:", $0 >>full
991 print "Found extra:", $0
997 if (uquota && !found_uquota) {
998 print "Missing saving/restoring uquota msg"
1000 if (gquota && !found_gquota) {
1001 print "Missing saving/restoring gquota msg"
1009 # Only in RESTORE_DIR: xfsdump_quotas
1010 # Only in RESTORE_DIR: xfsdump_quotas_group
1017 src/feature -U $SCRATCH_DEV && uquota=1
1018 src/feature -G $SCRATCH_DEV && gquota=1
1020 $AWK_PROG -v uquota=$uquota -v gquota=$gquota '
1021 /Only in RESTORE_DIR: xfsdump_quotas_group/ {
1024 print "Found extra:", $0
1028 /Only in RESTORE_DIR: xfsdump_quotas/ {
1031 print "Found extra:", $0
1037 if (uquota && !found_uquota) {
1038 print "Missing xfsdump_quotas msg"
1040 if (gquota && !found_gquota) {
1041 print "Missing xfsdump_quotas_group msg"
1047 # make sure this script returns success