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"
101 while [ $i -lt $_limit ]; do
102 echo "Checking online..." >>$seq.full
103 if _mt status >$tmp.status 2>&1; then
112 if [ $i -eq $_limit ]; then
113 echo "ERROR: mt -f $dumptape failed"
116 echo "mt -f $dumptape failed" >$seq.notrun
122 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
125 echo "ERROR: $dumptape is not online"
128 echo "dumptape, $dumptape, is not online" >$seq.notrun
136 echo "Wait for tape, $dumptape, ..." >>$seq.full
139 while [ $i -lt 20 ]; do
140 echo "Checking status..." >>$seq.full
141 if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
151 # Keep trying so we know we really have rewound
155 echo "Initiate rewind..." >>$seq.full
157 _mt rewind >/dev/null
162 # Do a custom erase because:
163 # (i) some machines don't support it
164 # (ii) some machines take forever to do it
168 echo "Erasing tape" | tee -a $seq.full
176 echo "Erasing tape" | tee -a $seq.full
182 echo $dumptape | grep ':' >/dev/null
194 echo "Put scsi tape driver into variable block size mode"
195 mt -f $dumptape setblk 0
203 if [ -z "$dumptape" ]; then
204 echo "This test requires a dump tape - none was specified"
205 echo "No dump tape specified" >$seq.notrun
216 echo "Error: $*" | tee -a $seq.full
217 echo "(see $seq.full for details)"
226 mkfs -t xfs -f $SCRATCH_DEV >>$seq.full ||\
229 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
230 _error "mount failed"
234 # Cleanup created dirs and files
242 if [ -n "$DEBUGDUMP" ]; then
243 # save it for inspection
244 tar -zcvf $seq.inventory.tgz /var/xfsdump/inventory
245 ls -lR /var/xfsdump/inventory >$seq.inventory.ls
248 # put inventory dir back
249 if [ -d /var/xfsdump/inventory.$seq ]; then
250 rm -rf /var/xfsdump/inventory # get rid of new one
251 mv /var/xfsdump/inventory.$seq /var/xfsdump/inventory
254 if [ $status -ne $NOTRUNSTS ]; then
255 # Sleep added to stop _check_fs from complaining that the
256 # scratch_dev is still busy
259 _check_fs $SCRATCH_DEV
265 # umount $SCRATCH_MNT >/dev/null
266 # mount $SCRATCH_MNT >/dev/null
271 # Run src/fsstress to create a mixture of
272 # files,dirs,links,symlinks
274 # Pinched from test 013.
276 _create_dumpdir_stress()
278 echo "Creating directory system to dump using src/fsstress."
282 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
285 if ! mkdir $dump_dir; then
286 echo " failed to mkdir $dump_dir"
291 echo "-----------------------------------------------"
292 echo "fsstress : $_param"
293 echo "-----------------------------------------------"
294 if ! $here/src/fsstress $_param $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
296 echo " fsstress (count=$_count) returned $? - see $seq.full"
298 echo "--------------------------------------" >>$here/$seq.full
299 echo "output from fsstress:" >>$here/$seq.full
300 echo "--------------------------------------" >>$here/$seq.full
301 cat $tmp.out >>$here/$seq.full
310 cat <<End-of-File >$tmp.config
311 # pathname size in bytes owner group
313 small 10 $nobody $nobody
314 big 102400 daemon sys
316 sub/big 102400 $nobody sys
318 sub/a 1 $nobody $nobody
319 sub/b 2 $nobody $nobody
320 sub/c 4 $nobody $nobody
321 sub/d 8 $nobody $nobody
322 sub/e 16 $nobody $nobody
323 sub/f 32 $nobody $nobody
324 sub/g 64 $nobody $nobody
325 sub/h 128 $nobody $nobody
326 sub/i 256 $nobody $nobody
327 sub/j 512 $nobody $nobody
328 sub/k 1024 $nobody $nobody
329 sub/l 2048 $nobody $nobody
330 sub/m 4096 $nobody $nobody
331 sub/n 8192 $nobody $nobody
333 sub/a00 100 $nobody $nobody
334 sub/b00 200 $nobody $nobody
335 sub/c00 400 $nobody $nobody
336 sub/d00 800 $nobody $nobody
337 sub/e00 1600 $nobody $nobody
338 sub/f00 3200 $nobody $nobody
339 sub/g00 6400 $nobody $nobody
340 sub/h00 12800 $nobody $nobody
341 sub/i00 25600 $nobody $nobody
342 sub/j00 51200 $nobody $nobody
343 sub/k00 102400 $nobody $nobody
344 sub/l00 204800 $nobody $nobody
345 sub/m00 409600 $nobody $nobody
346 sub/n00 819200 $nobody $nobody
348 sub/a000 1000 $nobody $nobody
349 sub/e000 16000 $nobody $nobody
350 sub/h000 128000 $nobody $nobody
351 sub/k000 1024000 $nobody $nobody
357 cat <<End-of-File >$tmp.config
358 # pathname size in bytes
360 smalll 10 $nobody $nobody
361 biggg 102400 $nobody $nobody
362 sub/smalll 10 $nobody $nobody
363 sub/biggg 102400 $nobody $nobody
368 # Create a bunch of directories/files of different sizes
371 # Pinched from test 001.
373 _do_create_dumpdir_fill()
375 echo "Creating directory system to dump using src/fill."
377 if mkdir -p $dump_dir
381 echo "Error: cannot mkdir \"$dump_dir\""
386 $verbose && echo -n "Setup "
387 sed -e '/^#/d' $tmp.config \
388 | while read file nbytes owner group perms
400 echo "Error: cannot mkdir \"$dir\""
406 if $here/src/fill $file $file $nbytes
411 echo "Error: cannot create \"$file\""
414 if [ -n "$owner" -a -n "$group" ]; then
415 chown $owner.$group $file
417 if [ -n "$perms" ]; then
420 $verbose && echo -n "."
428 _create_dumpdir_fill()
432 _do_create_dumpdir_fill
436 _create_dumpdir_fill2()
440 _do_create_dumpdir_fill
447 # Append a subset of the fill'ed files
448 # So we can see if just these get dumped on an incremental
450 _append_dumpdir_fill()
453 cat <<End-of-File >$tmp.config
463 sed -e '/^#/d' $tmp.config \
466 echo 'Extra text' >>$file
472 _do_create_dump_symlinks()
474 echo "Creating directory system of symlinks to dump."
476 if mkdir -p $dump_dir
480 echo "Error: cannot mkdir \"$dump_dir\""
485 $verbose && echo -n "Setup "
486 sed -e '/^#/d' $tmp.config \
487 | while read file nbytes owner group owner2 group2 perms perms2
499 echo "Error: cannot mkdir \"$dir\""
507 # Do chmod on symlink using umask.
508 # This won't do the right thing as it subtracts permissions.
509 # However, I don't care, as long as I get some different perms
511 if [ -n "$perms2" ]; then
515 ln -s $file $file-link
516 if [ -n "$perms2" ]; then
520 if [ -n "$owner" -a -n "$group" ]; then
521 chown $owner.$group $file
523 if [ -n "$owner" -a -n "$group" ]; then
524 chown -h $owner.$group $file-link
526 if [ -n "$perms" ]; then
529 $verbose && echo -n "."
538 cat <<End-of-File >$tmp.config
539 # path size owner1 group1 owner2 group2 perm1 perm2
541 a 0 $nobody $nobody daemon sys 124 421
542 b 0 daemon sys bin bin 347 743
543 sub/a 0 bin bin $nobody sys 777 777
544 sub/b 0 $nobody sys $nobody $nobody 367 763
548 _create_dumpdir_symlinks()
552 _do_create_dump_symlinks
558 # Filter out dates on symlinks
562 $AWK_PROG '/^l/ { date = $8; sub(date,"DATE"); print}
564 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
569 # Filter out the non-deterministic dump msgs from
570 # xfsdump and xfsrestore
575 -e "s/`hostname`/HOSTNAME/" \
576 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
577 -e "s#$dumptape#TAPE_DEV#" \
578 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
579 -e "s#$dump_file#DUMP_FILE#" \
580 -e 's/id:[ ]*[0-9a-f-]*/id: ID/' \
581 -e 's/time:[ ].*/time: TIME/' \
582 -e 's/date:[ ].*/date: DATE/' \
583 -e 's/dump begun .*/dump begun DATE/' \
584 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
585 -e '/: dump size/s/[1-9][0-9]*/NUM/' \
586 -e '/dump size:/s/[1-9][0-9]*/NUM/' \
587 -e '/media file size/s/[1-9][0-9]*/NUM/' \
589 -e '/inventory session uuid/d' \
597 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
598 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
599 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
600 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
607 -e "s#$dump_file#DUMP_FILE#" \
608 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
609 -e "s#$dumptape#TAPE_DEV#" \
610 -e "s#$dump_dir#DUMP_DIR#g" \
611 -e "s#$restore_dir#RESTORE_DIR#g" \
612 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
613 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
614 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
622 while getopts "f:FL:o" c $*
627 [ -z "$OPTARG" ] && _error "missing argument for -f"
631 [ -z "$OPTARG" ] && _error "missing argument for -L"
632 session_label=$OPTARG
635 dump_args="$dump_args -o"
638 dump_args="$dump_args -F"
641 _error "invalid argument"
655 echo "Dumping to tape..."
656 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
657 echo "xfsdump $opts" | _dir_filter
658 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
662 # Do full level 0 dump
668 echo "Dumping to tape..."
669 opts="$_dump_debug$dump_args -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
670 echo "xfsdump $opts" | _dir_filter
671 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
676 # Do full dump with -m
682 echo "Dumping to tape..."
684 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
685 echo "xfsdump $opts" | _dir_filter
686 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
690 # Do level 1 incremental dump
692 _do_dump_incremental()
696 echo "Dumping incrementally to tape..."
697 opts="$_dump_debug$dump_args -l1 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
698 echo "xfsdump $opts" | _dir_filter
699 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
703 # Do full dump to file
709 echo "Dumping to file..."
710 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
711 echo "xfsdump $opts" | _dir_filter
712 xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
716 _prepare_restore_dir()
719 if ! mkdir $restore_dir; then
720 echo " failed to mkdir $restore_dir"
728 # Get tape ready and restore dir
734 echo "Rewinding tape"
739 # Restore the tape into $restore_dir
747 echo "Restoring from tape..."
748 opts="$_restore_debug$dump_args -f $dumptape -L $session_label $restore_dir"
749 echo "xfsrestore $opts" | _dir_filter
750 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
754 # Restore the tape into $restore_dir using -m
761 echo "Restoring from tape..."
763 opts="$_restore_debug$dump_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
764 echo "xfsrestore $opts" | _dir_filter
765 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
769 # Restore the tape from a dump file
776 echo "Restoring from file..."
777 opts="$_restore_debug$dumpargs -f $dump_file -L $session_label $restore_dir"
778 echo "xfsrestore $opts" | _dir_filter
779 xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
783 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
785 # Use -s as we want to dump and restore to the same xfs partition
791 echo "xfsdump|xfsrestore ..."
792 restore_opts="$_restore_debug - $restore_dir"
793 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
794 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
795 xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
796 _dump_filter <$tmp.dump.mlog
800 # Compare dumped subdirectory with restored dir
802 # Thus no contents are compared but permissions, sizes,
803 # owners, etc... are.
808 # verify we got back what we dumped
810 echo "Comparing listing of dump directory with restore directory"
811 ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
812 ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
813 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
815 diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
820 # Compare using recursive diff the files of the dumped
822 # This one will compare the contents.
826 echo "Comparing dump directory with restore directory"
827 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
831 # Compare using recursive diff the files of the dumped
836 echo "Comparing dump directory with restore directory"
837 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter
841 # Check out the dump inventory
845 xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter
849 # Do the xfsinvutil cmd with debug and filters
850 # Need to set variable: "$middate" to the invutil date
855 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
856 xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT "$middate" $* \
857 | tee -a $seq.full | _invutil_filter
860 # make sure this script returns success