2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. All Rights Reserved.
5 # Functions useful for xfsdump/xfsrestore tests
7 # --- initializations ---
10 if [ -n "$DEBUGDUMP" ]; then
15 # Use dump/restore in qa directory (copy them here) for debugging
16 export PATH="$here:$PATH"
17 export __XFSDUMP_PROG=$(type -P xfsdump)
18 export XFSDUMP_PROG="$__XFSDUMP_PROG -e"
19 export XFSRESTORE_PROG=$(type -P xfsrestore)
20 export XFSINVUTIL_PROG=$(type -P xfsinvutil)
21 [ -x $here/xfsdump ] && echo "Using xfstests' xfsdump for debug"
22 [ -x $here/xfsrestore ] && echo "Using xfstests' xfsrestore for debug"
23 [ -x $here/xfsinvutil ] && echo "Using xfstests' xfsinvutil for debug"
26 [ "$XFSDUMP_PROG" = "" ] && _notrun "xfsdump not found"
27 [ "$XFSRESTORE_PROG" = "" ] && _notrun "xfsrestore not found"
28 [ "$XFSINVUTIL_PROG" = "" ] && _notrun "xfsinvutil not found"
30 # status returned for not run tests
33 # name those directories
34 dump_file=$tmp.dumpfile
35 # dump_file=$here/dumpfile #TEMP OVERRIDE DUMP FILE
37 dump_dir=$SCRATCH_MNT/$dump_sdir
38 restore_sdir=restoredir
39 restore_dir=$SCRATCH_MNT/$restore_sdir
42 media_label="stress_tape_media"
43 session_label="stress_$seq"
45 nobody=4 # define this uid/gid as a number
46 do_quota_check=true # do quota check if quotas enabled
49 trap "_cleanup; exit \$status" 0 1 2 3 15
51 # start inventory from a known base - move it aside for test
52 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
54 [ -d $dir.$seq ] && rm -rf $dir.$seq
60 [ `uname` = "Linux" ] && have_mtvariable=true
63 _require_multi_stream()
65 $XFSDUMP_PROG -JF -f /dev/null -f /dev/null 2> /dev/null |
66 grep -q "too many -f arguments" &&
67 _notrun "xfsdump multi-stream support required"
70 _require_legacy_v2_format()
73 grep -q "generate format 2 dump" ||
74 _notrun "xfsdump -K option required"
76 $XFSRESTORE_PROG 2>&1 |
77 grep -q "force use of format 2 generation" ||
78 _notrun "xfsrestore -K option required"
82 # do a remote/local mt
89 _rmtdev=`echo $dumptape | $AWK_PROG -F: '{print $2}'`
91 if echo $dumptape | grep '@' >/dev/null; then
92 _spec=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
93 _rmtuser=`echo $_spec | $AWK_PROG -F@ '{print $1}'`
94 _rmthost=`echo $_spec | $AWK_PROG -F@ '{print $2}'`
95 rsh -n -l $_rmtuser $_rmthost "mt -t $_rmtdev $op"
97 _rmthost=`echo $dumptape | $AWK_PROG -F: '{print $1}'`
98 rsh -n $_rmthost "mt -t $_rmtdev $op"
110 while [ $i -lt $_limit ]; do
111 echo "Checking online..." >>$seqres.full
112 if _mt status >$tmp.status 2>&1; then
121 if [ $i -eq $_limit ]; then
122 echo "ERROR: mt -f $dumptape failed"
125 _notrun "mt -f $dumptape failed"
129 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
132 echo "ERROR: $dumptape is not online"
135 _notrun "dumptape, $dumptape, is not online"
141 echo "Wait for tape, $dumptape, ..." >>$seqres.full
144 while [ $i -lt 20 ]; do
145 echo "Checking status..." >>$seqres.full
146 if _mt status 2>&1 | tee -a $seqres.full | egrep -i "onl|ready" >/dev/null; then
156 # Keep trying so we know we really have rewound
160 echo "Initiate rewind..." >>$seqres.full
162 _mt rewind >/dev/null
167 # Do a custom erase because:
168 # (i) some machines don't support it
169 # (ii) some machines take forever to do it
173 echo "Erasing tape" | tee -a $seqres.full
181 echo "Erasing tape" | tee -a $seqres.full
187 echo $dumptape | grep ':' >/dev/null
195 $have_mtvariable || return
201 echo "Put scsi tape driver into variable block size mode"
202 mt -f $dumptape setblk 0
210 if [ -z "$dumptape" -o "@" == "$dumptape" ]; then
211 _notrun "No dump tape specified"
222 _scratch_mkfs_xfs >>$seqres.full || _fail "mkfs failed"
223 _scratch_mount >>$seqres.full
227 # Cleanup created dirs and files
232 # Some tests include this before checking _supported_fs xfs
233 # and the sleeps & checks here get annoying
234 if [ "$FSTYP" != "xfs" ]; then
241 if [ -n "$DEBUGDUMP" ]; then
242 # save it for inspection
243 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
244 [ -d $dir ] || continue
245 tar -cvf $seqres.inventory.tar $dir
246 ls -nR $dir >$seqres.inventory.ls
250 # put inventory dir back
251 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
252 [ -d $dir.$seq ] || continue
253 rm -rf $dir # get rid of new one
257 if [ $status -ne $NOTRUNSTS ]; then
258 # Sleep added to stop _check_scratch_fs from complaining that the
259 # scratch_dev is still busy
267 # ensure that bulkstat data will
268 # match with incore data
269 # by forcing disk data to be written out
273 _saveddir=`pwd`; cd /
274 _scratch_unmount >>$seqres.full || _fail "unmount failed"
275 _scratch_mount >>$seqres.full
280 # Run fsstress to create a mixture of
281 # files,dirs,links,symlinks
283 # Pinched from test 013.
284 # Takes one argument, the number of ops to perform
286 _create_dumpdir_stress_num()
288 echo "Creating directory system to dump using fsstress."
293 _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 # Remove fsstress commands that aren't supported on all xfs configs so that
302 # we always execute exactly the same sequence of operations no matter how
303 # the filesystem is configured
304 if $FSSTRESS_PROG | grep -q clonerange; then
305 FSSTRESS_AVOID="-f clonerange=0 $FSSTRESS_AVOID"
307 if $FSSTRESS_PROG | grep -q deduperange; then
308 FSSTRESS_AVOID="-f deduperange=0 $FSSTRESS_AVOID"
312 echo "-----------------------------------------------"
313 echo "fsstress : $_param"
314 echo "-----------------------------------------------"
315 if ! $here/ltp/fsstress $_param -s 1 $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
317 echo " fsstress (count=$_count) returned $? - see $seqres.full"
319 echo "--------------------------------------" >>$seqres.full
320 echo "output from fsstress:" >>$seqres.full
321 echo "--------------------------------------" >>$seqres.full
322 cat $tmp.out >>$seqres.full
329 _create_dumpdir_stress() {
330 _create_dumpdir_stress_num 240
335 cat <<End-of-File >$tmp.config
336 # pathname size in bytes owner group
338 small 10 $nobody $nobody
339 big 102400 daemon sys
341 sub/big 102400 $nobody sys
343 sub/a 1 $nobody $nobody
344 sub/b 2 $nobody $nobody
345 sub/c 4 $nobody $nobody
346 sub/d 8 $nobody $nobody
347 sub/e 16 $nobody $nobody
348 sub/f 32 $nobody $nobody
349 sub/g 64 $nobody $nobody
350 sub/h 128 $nobody $nobody
351 sub/i 256 $nobody $nobody
352 sub/j 512 $nobody $nobody
353 sub/k 1024 $nobody $nobody
354 sub/l 2048 $nobody $nobody
355 sub/m 4096 $nobody $nobody
356 sub/n 8192 $nobody $nobody
358 sub/a00 100 $nobody $nobody
359 sub/b00 200 $nobody $nobody
360 sub/c00 400 $nobody $nobody
361 sub/d00 800 $nobody $nobody
362 sub/e00 1600 $nobody $nobody
363 sub/f00 3200 $nobody $nobody
364 sub/g00 6400 $nobody $nobody
365 sub/h00 12800 $nobody $nobody
366 sub/i00 25600 $nobody $nobody
367 sub/j00 51200 $nobody $nobody
368 sub/k00 102400 $nobody $nobody
369 sub/l00 204800 $nobody $nobody
370 sub/m00 409600 $nobody $nobody
371 sub/n00 819200 $nobody $nobody
373 sub/a000 1000 $nobody $nobody
374 sub/e000 16000 $nobody $nobody
375 sub/h000 128000 $nobody $nobody
376 sub/k000 1024000 $nobody $nobody
382 cat <<End-of-File >$tmp.config
383 # pathname size in bytes
385 smalll 10 $nobody $nobody
386 biggg 102400 $nobody $nobody
387 sub/smalll 10 $nobody $nobody
388 sub/biggg 102400 $nobody $nobody
392 _mk_fillconfig_perm()
394 cat <<End-of-File >$tmp.config
395 # pathname size/dir user group mode
397 file_suid 10 $nobody $nobody 04777
398 file_guid 10 $nobody $nobody 02777
399 file_sticky 10 $nobody $nobody 01777
400 file_mix1 10 $nobody $nobody 761
401 file_mix2 10 $nobody $nobody 642
402 dir_suid d $nobody $nobody 04777
403 dir_guid d $nobody $nobody 02777
404 dir_sticky d $nobody $nobody 01777
405 dir_mix1 d $nobody $nobody 761
406 dir_mix2 d $nobody $nobody 642
412 cat <<End-of-File >$tmp.config
413 # pathname size user group perm name value namespace
415 smalll 10 $nobody $nobody 777 attr1 some_text user
416 biggg 102400 $nobody $nobody 777 attr2 some_text2 root
417 sub/smalll 10 $nobody $nobody 777 attr3 some_text3 user
418 sub/biggg 102400 $nobody $nobody 777 attr4 some_text4 root
419 dir d $nobody $nobody 777 attr5 dir_text user
421 # Add more files so that there are more than the number
423 # There are bugs in dump/restore for # non-dir files < # streams
424 # It can be tested in another configuration.
425 # It is a pathalogical case.
427 sub/a 1 $nobody $nobody
428 sub/b 2 $nobody $nobody
429 sub/c 4 $nobody $nobody
430 sub/d 8 $nobody $nobody
431 sub/e 16 $nobody $nobody
432 sub/f 32 $nobody $nobody
433 sub/g 64 $nobody $nobody
434 sub/h 128 $nobody $nobody
435 sub/i 256 $nobody $nobody
436 sub/j 512 $nobody $nobody
437 sub/k 1024 $nobody $nobody
438 sub/l 2048 $nobody $nobody
439 sub/m 4096 $nobody $nobody
440 sub/n 8192 $nobody $nobody
445 # extended file attribute flags
447 _mk_fillconfig_xattr()
449 cat <<End-of-File >$tmp.config
450 # pathname size user group perm name
452 xflag_realtime 10 $nobody $nobody 777 XFS_XFLAG_REALTIME
453 xflag_prealloc 10 $nobody $nobody 777 XFS_XFLAG_PREALLOC
454 xflag_immutable 10 $nobody $nobody 777 XFS_XFLAG_IMMUTABLE
455 xflag_append 10 $nobody $nobody 777 XFS_XFLAG_APPEND
456 xflag_sync 10 $nobody $nobody 777 XFS_XFLAG_SYNC
457 xflag_noatime 10 $nobody $nobody 777 XFS_XFLAG_NOATIME
458 xflag_nodump 10 $nobody $nobody 777 XFS_XFLAG_NODUMP
459 xflag_hasattr 10 $nobody $nobody 777 XFS_XFLAG_HASATTR
464 # Create a bunch of directories/files of different sizes
467 # Pinched from test 001.
469 _do_create_dumpdir_fill()
471 echo "Creating directory system to dump using src/fill."
473 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
476 $verbose && echo -n "Setup "
477 sed -e '/^#/d' $tmp.config \
478 | while read file nbytes owner group perms ea_name ea_value namespace
480 if [ $nbytes = "d" ]; then
490 echo "Error: cannot mkdir \"$dir\""
495 # create a directory/file
506 echo "Error: cannot mkdir \"$dir\""
512 if $here/src/fill $file $file $nbytes
517 echo "Error: cannot create \"$file\""
521 if [ -n "$owner" -a -n "$group" ]; then
522 chown $owner.$group $file
524 if [ -n "$perms" ]; then
528 # extended attributes (EA)
529 if [ -n "$ea_name" -a -n "$ea_value" ]; then
530 if [ "X$namespace" = "Xroot" ]; then
531 attr -R -s $ea_name -V $ea_value $file
533 attr -s $ea_name -V $ea_value $file
535 # extended file attribute flags - no value - NOT EAs
536 elif [ -n "$ea_name" -a -z "$ea_value" ]; then
539 # use xfs_io to send the ioctl
542 $verbose && echo -n "."
549 _mk_fillconfig_multi()
552 cat <<End-of-File >>$tmp.config
553 # pathname size in bytes
555 large000 8874368 $nobody $nobody
556 large111 2582912 $nobody $nobody
557 large222 7825792 $nobody $nobody
561 _create_dumpdir_largefile()
564 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
565 _largesize=4294967297
566 _largefile=$dump_dir/largefile
567 echo "dd a largefile at offset $_largesize"
568 POSIXLY_CORRECT=yes \
569 dd if=/dev/zero of=$_largefile bs=1 seek=$_largesize count=10 2>&1
573 _create_dumpdir_fill()
577 _do_create_dumpdir_fill
581 _create_dumpdir_fill2()
585 _do_create_dumpdir_fill
589 _create_dumpdir_fill_perm()
593 _do_create_dumpdir_fill
597 _create_dumpdir_fill_ea()
601 _do_create_dumpdir_fill
606 # Create enough files, and a few large enough files, so that
607 # some files are likely to be split across streams.
609 _create_dumpdir_fill_multi()
613 _do_create_dumpdir_fill
618 # Append a subset of the fill'ed files
619 # So we can see if just these get dumped on an incremental
621 _append_dumpdir_fill()
624 cat <<End-of-File >$tmp.config
634 sed -e '/^#/d' $tmp.config \
637 echo 'Extra text' >>$file
644 _do_create_dump_symlinks()
646 echo "Creating directory system of symlinks to dump."
648 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
651 $verbose && echo -n "Setup "
652 sed -e '/^#/d' $tmp.config \
653 | while read file nbytes owner group owner2 group2 perms perms2
665 echo "Error: cannot mkdir \"$dir\""
673 # Do chmod on symlink using umask.
674 # This won't do the right thing as it subtracts permissions.
675 # However, I don't care, as long as I get some different perms
677 if [ -n "$perms2" ]; then
681 ln -s $file $file-link
682 if [ -n "$perms2" ]; then
686 if [ -n "$owner" -a -n "$group" ]; then
687 chown $owner.$group $file
689 if [ -n "$owner" -a -n "$group" ]; then
690 chown -h $owner.$group $file-link
692 if [ -n "$perms" ]; then
695 $verbose && echo -n "."
704 cat <<End-of-File >$tmp.config
705 # path size owner1 group1 owner2 group2 perm1 perm2
707 a 0 $nobody $nobody daemon sys 124 421
708 b 0 daemon sys bin bin 347 743
709 sub/a 0 bin bin $nobody sys 777 777
710 sub/b 0 $nobody sys $nobody $nobody 367 763
714 _create_dumpdir_symlinks()
718 _do_create_dump_symlinks
723 # create hardlinks of form $_fname, $_fname_h1 $_fname_h2 ...
732 while [ $_j -le $_numlinks ]; do
734 _hardlink=$_fname$_suffix
735 echo "creating hardlink $_hardlink to $_fname"
736 ln $_fname $_hardlink
742 # create a set of hardlinks
743 # create hardlinks of form file1, file1_h1 file1_h2 ...
744 # create hardlinks of form file2, file2_h1 file2_h2 ...
745 # create hardlinks of form file3, file3_h1 file3_h2 ...
751 while [ $_i -le $_numsets ]; do
752 _create_hardlinks file$_i 5
761 echo "mod level $_level" >$dump_dir/file$_level
764 _create_dumpdir_hardlinks()
768 echo "Creating directory system of hardlinks to incrementally dump."
770 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
773 _create_hardset $_numsets
781 # Filter out times and dates on symlinks and char devices.
782 # Filter out size on directories because this can differ
783 # when transitioning to long inode numbers (ie. 64 bits).
788 /^l/ { date = $8; time = $7; sub(date,"DATE"); sub(time,"TIME"); print}
789 /^c/ { date = $9; time = $7; sub(date,"DATE"); sub(time,"TIME"); print}
790 /^d/ { size = $5; sub(size,"SIZE"); print}
792 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
796 # Filtering of Irix character hwgraph device names
798 # chardev: /hw/node/xtalk/15/pci/0/scsi_ctlr/0/target/1/lun/0/disk/partition/4/char
799 # blkdev: /dev/dsk/dks0d1s4
805 sub(/\/hw.*scsi_ctlr\//,"/dev/dsk/dks") # blah blah /dev/dsk/dks0/target/1/....
806 sub(/\/target\//,"d") # blah blah /dev/dsk/dks0d1/lun/0/disk.....
807 sub(/\/lun.*partition\//,"s") # blah blah /dev/dsk/dks0d1s4/char
808 sub(/\/char/,"") # blah blah /dev/dsk/dks0d1s4
816 # Filter out the non-deterministic dump msgs from
817 # xfsdump and xfsrestore
823 -e "s#$__XFSDUMP_PROG#xfsdump#" \
824 -e "s#$XFSRESTORE_PROG#xfsrestore#" \
825 -e "s#$XFSINVUTIL_PROG#xfsinvutil#" \
826 -e "s/`hostname`/HOSTNAME/" \
827 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
828 -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#" \
829 -e "s#$dumptape#TAPE_DEV#" \
830 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
831 -e "s#$dump_file#DUMP_FILE#" \
832 -e 's#/var/lib/xfsdump#/var/xfsdump#' \
833 -e 's/session id:[ ]*[0-9a-f-]*/session id: ID/' \
834 -e '/filesystem id:[ ]*[0-9a-f-]*/d' \
835 -e 's/time:[ ].*/time: TIME/' \
836 -e 's/date:[ ].*/date: DATE/' \
837 -e 's/dump begun .*/dump begun DATE/' \
838 -e 's/previously begun .*/previously begun DATE/' \
839 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
840 -e 's/restore.[0-9][0-9]*/restore.PID/' \
841 -e 's/ino [0-9][0-9]*/ino INO/g' \
842 -e '/stream [0-9]:/s/offset [0-9][0-9]*/offset NUM/g' \
843 -e '/: dump size/s/[0-9][0-9]*/NUM/' \
844 -e '/dump size:/s/[0-9][0-9]*/NUM/' \
845 -e '/dump size per stream:/s/[0-9][0-9]*/NUM/' \
846 -e 's/\(media file size[ ]*\)[0-9][0-9]*/\1NUM/' \
847 -e 's/\(mfile size:[ ]*\)[0-9][0-9]*/\1NUM/' \
848 -e '/drive[ ]*[0-9][0-9]*:/d' \
850 -e '/inventory session uuid/d' \
851 -e '/ - Running single-threaded/d' \
852 -e '/Mount point match/d' \
853 -e '/^.*I\/O metrics: .*$/d' \
854 -e 's/1048576/BLOCKSZ/' \
855 -e 's/2097152/BLOCKSZ/' \
856 -e 's/(pid[ ]*[1-9][0-9]*)/\(pid PID\)/' \
857 -e '/version [3-9]\.[0-9]/d' \
858 -e 's/\/hw\/module.*$/SCRATCH_DEV/' \
859 -e 's/xfsdump: ino map phase 1: .*/xfsdump: ino map <PHASES>/' \
860 -e '/xfsdump: ino map phase [2]/,1d' \
861 -e '/xfsdump: ino map phase [3]/,1d' \
862 -e '/xfsdump: ino map phase [4]/,1d' \
863 -e '/xfsdump: ino map phase [5]/,1d' \
864 -e 's/id:[[:space:]]*[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/ID: ID/' \
865 -e 's/\[y\/n\][- ]----------------------*/\[y\/n\]/' \
866 -e '/skip attribute set/d' \
868 # filter out all the output between the lines "Dump Summary:"
870 if ($_ =~ /(?:Dump|Restore) Summary/) {
872 } elsif ($_ =~ /(?:Dump|Restore) Status/) {
875 print if (! $skip);' \
877 # correct the file count if large scratch devices are being used
879 if ($_ =~ /(\S+) directories and (\S+) entries/) {
881 if ($ENV{'LARGE_SCRATCH_DEV'} && $foo > 0) {
884 printf("xfsrestore: %u directories and %u entries processed\n",
895 _dump_filter_main | _check_quota_dumprestore | _check_quota_entries
905 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
906 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
907 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
908 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
916 -e "s#$dump_file#DUMP_FILE#g" \
917 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
918 -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#" \
919 -e "s#$dumptape#TAPE_DEV#" \
920 -e "s#$dump_dir#DUMP_DIR#g" \
921 -e "s#$restore_dir#RESTORE_DIR#g" \
922 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
923 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
924 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
926 -e "/Only in SCRATCH_MNT: .use_space/d" \
927 -e "s#$RESULT_DIR/##g" \
932 # Parse xfsdump arguments.
933 # Note: requires a space between option letter and argument
944 [ -z "$2" ] && _fail "missing argument for -f"
950 [ -z "$2" ] && _fail "missing argument for -L"
955 [ -z "$2" ] && _fail "missing argument for --multi"
966 dump_args="$dump_args $1"
969 [ -z "$2" ] && _fail "missing argument for $1"
970 dump_args="$dump_args $1$2"
974 _fail "invalid argument to common/dump function: $1"
982 # Parse xfsrestore arguments.
983 # Note: requires a space between option letter and argument
985 _parse_restore_args()
994 [ -z "$2" ] && _fail "missing argument for -f"
1000 [ -z "$2" ] && _fail "missing argument for -L"
1005 [ -z "$2" ] && _fail "missing argument for --multi"
1013 do_quota_check=false
1016 restore_args="$restore_args $1"
1019 _fail "invalid argument to common/dump function: $1"
1034 echo "Dumping to tape..."
1035 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1036 echo "xfsdump $opts" | _dir_filter
1037 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1047 echo "Dumping to tape..."
1048 opts="$_dump_debug$dump_args -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1049 echo "xfsdump $opts" | _dir_filter
1050 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1055 # Do full dump with -m
1061 echo "Dumping to tape..."
1063 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1064 echo "xfsdump $opts" | _dir_filter
1065 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1070 # Do full dump to file
1076 echo "Dumping to file..."
1077 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
1078 echo "xfsdump $opts" | _dir_filter
1079 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1083 # Do full dump to multiple files
1085 _do_dump_multi_file()
1092 while [ $i -lt $multi ]
1094 multi_args="$multi_args -f $dump_file.$i -M $media_label.$i"
1098 echo "Dumping to files..."
1099 opts="$_dump_debug$dump_args $multi_args -L $session_label $SCRATCH_MNT"
1100 echo "xfsdump $opts" | _dir_filter
1101 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1105 _prepare_restore_dir()
1108 mkdir $restore_dir || _fail "failed to mkdir $restore_dir"
1113 # Get tape ready and restore dir
1117 _prepare_restore_dir
1119 echo "Rewinding tape"
1124 # Restore the tape into $restore_dir
1128 _parse_restore_args $*
1131 echo "Restoring from tape..."
1132 opts="$_restore_debug$restore_args -f $dumptape -L $session_label $restore_dir"
1133 echo "xfsrestore $opts" | _dir_filter
1134 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1138 # Restore the tape into $restore_dir using -m
1142 _parse_restore_args $*
1145 echo "Restoring from tape..."
1147 opts="$_restore_debug$restore_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
1148 echo "xfsrestore $opts" | _dir_filter
1149 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1153 # Restore the tape from a dump file
1157 _parse_restore_args $*
1158 _prepare_restore_dir
1160 echo "Restoring from file..."
1161 opts="$_restore_debug$restore_args -f $dump_file -L $session_label $restore_dir"
1162 echo "xfsrestore $opts" | _dir_filter
1163 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1167 # Cumulative restore from a file
1168 # Must call _prepare_restore_dir before the first
1169 # (and only the first) call to this function.
1171 _do_restore_file_cum()
1173 _parse_restore_args $*
1175 echo "Restoring cumumlative from file..."
1176 opts="$_restore_debug$restore_args -f $dump_file -r $restore_dir"
1177 echo "xfsrestore $opts" | _dir_filter
1178 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1183 _parse_restore_args $*
1185 echo "Contents of dump ..."
1186 opts="$_restore_debug$restore_args -f $dump_file -t"
1187 echo "xfsrestore $opts" | _dir_filter
1189 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter_main |\
1190 _check_quota_file |\
1191 _check_quota_entries |\
1192 $AWK_PROG 'NF != 1 { print; next }
1193 {files = sprintf("%s\n%s", files, $1)}
1194 END { print files | "sort" } '
1195 # the above awk code is to alpha sort only the output
1196 # of files (and not the verbose restore msgs)
1201 # Restore the tape from multiple dump files
1203 _do_restore_multi_file()
1205 _parse_restore_args $*
1206 _prepare_restore_dir
1211 while [ $i -lt $multi ]
1213 multi_args="$multi_args -f $dump_file.$i"
1217 echo "Restoring from file..."
1218 opts="$_restore_debug$restore_args $multi_args -L $session_label $restore_dir"
1219 echo "xfsrestore $opts" | _dir_filter
1220 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1224 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
1225 # Pass dump options in $1 and restore options in $2, if required. e.g.:
1226 # _do_dump_restore "-o -F" "-R"
1227 # _do_dump_restore "" "-R"
1229 # Use -s as we want to dump and restore to the same xfs partition
1234 _parse_restore_args $2
1235 _prepare_restore_dir
1236 echo "xfsdump|xfsrestore ..."
1237 restore_opts="$_restore_debug$restore_args - $restore_dir"
1238 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
1239 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
1240 $XFSDUMP_PROG $dump_opts 2>$tmp.dump.mlog | $XFSRESTORE_PROG $restore_opts 2>&1 | tee -a $seqres.full | _dump_filter
1241 _dump_filter <$tmp.dump.mlog
1245 # Compare dumped subdirectory with restored dir
1247 # Thus no contents are compared but permissions, sizes,
1248 # owners, etc... are.
1253 # verify we got back what we dumped
1255 echo "Comparing listing of dump directory with restore directory"
1256 ls -nR $dump_dir | tee -a $seqres.full | _ls_filter >$tmp.dump_dir
1257 ls -nR $restore_dir/$dump_sdir | tee -a $seqres.full | _ls_filter \
1258 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
1260 diff -bcs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
1264 # filter out the date fields
1268 $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
1272 # _ls_compare_sub but don't compare dates
1273 _ls_nodate_compare_sub()
1276 # verify we got back what we dumped
1278 echo "Comparing listing of dump directory with restore directory"
1279 ls -nR $dump_dir | tee -a $seqres.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
1280 ls -nR $restore_dir/$dump_sdir | tee -a $seqres.full | _ls_filter \
1281 | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
1283 diff -bcs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
1287 # Compare using recursive diff the files of the dumped
1289 # This one will compare the contents.
1293 echo "Comparing dump directory with restore directory"
1294 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
1301 # Tim - this is the IRIX way...
1302 # find $_path -exec attr -l {} \; |\
1303 # awk '{print $9, $2}' |\
1306 # and this is now the Linux way...
1308 getfattr --absolute-names -Rh -m user $_path |\
1310 if (m/^# file: (\S+)/) { $file = $1 }
1311 elsif (m/^user\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1313 while read file ea_name; do
1314 attr -g $ea_name $file
1317 if [ "$USE_ATTR_SECURE" = yes ]; then
1318 echo "Security names"
1319 getfattr --absolute-names -Rh -m security $_path |\
1321 if (m/^# file: (\S+)/) { $file = $1 }
1322 elsif (m/^security\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1324 while read file ea_name; do
1325 attr -g $ea_name $file
1330 getfattr --absolute-names -Rh -m trusted $_path |\
1332 if (m/^# file: (\S+)/) { $file = $1 }
1333 elsif (m/^trusted\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1335 while read file ea_name; do
1336 attr -R -g $ea_name $file
1341 # Compare the extended attributes of the files/dirs
1342 # b/w the dumped and restore dirs.
1345 # Attribute "attr5" had a 8 byte value for /spare1/dump.5460/dir:
1346 # Attribute "attr5" had a 8 byte value for /spare1/restore.5460/dump.5460/dir:
1350 echo "Comparing dump directory with restore directory"
1351 echo "Looking at the extended attributes (EAs)"
1353 _get_eas_on_path $dump_dir | tee $seqres.ea1 | _dir_filter
1354 echo "EAs on restore"
1355 _get_eas_on_path $restore_dir/$dump_sdir \
1356 | sed -e "s#$restore_sdir\/##" \
1359 diff -s $seqres.ea1 $seqres.ea2 | _dir_filter
1364 # Compare using recursive diff the files of the dumped
1369 echo "Comparing dump directory with restore directory"
1370 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter | _check_quota_diff
1374 # Check out the dump inventory
1378 $XFSDUMP_PROG $_dump_debug -I | tee -a $seqres.full | _dump_filter_main
1382 # Do the xfsinvutil cmd with debug and filters
1383 # Need to set variable: "$middate" to the invutil date
1388 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seqres.full
1389 $XFSINVUTIL_PROG $_invutil_debug $* -M $host:$SCRATCH_MNT "$middate" \
1390 | tee -a $seqres.full | _invutil_filter
1394 # ensure we can find the user quota msg if user quotas are on
1395 # ensure we can find the group quota msg if group quotas are on
1405 $here/src/feature -U $SCRATCH_DEV && uquota=1
1406 $here/src/feature -G $SCRATCH_DEV && gquota=1
1407 $here/src/feature -P $SCRATCH_DEV && pquota=1
1409 $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v pquota=$pquota \
1410 -v full=$seqres.full -v usermsg="$usermsg" \
1411 -v groupmsg="$groupmsg" -v projectmsg="$projectmsg" '
1413 print "Found project quota:", $0 >>full
1416 print "Found extra:", $0
1421 print "Found group quota:", $0 >>full
1424 print "Found extra:", $0
1429 print "Found user quota:", $0 >>full
1432 print "Found extra:", $0
1436 $0 ~ "Restore Status: INCOMPLETE" {
1441 if (uquota && !found_uquota && !incomplete) {
1442 print "Missing user quota msg:", usermsg
1444 if (gquota && !found_gquota && !incomplete) {
1445 print "Missing group quota msg:", groupmsg
1447 if (pquota && !found_pquota && !incomplete) {
1448 print "Missing project quota msg:", projectmsg
1455 # xfsrestore: 3 directories and 40 entries processed
1457 # num entries needs to be reduced by num quota file(s)
1459 _check_quota_entries()
1464 $here/src/feature -U $SCRATCH_DEV && uquota=1
1465 $here/src/feature -G $SCRATCH_DEV && gquota=1
1466 $here/src/feature -P $SCRATCH_DEV && pquota=1
1467 $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v pquota=$pquota '
1468 /entries processed/ {
1478 # xfsdump: saving user quota information for: SCRATCH_MNT
1479 # xfsdump: saving group quota information for: SCRATCH_MNT
1480 # xfsdump: saving project quota information for: SCRATCH_MNT
1481 # xfsrestore: user quota information written to ...'
1482 # xfsrestore: group quota information written to ...'
1483 # xfsrestore: project quota information written to ...'
1484 # xfsrestore: use 'xfs_quota' to restore quotas
1486 _check_quota_dumprestore()
1488 _check_quota 'user quota information' \
1489 'group quota information' \
1490 'project quota information' | \
1491 sed "/xfsrestore:.*use 'xfs_quota' to restore quotas/d"
1496 # Only in RESTORE_DIR: xfsdump_quotas
1497 # Only in RESTORE_DIR: xfsdump_quotas_group
1498 # Only in RESTORE_DIR: xfsdump_quotas_project
1502 _check_quota 'Only in RESTORE_DIR: xfsdump_quotas' \
1503 'Only in RESTORE_DIR: xfsdump_quotas_group' \
1504 'Only in RESTORE_DIR: xfsdump_quotas_proj'
1508 # Look for the quota file in the output
1509 # Ensure that it is there if it should be
1510 # Filter it out so that the output is always the same
1511 # even with no quotas
1515 _check_quota 'xfsdump_quotas' 'xfsdump_quotas_group' 'xfsdump_quotas_proj'
1519 # make sure this script returns success