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 _require_user_exists daemon
31 _require_user_exists bin
35 # status returned for not run tests
38 # name those directories
39 dump_file=$tmp.dumpfile
40 # dump_file=$here/dumpfile #TEMP OVERRIDE DUMP FILE
42 dump_dir=$SCRATCH_MNT/$dump_sdir
43 restore_sdir=restoredir
44 restore_dir=$SCRATCH_MNT/$restore_sdir
47 media_label="stress_tape_media"
48 session_label="stress_$seq"
50 nobody=4 # define this uid/gid as a number
51 do_quota_check=true # do quota check if quotas enabled
53 # start inventory from a known base - move it aside for test
54 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
56 [ -d $dir.$seq ] && rm -rf $dir.$seq
62 [ `uname` = "Linux" ] && have_mtvariable=true
65 _require_multi_stream()
67 $XFSDUMP_PROG -JF -f /dev/null -f /dev/null 2> /dev/null |
68 grep -q "too many -f arguments" &&
69 _notrun "xfsdump multi-stream support required"
72 _require_legacy_v2_format()
75 grep -q "generate format 2 dump" ||
76 _notrun "xfsdump -K option required"
78 $XFSRESTORE_PROG 2>&1 |
79 grep -q "force use of format 2 generation" ||
80 _notrun "xfsrestore -K option required"
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..." >>$seqres.full
114 if _mt status >$tmp.status 2>&1; then
123 if [ $i -eq $_limit ]; then
124 echo "ERROR: mt -f $dumptape failed"
127 _notrun "mt -f $dumptape failed"
131 if egrep -i 'onl|ready' $tmp.status | grep -iv 'not ready' >/dev/null; then
134 echo "ERROR: $dumptape is not online"
137 _notrun "dumptape, $dumptape, is not online"
143 echo "Wait for tape, $dumptape, ..." >>$seqres.full
146 while [ $i -lt 20 ]; do
147 echo "Checking status..." >>$seqres.full
148 if _mt status 2>&1 | tee -a $seqres.full | egrep -i "onl|ready" >/dev/null; then
158 # Keep trying so we know we really have rewound
162 echo "Initiate rewind..." >>$seqres.full
164 _mt rewind >/dev/null
169 # Do a custom erase because:
170 # (i) some machines don't support it
171 # (ii) some machines take forever to do it
175 echo "Erasing tape" | tee -a $seqres.full
183 echo "Erasing tape" | tee -a $seqres.full
189 echo $dumptape | grep ':' >/dev/null
197 $have_mtvariable || return
203 echo "Put scsi tape driver into variable block size mode"
204 mt -f $dumptape setblk 0
212 if [ -z "$dumptape" -o "@" == "$dumptape" ]; then
213 _notrun "No dump tape specified"
221 # Cleanup created dirs and files
226 # Some tests include this before checking _supported_fs xfs
227 # and the sleeps & checks here get annoying
228 if [ "$FSTYP" != "xfs" ]; then
234 if [ -n "$DEBUGDUMP" ]; then
235 # save it for inspection
236 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
237 [ -d $dir ] || continue
238 tar -cvf $seqres.inventory.tar $dir
239 ls -nR $dir >$seqres.inventory.ls
243 # put inventory dir back
244 for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
245 [ -d $dir.$seq ] || continue
246 rm -rf $dir # get rid of new one
250 if [ -f ${RESULT_DIR}/require_scratch ] && [ $status -ne $NOTRUNSTS ]; then
251 # Sleep added to stop _check_scratch_fs from complaining that the
252 # scratch_dev is still busy
260 # ensure that bulkstat data will
261 # match with incore data
262 # by forcing disk data to be written out
266 _saveddir=`pwd`; cd /
267 _scratch_unmount >>$seqres.full || _fail "unmount failed"
268 _scratch_mount >>$seqres.full
273 # Run fsstress to create a mixture of
274 # files,dirs,links,symlinks
276 # Pinched from test 013.
277 # Takes one argument, the number of ops to perform
279 _create_dumpdir_stress_num()
281 echo "Creating directory system to dump using fsstress."
285 _param="-f link=10 -f creat=10 -f mkdir=10 -f truncate=5 -f symlink=10"
287 if ! mkdir $dump_dir; then
288 echo " failed to mkdir $dump_dir"
293 # Remove fsstress commands that aren't supported on all xfs configs so that
294 # we always execute exactly the same sequence of operations no matter how
295 # the filesystem is configured
296 if $FSSTRESS_PROG | grep -q clonerange; then
297 FSSTRESS_AVOID="-f clonerange=0 $FSSTRESS_AVOID"
299 if $FSSTRESS_PROG | grep -q deduperange; then
300 FSSTRESS_AVOID="-f deduperange=0 $FSSTRESS_AVOID"
302 if $FSSTRESS_PROG | grep -q copyrange; then
303 FSSTRESS_AVOID="-f copyrange=0 $FSSTRESS_AVOID"
305 if $FSSTRESS_PROG | grep -q splice; then
306 FSSTRESS_AVOID="-f splice=0 $FSSTRESS_AVOID"
310 echo "-----------------------------------------------"
311 echo "fsstress : $_param"
312 echo "-----------------------------------------------"
313 if ! $here/ltp/fsstress $_param -s 1 $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
315 echo " fsstress (count=$_count) returned $? - see $seqres.full"
317 echo "--------------------------------------" >>$seqres.full
318 echo "output from fsstress:" >>$seqres.full
319 echo "--------------------------------------" >>$seqres.full
320 cat $tmp.out >>$seqres.full
327 _create_dumpdir_stress() {
328 _create_dumpdir_stress_num 240
333 cat <<End-of-File >$tmp.config
334 # pathname size in bytes owner group
336 small 10 $nobody $nobody
337 big 102400 daemon sys
339 sub/big 102400 $nobody sys
341 sub/a 1 $nobody $nobody
342 sub/b 2 $nobody $nobody
343 sub/c 4 $nobody $nobody
344 sub/d 8 $nobody $nobody
345 sub/e 16 $nobody $nobody
346 sub/f 32 $nobody $nobody
347 sub/g 64 $nobody $nobody
348 sub/h 128 $nobody $nobody
349 sub/i 256 $nobody $nobody
350 sub/j 512 $nobody $nobody
351 sub/k 1024 $nobody $nobody
352 sub/l 2048 $nobody $nobody
353 sub/m 4096 $nobody $nobody
354 sub/n 8192 $nobody $nobody
356 sub/a00 100 $nobody $nobody
357 sub/b00 200 $nobody $nobody
358 sub/c00 400 $nobody $nobody
359 sub/d00 800 $nobody $nobody
360 sub/e00 1600 $nobody $nobody
361 sub/f00 3200 $nobody $nobody
362 sub/g00 6400 $nobody $nobody
363 sub/h00 12800 $nobody $nobody
364 sub/i00 25600 $nobody $nobody
365 sub/j00 51200 $nobody $nobody
366 sub/k00 102400 $nobody $nobody
367 sub/l00 204800 $nobody $nobody
368 sub/m00 409600 $nobody $nobody
369 sub/n00 819200 $nobody $nobody
371 sub/a000 1000 $nobody $nobody
372 sub/e000 16000 $nobody $nobody
373 sub/h000 128000 $nobody $nobody
374 sub/k000 1024000 $nobody $nobody
380 cat <<End-of-File >$tmp.config
381 # pathname size in bytes
383 smalll 10 $nobody $nobody
384 biggg 102400 $nobody $nobody
385 sub/smalll 10 $nobody $nobody
386 sub/biggg 102400 $nobody $nobody
390 _mk_fillconfig_perm()
392 cat <<End-of-File >$tmp.config
393 # pathname size/dir user group mode
395 file_suid 10 $nobody $nobody 04777
396 file_guid 10 $nobody $nobody 02777
397 file_sticky 10 $nobody $nobody 01777
398 file_mix1 10 $nobody $nobody 761
399 file_mix2 10 $nobody $nobody 642
400 dir_suid d $nobody $nobody 04777
401 dir_guid d $nobody $nobody 02777
402 dir_sticky d $nobody $nobody 01777
403 dir_mix1 d $nobody $nobody 761
404 dir_mix2 d $nobody $nobody 642
410 cat <<End-of-File >$tmp.config
411 # pathname size user group perm name value namespace
413 smalll 10 $nobody $nobody 777 attr1 some_text user
414 biggg 102400 $nobody $nobody 777 attr2 some_text2 root
415 sub/smalll 10 $nobody $nobody 777 attr3 some_text3 user
416 sub/biggg 102400 $nobody $nobody 777 attr4 some_text4 root
417 dir d $nobody $nobody 777 attr5 dir_text user
419 # Add more files so that there are more than the number
421 # There are bugs in dump/restore for # non-dir files < # streams
422 # It can be tested in another configuration.
423 # It is a pathalogical case.
425 sub/a 1 $nobody $nobody
426 sub/b 2 $nobody $nobody
427 sub/c 4 $nobody $nobody
428 sub/d 8 $nobody $nobody
429 sub/e 16 $nobody $nobody
430 sub/f 32 $nobody $nobody
431 sub/g 64 $nobody $nobody
432 sub/h 128 $nobody $nobody
433 sub/i 256 $nobody $nobody
434 sub/j 512 $nobody $nobody
435 sub/k 1024 $nobody $nobody
436 sub/l 2048 $nobody $nobody
437 sub/m 4096 $nobody $nobody
438 sub/n 8192 $nobody $nobody
443 # extended file attribute flags
445 _mk_fillconfig_xattr()
447 cat <<End-of-File >$tmp.config
448 # pathname size user group perm name
450 xflag_realtime 10 $nobody $nobody 777 XFS_XFLAG_REALTIME
451 xflag_prealloc 10 $nobody $nobody 777 XFS_XFLAG_PREALLOC
452 xflag_immutable 10 $nobody $nobody 777 XFS_XFLAG_IMMUTABLE
453 xflag_append 10 $nobody $nobody 777 XFS_XFLAG_APPEND
454 xflag_sync 10 $nobody $nobody 777 XFS_XFLAG_SYNC
455 xflag_noatime 10 $nobody $nobody 777 XFS_XFLAG_NOATIME
456 xflag_nodump 10 $nobody $nobody 777 XFS_XFLAG_NODUMP
457 xflag_hasattr 10 $nobody $nobody 777 XFS_XFLAG_HASATTR
462 # Create a bunch of directories/files of different sizes
465 # Pinched from test 001.
467 _do_create_dumpdir_fill()
469 echo "Creating directory system to dump using src/fill."
471 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
474 $verbose && echo -n "Setup "
475 sed -e '/^#/d' $tmp.config \
476 | while read file nbytes owner group perms ea_name ea_value namespace
478 if [ $nbytes = "d" ]; then
488 echo "Error: cannot mkdir \"$dir\""
493 # create a directory/file
504 echo "Error: cannot mkdir \"$dir\""
510 if $here/src/fill $file $file $nbytes
515 echo "Error: cannot create \"$file\""
519 if [ -n "$owner" -a -n "$group" ]; then
520 chown $owner.$group $file
522 if [ -n "$perms" ]; then
526 # extended attributes (EA)
527 if [ -n "$ea_name" -a -n "$ea_value" ]; then
528 if [ "X$namespace" = "Xroot" ]; then
529 attr -R -s $ea_name -V $ea_value $file
531 attr -s $ea_name -V $ea_value $file
533 # extended file attribute flags - no value - NOT EAs
534 elif [ -n "$ea_name" -a -z "$ea_value" ]; then
537 # use xfs_io to send the ioctl
540 $verbose && echo -n "."
547 _mk_fillconfig_multi()
550 cat <<End-of-File >>$tmp.config
551 # pathname size in bytes
553 large000 8874368 $nobody $nobody
554 large111 2582912 $nobody $nobody
555 large222 7825792 $nobody $nobody
559 _create_dumpdir_largefile()
561 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
562 _largesize=4294967297
563 _largefile=$dump_dir/largefile
564 echo "dd a largefile at offset $_largesize"
565 POSIXLY_CORRECT=yes \
566 dd if=/dev/zero of=$_largefile bs=1 seek=$_largesize count=10 2>&1
570 _create_dumpdir_fill()
573 _do_create_dumpdir_fill
577 _create_dumpdir_fill2()
580 _do_create_dumpdir_fill
584 _create_dumpdir_fill_perm()
587 _do_create_dumpdir_fill
591 _create_dumpdir_fill_ea()
594 _do_create_dumpdir_fill
599 # Create enough files, and a few large enough files, so that
600 # some files are likely to be split across streams.
602 _create_dumpdir_fill_multi()
605 _do_create_dumpdir_fill
610 # Append a subset of the fill'ed files
611 # So we can see if just these get dumped on an incremental
613 _append_dumpdir_fill()
616 cat <<End-of-File >$tmp.config
626 sed -e '/^#/d' $tmp.config \
629 echo 'Extra text' >>$file
636 _do_create_dump_symlinks()
638 echo "Creating directory system of symlinks to dump."
640 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
643 $verbose && echo -n "Setup "
644 sed -e '/^#/d' $tmp.config \
645 | while read file nbytes owner group owner2 group2 perms perms2
657 echo "Error: cannot mkdir \"$dir\""
665 # Do chmod on symlink using umask.
666 # This won't do the right thing as it subtracts permissions.
667 # However, I don't care, as long as I get some different perms
669 if [ -n "$perms2" ]; then
673 ln -s $file $file-link
674 if [ -n "$perms2" ]; then
678 if [ -n "$owner" -a -n "$group" ]; then
679 chown $owner.$group $file
681 if [ -n "$owner" -a -n "$group" ]; then
682 chown -h $owner.$group $file-link
684 if [ -n "$perms" ]; then
687 $verbose && echo -n "."
696 cat <<End-of-File >$tmp.config
697 # path size owner1 group1 owner2 group2 perm1 perm2
699 a 0 $nobody $nobody daemon sys 124 421
700 b 0 daemon sys bin bin 347 743
701 sub/a 0 bin bin $nobody sys 777 777
702 sub/b 0 $nobody sys $nobody $nobody 367 763
706 _create_dumpdir_symlinks()
709 _do_create_dump_symlinks
714 # create hardlinks of form $_fname, $_fname_h1 $_fname_h2 ...
723 while [ $_j -le $_numlinks ]; do
725 _hardlink=$_fname$_suffix
726 echo "creating hardlink $_hardlink to $_fname"
727 ln $_fname $_hardlink
733 # create a set of hardlinks
734 # create hardlinks of form file1, file1_h1 file1_h2 ...
735 # create hardlinks of form file2, file2_h1 file2_h2 ...
736 # create hardlinks of form file3, file3_h1 file3_h2 ...
742 while [ $_i -le $_numsets ]; do
743 _create_hardlinks file$_i 5
752 echo "mod level $_level" >$dump_dir/file$_level
755 _create_dumpdir_hardlinks()
758 echo "Creating directory system of hardlinks to incrementally dump."
760 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
763 _create_hardset $_numsets
771 # Filter out times and dates on symlinks and char devices.
772 # Filter out size on directories because this can differ
773 # when transitioning to long inode numbers (ie. 64 bits).
778 /^l/ { date = $8; time = $7; sub(date,"DATE"); sub(time,"TIME"); print}
779 /^c/ { date = $9; time = $7; sub(date,"DATE"); sub(time,"TIME"); print}
780 /^d/ { size = $5; sub(size,"SIZE"); print}
782 | sed -e 's/total [0-9][0-9]*/total TOTAL/'
786 # Filtering of Irix character hwgraph device names
788 # chardev: /hw/node/xtalk/15/pci/0/scsi_ctlr/0/target/1/lun/0/disk/partition/4/char
789 # blkdev: /dev/dsk/dks0d1s4
795 sub(/\/hw.*scsi_ctlr\//,"/dev/dsk/dks") # blah blah /dev/dsk/dks0/target/1/....
796 sub(/\/target\//,"d") # blah blah /dev/dsk/dks0d1/lun/0/disk.....
797 sub(/\/lun.*partition\//,"s") # blah blah /dev/dsk/dks0d1s4/char
798 sub(/\/char/,"") # blah blah /dev/dsk/dks0d1s4
806 # Filter out the non-deterministic dump msgs from
807 # xfsdump and xfsrestore
813 -e "s#$__XFSDUMP_PROG#xfsdump#" \
814 -e "s#$XFSRESTORE_PROG#xfsrestore#" \
815 -e "s#$XFSINVUTIL_PROG#xfsinvutil#" \
816 -e "s/`hostname`/HOSTNAME/" \
817 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
818 -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#" \
819 -e "s#$dumptape#TAPE_DEV#" \
820 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
821 -e "s#$dump_file#DUMP_FILE#" \
822 -e 's#/var/lib/xfsdump#/var/xfsdump#' \
823 -e 's/session id:[ ]*[0-9a-f-]*/session id: ID/' \
824 -e '/filesystem id:[ ]*[0-9a-f-]*/d' \
825 -e 's/time:[ ].*/time: TIME/' \
826 -e 's/date:[ ].*/date: DATE/' \
827 -e 's/dump begun .*/dump begun DATE/' \
828 -e 's/previously begun .*/previously begun DATE/' \
829 -e 's/[0-9][0-9]* seconds/SECS seconds/' \
830 -e 's/restore.[0-9][0-9]*/restore.PID/' \
831 -e 's/ino [0-9][0-9]*/ino INO/g' \
832 -e '/stream [0-9]:/s/offset [0-9][0-9]*/offset NUM/g' \
833 -e '/: dump size/s/[0-9][0-9]*/NUM/' \
834 -e '/dump size:/s/[0-9][0-9]*/NUM/' \
835 -e '/dump size per stream:/s/[0-9][0-9]*/NUM/' \
836 -e 's/\(media file size[ ]*\)[0-9][0-9]*/\1NUM/' \
837 -e 's/\(mfile size:[ ]*\)[0-9][0-9]*/\1NUM/' \
838 -e '/drive[ ]*[0-9][0-9]*:/d' \
840 -e '/inventory session uuid/d' \
841 -e '/ - Running single-threaded/d' \
842 -e '/Mount point match/d' \
843 -e '/^.*I\/O metrics: .*$/d' \
844 -e 's/1048576/BLOCKSZ/' \
845 -e 's/2097152/BLOCKSZ/' \
846 -e 's/(pid[ ]*[1-9][0-9]*)/\(pid PID\)/' \
847 -e '/version [3-9]\.[0-9]/d' \
848 -e 's/\/hw\/module.*$/SCRATCH_DEV/' \
849 -e 's/xfsdump: ino map phase 1: .*/xfsdump: ino map <PHASES>/' \
850 -e '/xfsdump: ino map phase [2]/,1d' \
851 -e '/xfsdump: ino map phase [3]/,1d' \
852 -e '/xfsdump: ino map phase [4]/,1d' \
853 -e '/xfsdump: ino map phase [5]/,1d' \
854 -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/' \
855 -e 's/\[y\/n\][- ]----------------------*/\[y\/n\]/' \
856 -e '/skip attribute set/d' \
857 -e '/xfsrestore: NOTE: attempt to reserve [0-9]* bytes for.*Operation not supported/d' \
859 # filter out all the output between the lines "Dump Summary:"
861 if ($_ =~ /(?:Dump|Restore) Summary/) {
863 } elsif ($_ =~ /(?:Dump|Restore) Status/) {
866 print if (! $skip);' \
868 # correct the file count if large scratch devices are being used
870 if ($_ =~ /(\S+) directories and (\S+) entries/) {
872 if ($ENV{'LARGE_SCRATCH_DEV'} && $foo > 0) {
875 printf("xfsrestore: %u directories and %u entries processed\n",
886 _dump_filter_main | _check_quota_dumprestore | _check_quota_entries
896 -e 's/UUID[ ]*:[ ][0-9a-f-]*/UUID : ID/' \
897 -e 's/TIME OF DUMP[ ]*:.*/TIME OF DUMP : TIME/' \
898 -e 's/HOSTNAME:SCRATCH_MNT.*/HOSTNAME:SCRATCH_MNT/' \
899 -e 's#inventory/[0-9a-f-]*#inventory/UUID#' \
907 -e "s#$dump_file#DUMP_FILE#g" \
908 -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
909 -e "s#$SCRATCH_RAWDEV#SCRATCH_DEV#" \
910 -e "s#$dumptape#TAPE_DEV#" \
911 -e "s#$dump_dir#DUMP_DIR#g" \
912 -e "s#$restore_dir#RESTORE_DIR#g" \
913 -e "s#$SCRATCH_MNT#SCRATCH_MNT#g" \
914 -e "s#$dump_sdir#DUMP_SUBDIR#g" \
915 -e "s#$restore_sdir#RESTORE_SUBDIR#g" \
917 -e "/Only in SCRATCH_MNT: .use_space/d" \
918 -e "s#$RESULT_DIR/##g" \
923 # Parse xfsdump arguments.
924 # Note: requires a space between option letter and argument
935 [ -z "$2" ] && _fail "missing argument for -f"
941 [ -z "$2" ] && _fail "missing argument for -L"
946 [ -z "$2" ] && _fail "missing argument for --multi"
957 dump_args="$dump_args $1"
960 [ -z "$2" ] && _fail "missing argument for $1"
961 dump_args="$dump_args $1$2"
965 _fail "invalid argument to common/dump function: $1"
973 # Parse xfsrestore arguments.
974 # Note: requires a space between option letter and argument
976 _parse_restore_args()
985 [ -z "$2" ] && _fail "missing argument for -f"
991 [ -z "$2" ] && _fail "missing argument for -L"
996 [ -z "$2" ] && _fail "missing argument for --multi"
1004 do_quota_check=false
1007 restore_args="$restore_args $1"
1010 _fail "invalid argument to common/dump function: $1"
1025 echo "Dumping to tape..."
1026 opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1027 echo "xfsdump $opts" | _dir_filter
1028 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1038 echo "Dumping to tape..."
1039 opts="$_dump_debug$dump_args -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1040 echo "xfsdump $opts" | _dir_filter
1041 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1046 # Do full dump with -m
1052 echo "Dumping to tape..."
1054 opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
1055 echo "xfsdump $opts" | _dir_filter
1056 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1061 # Do full dump to file
1067 echo "Dumping to file..."
1068 opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
1069 echo "xfsdump $opts" | _dir_filter
1070 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1074 # Do full dump to multiple files
1076 _do_dump_multi_file()
1083 while [ $i -lt $multi ]
1085 multi_args="$multi_args -f $dump_file.$i -M $media_label.$i"
1089 echo "Dumping to files..."
1090 opts="$_dump_debug$dump_args $multi_args -L $session_label $SCRATCH_MNT"
1091 echo "xfsdump $opts" | _dir_filter
1092 $XFSDUMP_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1096 _prepare_restore_dir()
1099 mkdir $restore_dir || _fail "failed to mkdir $restore_dir"
1104 # Get tape ready and restore dir
1108 _prepare_restore_dir
1110 echo "Rewinding tape"
1115 # Restore the tape into $restore_dir
1119 _parse_restore_args $*
1122 echo "Restoring from tape..."
1123 opts="$_restore_debug$restore_args -f $dumptape -L $session_label $restore_dir"
1124 echo "xfsrestore $opts" | _dir_filter
1125 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1129 # Restore the tape into $restore_dir using -m
1133 _parse_restore_args $*
1136 echo "Restoring from tape..."
1138 opts="$_restore_debug$restore_args -m -b $onemeg -f $dumptape -L $session_label $restore_dir"
1139 echo "xfsrestore $opts" | _dir_filter
1140 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1144 # Restore the tape from a dump file
1148 _parse_restore_args $*
1149 _prepare_restore_dir
1151 echo "Restoring from file..."
1152 opts="$_restore_debug$restore_args -f $dump_file -L $session_label $restore_dir"
1153 echo "xfsrestore $opts" | _dir_filter
1154 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1158 # Cumulative restore from a file
1159 # Must call _prepare_restore_dir before the first
1160 # (and only the first) call to this function.
1162 _do_restore_file_cum()
1164 _parse_restore_args $*
1166 echo "Restoring cumumlative from file..."
1167 opts="$_restore_debug$restore_args -f $dump_file -r $restore_dir"
1168 echo "xfsrestore $opts" | _dir_filter
1169 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1174 _parse_restore_args $*
1176 echo "Contents of dump ..."
1177 opts="$_restore_debug$restore_args -f $dump_file -t"
1178 echo "xfsrestore $opts" | _dir_filter
1180 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter_main |\
1181 _check_quota_file |\
1182 _check_quota_entries |\
1183 $AWK_PROG 'NF != 1 { print; next }
1184 {files = sprintf("%s\n%s", files, $1)}
1185 END { print files | "sort" } '
1186 # the above awk code is to alpha sort only the output
1187 # of files (and not the verbose restore msgs)
1192 # Restore the tape from multiple dump files
1194 _do_restore_multi_file()
1196 _parse_restore_args $*
1197 _prepare_restore_dir
1202 while [ $i -lt $multi ]
1204 multi_args="$multi_args -f $dump_file.$i"
1208 echo "Restoring from file..."
1209 opts="$_restore_debug$restore_args $multi_args -L $session_label $restore_dir"
1210 echo "xfsrestore $opts" | _dir_filter
1211 $XFSRESTORE_PROG $opts 2>&1 | tee -a $seqres.full | _dump_filter
1215 # Do xfsdump piped into xfsrestore - xfsdump | xfsrestore
1216 # Pass dump options in $1 and restore options in $2, if required. e.g.:
1217 # _do_dump_restore "-o -F" "-R"
1218 # _do_dump_restore "" "-R"
1220 # Use -s as we want to dump and restore to the same xfs partition
1225 _parse_restore_args $2
1226 _prepare_restore_dir
1227 echo "xfsdump|xfsrestore ..."
1228 restore_opts="$_restore_debug$restore_args - $restore_dir"
1229 dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
1230 echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter
1231 $XFSDUMP_PROG $dump_opts 2>$tmp.dump.mlog | $XFSRESTORE_PROG $restore_opts 2>&1 | tee -a $seqres.full | _dump_filter
1232 _dump_filter <$tmp.dump.mlog
1236 # Compare dumped subdirectory with restored dir
1238 # Thus no contents are compared but permissions, sizes,
1239 # owners, etc... are.
1244 # verify we got back what we dumped
1246 echo "Comparing listing of dump directory with restore directory"
1247 ls -nR $dump_dir | tee -a $seqres.full | _ls_filter >$tmp.dump_dir
1248 ls -nR $restore_dir/$dump_sdir | tee -a $seqres.full | _ls_filter \
1249 | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
1251 diff -bcs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
1255 # filter out the date fields
1259 $AWK_PROG 'NF == 9 { print $1, $2, $3, $4, $9 }'
1263 # _ls_compare_sub but don't compare dates
1264 _ls_nodate_compare_sub()
1267 # verify we got back what we dumped
1269 echo "Comparing listing of dump directory with restore directory"
1270 ls -nR $dump_dir | tee -a $seqres.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
1271 ls -nR $restore_dir/$dump_sdir | tee -a $seqres.full | _ls_filter \
1272 | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
1274 diff -bcs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
1278 # Compare using recursive diff the files of the dumped
1280 # This one will compare the contents.
1284 echo "Comparing dump directory with restore directory"
1285 diff -rs $dump_dir $restore_dir/$dump_sdir | _dir_filter
1292 # Tim - this is the IRIX way...
1293 # find $_path -exec attr -l {} \; |\
1294 # awk '{print $9, $2}' |\
1297 # and this is now the Linux way...
1299 getfattr --absolute-names -Rh -m user $_path |\
1301 if (m/^# file: (\S+)/) { $file = $1 }
1302 elsif (m/^user\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1304 while read file ea_name; do
1305 attr -g $ea_name $file
1308 if [ "$USE_ATTR_SECURE" = yes ]; then
1309 echo "Security names"
1310 getfattr --absolute-names -Rh -m security $_path |\
1312 if (m/^# file: (\S+)/) { $file = $1 }
1313 elsif (m/^security\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1315 while read file ea_name; do
1316 attr -g $ea_name $file
1321 getfattr --absolute-names -Rh -m trusted $_path |\
1323 if (m/^# file: (\S+)/) { $file = $1 }
1324 elsif (m/^trusted\.(\w+)/) { print $file, " ",$1,"\n" }' |\
1326 while read file ea_name; do
1327 attr -R -g $ea_name $file
1332 # Compare the extended attributes of the files/dirs
1333 # b/w the dumped and restore dirs.
1336 # Attribute "attr5" had a 8 byte value for /spare1/dump.5460/dir:
1337 # Attribute "attr5" had a 8 byte value for /spare1/restore.5460/dump.5460/dir:
1341 echo "Comparing dump directory with restore directory"
1342 echo "Looking at the extended attributes (EAs)"
1344 _get_eas_on_path $dump_dir | tee $seqres.ea1 | _dir_filter
1345 echo "EAs on restore"
1346 _get_eas_on_path $restore_dir/$dump_sdir \
1347 | sed -e "s#$restore_sdir\/##" \
1350 diff -s $seqres.ea1 $seqres.ea2 | _dir_filter
1355 # Compare using recursive diff the files of the dumped
1360 echo "Comparing dump directory with restore directory"
1361 diff -rs $SCRATCH_MNT $restore_dir | _dir_filter | _check_quota_diff
1365 # Check out the dump inventory
1369 $XFSDUMP_PROG $_dump_debug -I | tee -a $seqres.full | _dump_filter_main
1373 # Do the xfsinvutil cmd with debug and filters
1374 # Need to set variable: "$middate" to the invutil date
1379 echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seqres.full
1380 $XFSINVUTIL_PROG $_invutil_debug $* -M $host:$SCRATCH_MNT "$middate" \
1381 | tee -a $seqres.full | _invutil_filter
1385 # ensure we can find the user quota msg if user quotas are on
1386 # ensure we can find the group quota msg if group quotas are on
1396 $here/src/feature -U $SCRATCH_DEV && uquota=1
1397 $here/src/feature -G $SCRATCH_DEV && gquota=1
1398 $here/src/feature -P $SCRATCH_DEV && pquota=1
1400 $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v pquota=$pquota \
1401 -v full=$seqres.full -v usermsg="$usermsg" \
1402 -v groupmsg="$groupmsg" -v projectmsg="$projectmsg" '
1404 print "Found project quota:", $0 >>full
1407 print "Found extra:", $0
1412 print "Found group quota:", $0 >>full
1415 print "Found extra:", $0
1420 print "Found user quota:", $0 >>full
1423 print "Found extra:", $0
1427 $0 ~ "Restore Status: INCOMPLETE" {
1432 if (uquota && !found_uquota && !incomplete) {
1433 print "Missing user quota msg:", usermsg
1435 if (gquota && !found_gquota && !incomplete) {
1436 print "Missing group quota msg:", groupmsg
1438 if (pquota && !found_pquota && !incomplete) {
1439 print "Missing project quota msg:", projectmsg
1446 # xfsrestore: 3 directories and 40 entries processed
1448 # num entries needs to be reduced by num quota file(s)
1450 _check_quota_entries()
1455 $here/src/feature -U $SCRATCH_DEV && uquota=1
1456 $here/src/feature -G $SCRATCH_DEV && gquota=1
1457 $here/src/feature -P $SCRATCH_DEV && pquota=1
1458 $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v pquota=$pquota '
1459 /entries processed/ {
1469 # xfsdump: saving user quota information for: SCRATCH_MNT
1470 # xfsdump: saving group quota information for: SCRATCH_MNT
1471 # xfsdump: saving project quota information for: SCRATCH_MNT
1472 # xfsrestore: user quota information written to ...'
1473 # xfsrestore: group quota information written to ...'
1474 # xfsrestore: project quota information written to ...'
1475 # xfsrestore: use 'xfs_quota' to restore quotas
1477 _check_quota_dumprestore()
1479 _check_quota 'user quota information' \
1480 'group quota information' \
1481 'project quota information' | \
1482 sed "/xfsrestore:.*use 'xfs_quota' to restore quotas/d"
1487 # Only in RESTORE_DIR: xfsdump_quotas
1488 # Only in RESTORE_DIR: xfsdump_quotas_group
1489 # Only in RESTORE_DIR: xfsdump_quotas_project
1493 _check_quota 'Only in RESTORE_DIR: xfsdump_quotas' \
1494 'Only in RESTORE_DIR: xfsdump_quotas_group' \
1495 'Only in RESTORE_DIR: xfsdump_quotas_proj'
1499 # Look for the quota file in the output
1500 # Ensure that it is there if it should be
1501 # Filter it out so that the output is always the same
1502 # even with no quotas
1506 _check_quota 'xfsdump_quotas' 'xfsdump_quotas_group' 'xfsdump_quotas_proj'
1513 local ndirs=$(find $dir -type d | wc -l)
1514 local nents=$(find $dir | wc -l)
1516 echo "$ndirs directories and $nents entries"
1519 _count_dumpdir_files()
1521 _count_dir_files $dump_dir
1524 _count_restoredir_files()
1526 _count_dir_files $restore_dir/$dump_sdir
1530 # make sure this script returns success