shadow_copy2: Add test case for snapprefix and delimiter
[Samba.git] / source3 / script / tests / test_shadow_copy.sh
blob45d9cf1ef9254343acdf4b9a2ac27f51727dee67
1 #!/bin/bash
3 # Blackbox test for shadow_copy2 VFS.
6 if [ $# -lt 7 ]; then
7 cat <<EOF
8 Usage: test_shadow_copy SERVER SERVER_IP DOMAIN USERNAME PASSWORD WORKDIR SMBCLIENT
9 EOF
10 exit 1;
13 SERVER=${1}
14 SERVER_IP=${2}
15 DOMAIN=${3}
16 USERNAME=${4}
17 PASSWORD=${5}
18 WORKDIR=${6}
19 SMBCLIENT=${7}
20 shift 7
21 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
22 ADDARGS="$*"
24 incdir=`dirname $0`/../../../testprogs/blackbox
25 . $incdir/subunit.sh
27 SNAPSHOTS[0]='@GMT-2015.10.31-19.40.30'
28 SNAPSHOTS[1]='@GMT-2016.10.31-19.40.30'
29 SNAPSHOTS[2]='@GMT-2017.10.31-19.40.30'
30 SNAPSHOTS[3]='@GMT-2018.10.31-19.40.30'
31 SNAPSHOTS[4]='@GMT-2019.10.31-19.40.30'
32 SNAPSHOTS[5]='@GMT-2020.10.31-19.40.30'
33 SNAPSHOTS[6]='@GMT-2021.10.31-19.40.30'
34 SNAPSHOTS[7]='@GMT-2022.10.31-19.40.30'
35 SNAPSHOTS[8]='@GMT-2023.10.31-19.40.30'
36 SNAPSHOTS[9]='@GMT-2024.10.31-19.40.30'
37 SNAPSHOTS[10]='@GMT-2010-11-11'
38 SNAPSHOTS[11]='@GMT-2011.11.11-11.40.30'
39 SNAPSHOTS[12]='snap@GMT-2012.11.11-11.40.30'
40 SNAPSHOTS[13]='@GMT-2013.11.11-11_40_33-snap'
41 SNAPSHOTS[14]='@GMT-2014.11.11-11.40.30'
42 SNAPSHOTS[15]='daily@GMT-2015.11.11-11.40.30'
43 SNAPSHOTS[16]='snap_GMT-2016.11.11-11.40.30'
44 SNAPSHOTS[17]='sysp_GMT-2017.11.11-11.40.30'
45 SNAPSHOTS[18]='monthly@GMT-2018.11.11-11.40.30'
46 SNAPSHOTS[19]='straps_GMT-2019.11.11-11.40.33'
48 # build a hierarchy of files, symlinks, and directories
49 build_files()
51 local rootdir
52 local prefix
53 local version
54 local destdir
55 rootdir=$1
56 prefix=$2
57 version=$3
58 if [ -n "$prefix" ] ; then
59 destdir=$rootdir/$prefix
60 else
61 destdir=$rootdir
64 mkdir -p $destdir
65 if [ "$version" = "latest" ] ; then
66 #non-snapshot files
67 # for non-snapshot version, create legit files
68 # so that wide-link checks focus on snapshot files
69 touch $destdir/foo
70 mkdir -p $destdir/bar
71 touch $destdir/bar/baz
72 touch $destdir/bar/lfoo
73 touch $destdir/bar/letcpasswd
74 touch $destdir/bar/loutside
75 elif [ "$version" = "fullsnap" ] ; then
76 #snapshot files
77 touch $destdir/foo
78 mkdir -p $destdir/bar
79 touch $destdir/bar/baz
80 ln -fs ../foo $destdir/bar/lfoo
81 ln -fs /etc/passwd $destdir/bar/letcpasswd
82 ln -fs ../../outside $destdir/bar/loutside
83 touch `dirname $destdir`/outside
84 else #subshare snapshot - at bar
85 touch $destdir/baz
86 ln -fs ../foo $destdir/lfoo
87 ln -fs /etc/passwd $destdir/letcpasswd
88 ln -fs ../../outside $destdir/loutside
89 touch `dirname $destdir`/../outside
94 # build a snapshots directory
95 build_snapshots()
97 local where #where to build snapshots
98 local prefix #prefix from snapshot dir to share root
99 local start #timestamp index of first snapshot
100 local end #timestamp index of last snapshot
101 local sub #creat a snapshot of subtree of share
102 local snapdir
103 local snapname
104 local i
105 local version
107 where=$1
108 prefix=$2
109 start=$3
110 end=$4
111 sub=$5
113 snapdir=$where/.snapshots
114 mkdir -p $snapdir
116 version="fullsnap"
117 if [ "$sub" = "1" ] ; then
118 version="subsnap"
119 prefix=""
121 # a valid link target for an inner symlink -
122 # the link is not broken yet should be blocked
123 # by wide link checks
124 touch $snapdir/foo
127 for i in `seq $start $end` ; do
128 snapname=${SNAPSHOTS[$i]}
129 mkdir $snapdir/$snapname
130 build_files $snapdir/$snapname "$prefix" $version
131 done
134 # Test listing previous versions of a file
135 test_count_versions()
137 local share
138 local path
139 local expected_count
140 local versions
142 share=$1
143 path=$2
144 expected_count=$3
145 versions=`$SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/$share" -I $SERVER_IP -c "allinfo $path" | grep "^create_time:" | wc -l`
146 if [ "$versions" = "$expected_count" ] ; then
147 true
148 else
149 echo "expected $expected_count versions of $path, got $versions"
150 false
154 # Test fetching a previous version of a file
155 test_fetch_snap_file()
157 local share
158 local path
159 local snapidx
161 share=$1
162 path=$2
163 snapidx=$3
164 $SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/$share" -I $SERVER_IP \
165 -c "get ${SNAPSHOTS[$snapidx]}/$path $WORKDIR/foo"
168 test_shadow_copy_fixed()
170 local share #share to contact
171 local where #where to place snapshots
172 local prefix #prefix to files inside snapshot
173 local msg
174 local allow_wl
175 local ncopies_allowd
176 local ncopies_blocked
178 share=$1
179 where=$2
180 prefix=$3
181 msg=$4
182 allow_wl=$5
184 ncopies_allowed=4
185 ncopies_blocked=1
186 if [ -n "$allow_wl" ] ; then
187 ncopies_blocked=4
190 #delete snapshots from previous tests
191 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
192 build_snapshots $WORKDIR/$where "$prefix" 0 2
194 testit "$msg - regular file" \
195 test_count_versions $share foo $ncopies_allowed || \
196 failed=`expr $failed + 1`
198 testit "$msg - regular file in subdir" \
199 test_count_versions $share bar/baz $ncopies_allowed || \
200 failed=`expr $failed + 1`
202 testit "$msg - local symlink" \
203 test_count_versions $share bar/lfoo $ncopies_allowed || \
204 failed=`expr $failed + 1`
206 testit "$msg - abs symlink outside" \
207 test_count_versions $share bar/letcpasswd $ncopies_blocked || \
208 failed=`expr $failed + 1`
210 testit "$msg - rel symlink outside" \
211 test_count_versions $share bar/loutside $ncopies_blocked || \
212 failed=`expr $failed + 1`
215 test_shadow_copy_everywhere()
217 local share #share to contact
219 share=$1
221 #delete snapshots from previous tests
222 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
223 build_snapshots "$WORKDIR/mount" "base/share" 0 0
224 build_snapshots "$WORKDIR/mount/base" "share" 1 2
225 build_snapshots "$WORKDIR/mount/base/share" "" 3 5
226 build_snapshots "$WORKDIR/mount/base/share/bar" "" 6 9 1
228 testit "snapshots in each dir - regular file" \
229 test_count_versions $share foo 4 || \
230 failed=`expr $failed + 1`
232 testit "snapshots in each dir - regular file in subdir" \
233 test_count_versions $share bar/baz 5 || \
234 failed=`expr $failed + 1`
236 testit "snapshots in each dir - local symlink (but outside snapshot)" \
237 test_count_versions $share bar/lfoo 1 || \
238 failed=`expr $failed + 1`
240 testit "snapshots in each dir - abs symlink outside" \
241 test_count_versions $share bar/letcpasswd 1 || \
242 failed=`expr $failed + 1`
244 testit "snapshots in each dir - rel symlink outside" \
245 test_count_versions $share bar/loutside 1 || \
246 failed=`expr $failed + 1`
248 #the previous versions of the file bar/lfoo points to are outside its
249 #snapshot, and are not reachable. However, but previous versions
250 #taken at different, non-overlapping times higher up the
251 #hierarchy are still reachable.
252 testit "fetch a previous version of a regular file" \
253 test_fetch_snap_file $share "bar/baz" 6 || \
254 failed=`expr $failed + 1`
256 testit_expect_failure "fetch a (non-existent) previous version of a symlink" \
257 test_fetch_snap_file $share "bar/lfoo" 6 || \
258 failed=`expr $failed + 1`
260 testit "fetch a previous version of a symlink via browsing (1)" \
261 test_fetch_snap_file $share "bar/lfoo" 0 || \
262 failed=`expr $failed + 1`
264 testit "fetch a previous version of a symlink via browsing (2)" \
265 test_fetch_snap_file $share "bar/lfoo" 1 || \
266 failed=`expr $failed + 1`
268 testit "fetch a previous version of a symlink via browsing (3)" \
269 test_fetch_snap_file $share "bar/lfoo" 3 || \
270 failed=`expr $failed + 1`
274 test_shadow_copy_format()
276 local share #share to contact
277 local where #where to place snapshots
278 local prefix #prefix to files inside snapshot
279 local ncopies_allowd
280 local msg
282 share=$1
283 where=$2
284 prefix=$3
285 ncopies_allowed=$4
286 msg=$5
288 #delete snapshots from previous tests
289 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
290 build_snapshots $WORKDIR/$where "$prefix" 10 19
292 testit "$msg - regular file" \
293 test_count_versions $share foo $ncopies_allowed || \
294 failed=`expr $failed + 1`
297 #build "latest" files
298 build_files $WORKDIR/mount base/share "latest"
300 failed=0
302 # a test with wide links allowed - also to verify that what's later
303 # being blocked is a result of server security measures and not
304 # a testing artifact.
305 test_shadow_copy_fixed shadow_wl mount base/share "shadow copies with wide links allowed" 1
307 # tests for a fixed snapshot location
308 test_shadow_copy_fixed shadow1 mount base/share "full volume snapshots mounted under volume"
309 test_shadow_copy_fixed shadow2 . base/share "full volume snapshots mounted outside volume"
310 test_shadow_copy_fixed shadow3 mount/base share "sub volume snapshots mounted under snapshot point"
311 test_shadow_copy_fixed shadow4 . share "sub volume snapshots mounted outside"
312 test_shadow_copy_fixed shadow5 mount/base/share "" "full volume snapshots and share mounted under volume"
313 test_shadow_copy_fixed shadow6 . "" "full volume snapshots and share mounted outside"
314 test_shadow_copy_fixed shadow8 . share "logical snapshot layout"
316 # tests for snapshot everywhere - one snapshot location
317 test_shadow_copy_fixed shadow7 mount base/share "'everywhere' full volume snapshots"
318 test_shadow_copy_fixed shadow7 mount/base share "'everywhere' sub volume snapshots"
319 test_shadow_copy_fixed shadow7 mount/base/share "" "'everywhere' share snapshots"
321 # a test for snapshots everywhere - multiple snapshot locations
322 test_shadow_copy_everywhere shadow7
324 # tests for testing snapshot selection via shadow:format
325 test_shadow_copy_format shadow_fmt0 mount/base share 3 "basic shadow:format test"
326 test_shadow_copy_format shadow_fmt1 mount/base share 2 "shadow:format with only date"
327 test_shadow_copy_format shadow_fmt2 mount/base share 2 "shadow:format with some prefix"
328 test_shadow_copy_format shadow_fmt3 mount/base share 2 "shadow:format with modified format"
329 test_shadow_copy_format shadow_fmt4 mount/base share 3 "shadow:format with snapprefix"
330 test_shadow_copy_format shadow_fmt5 mount/base share 6 "shadow:format with delimiter"
332 exit $failed