common: use mount/umount helpers everywhere
[xfstests-dev.git] / tests / xfs / 065
1 #! /bin/bash
2 # FS QA Test No. 065
3 #
4 # Testing incremental dumps and cumulative restores with
5 # "adding, deleting, renaming, linking, and unlinking files and
6 #  directories".
7 # Do different operations for each level.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/dump
41
42 #
43 # list recursively the directory
44 #
45 # e.g. lstat output: src/lstat64 31056 -rwxr-xr-x 38403,0
46 # Don't print out sizes of directories - which can vary - overwrite with XXX.
47 #
48 _list_dir()
49 {
50     __dir=$1
51     find $__dir  -exec $here/src/lstat64 -t {} \; |\
52     sed -e 's/.*dumpdir/dumpdir/' -e '/^dumpdir /d' |\
53     sed -e 's/.*restoredir/restoredir/' -e '/^restoredir /d' |\
54     egrep -v 'housekeeping|dirattr|dirextattr|namreg|state|tree' |\
55     awk '$3 ~ /^d/ { $2 = "XXX" } {print}' |\
56     LC_COLLATE=POSIX sort
57
58
59 # real QA test starts here
60 _supported_fs xfs
61 _supported_os IRIX Linux
62
63 #
64 # too much hassle to get output matching with quotas turned on
65 # so don't run it
66 #
67 _scratch_unmount 2>/dev/null
68 _scratch_mount
69 $here/src/feature -U $SCRATCH_DEV && \
70         _notrun "UQuota enabled, test needs controlled xfsdump output"
71 $here/src/feature -G $SCRATCH_DEV && \
72         _notrun "GQuota enabled, test needs controlled xfsdump output"
73 $here/src/feature -P $SCRATCH_DEV && \
74         _notrun "PQuota enabled, test needs controlled xfsdump output"
75 _scratch_unmount
76
77 #
78 # adding      - touch/echo, mkdir
79 # deleting    - rm, rmdir
80 # renaming    - mv
81 # linking     - ln
82 # unlinking   - rm
83 # files and directories
84 #
85
86 _wipe_fs
87 mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
88 cd $dump_dir
89
90 echo "Do the incremental dumps"
91 i=0
92 num_dumps=8 # do some extra to ensure nothing changes
93 while [ $i -le $num_dumps ]; do
94     cd $dump_dir
95     case $i in
96         0)
97             # adding
98             echo 'add0' >addedfile0
99             echo 'add1' >addedfile1
100             echo 'add2' >addedfile2
101             echo 'add3' >addedfile3
102             mkdir addeddir1
103             mkdir addeddir2
104             mkdir addeddir3
105             mkdir addeddir4
106             echo 'add4' >addeddir3/addedfile4
107             echo 'add5' >addeddir4/addedfile5
108             ;;
109         1)
110             # deleting
111             rm addedfile2
112             rmdir addeddir2
113             rm -rf addeddir3
114             ;;
115         2)
116             # renaming
117             mv addedfile1 addedfile2 # rename to previous existing file
118             mv addeddir4/addedfile5 addeddir4/addedfile4
119             mv addeddir4 addeddir6
120             mv addeddir1 addeddir2 # rename to previous existing dir
121             ;;
122         3)
123             # linking
124             ln addedfile0 linkfile0
125             ln addedfile0 linkfile0_1  # have a 2nd link to file
126             ln addedfile2 linkfile2
127             ln addeddir6/addedfile4 linkfile64
128             ;;
129         4)
130             # unlinking
131             rm linkfile0  # remove a link
132             rm addedfile2 # remove original link
133             rm linkfile64  # remove link
134             rm addeddir6/addedfile4 # remove last link
135             ;;
136         5)  # link first - then onto 6)
137             rm -rf *
138             echo 'add6' >addedfile6
139             ln addedfile6 linkfile6_1
140             ln addedfile6 linkfile6_2
141             ln addedfile6 linkfile6_3
142             ;;
143         6)  # then move the inode that the links point to
144             mv addedfile6 addedfile6_mv
145             rm linkfile6_1
146             rm linkfile6_2
147             rm linkfile6_3
148             ln addedfile6_mv linkfile6_mv_1
149             ln addedfile6_mv linkfile6_mv_2
150             ln addedfile6_mv linkfile6_mv_3
151             ;;
152     esac
153     cd $here
154     sleep 2
155     _stable_fs
156
157     echo "Listing of what files we have at level $i:"
158     _list_dir $dump_dir | tee $tmp.ls.$i
159
160     _do_dump_file -f $tmp.df.level$i -l $i
161     let i=$i+1
162 done
163
164 echo "Look at what files are contained in the inc. dump"
165 i=0
166 while [ $i -le $num_dumps ]; do
167     echo ""
168     echo "restoring from df.level$i"
169     _do_restore_toc -f $tmp.df.level$i
170     let i=$i+1
171 done
172
173 echo "Do the cumulative restores"
174 _prepare_restore_dir
175 i=0
176 while [ $i -le $num_dumps ]; do
177     echo ""
178     echo "restoring from df.level$i"
179     _do_restore_file_cum -f $tmp.df.level$i
180     echo "list restore_dir"
181     _list_dir $restore_dir | _check_quota_file | tee $tmp.restorals.$i
182     let i=$i+1
183 done
184
185 echo ""
186 echo "Do the ls comparison"
187 i=0
188 while [ $i -le $num_dumps ]; do
189     echo "Comparing ls of FS with restored FS at level $i"
190     diff -s $tmp.ls.$i $tmp.restorals.$i | sed "s#$tmp#TMP#g"
191     echo ""
192     let i=$i+1
193 done
194
195 # success, all done
196 status=0
197 exit