]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/truncate-test
Pull regression truncate-test from Branch-9.1
[bacula/bacula] / regress / tests / truncate-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # Test truncate command (replaces old purge action=truncate ...)
7 #
8 #
9 TestName="truncate-test"
10 JobName=FIFOTest
11 . scripts/functions
12
13 cwd=`pwd`
14 scripts/cleanup
15 scripts/copy-test-confs
16
17 echo $src > $tmp/file-list
18
19 sed 's/Pool Type = Backup/Pool Type = Backup; ActionOnPurge = Truncate/' $conf/bacula-dir.conf > $tmp/1
20 cp $tmp/1 $conf/bacula-dir.conf
21
22 start_test
23
24 cat >tmp/bconcmds <<END_OF_DATA
25 @$out /dev/null
26 messages
27 @$out $tmp/log1.out
28 label storage=File volume=TestVolume001
29 @########################################################
30 @# Run a first job on TestVolume001
31 @########################################################
32 run level=full job=$JobName yes
33 wait
34 messages
35 @#@$out $tmp/log2.out
36 @#restore where=${cwd}/tmp/bacula-restores select all storage=File done
37 @#yes
38 @#wait
39 @#messages
40 @#########################################################
41 @# Run a second job on TestVolume002
42 @#########################################################
43 @$out $tmp/log3.out
44 label storage=File volume=TestVolume002
45 update volume=TestVolume001 volstatus=Used
46 messages
47 show pool
48 @$out $tmp/log1.out
49 run level=full job=$JobName yes
50 wait
51 messages
52 @#########################################################
53 @# Run a 3th job on TestVolume003
54 @#########################################################
55 @$out $tmp/log3.out
56 update volume=TestVolume002 volstatus=Full
57 label storage=File volume=TestVolume003
58 messages
59 show pool
60 @$out $tmp/log1.out
61 run level=full job=$JobName yes
62 wait
63 messages
64 @#########################################################
65 @# Run a 4th job
66 @#########################################################
67 @$out $tmp/log5.out
68 update volume=TestVolume003 volstatus=Used
69 label storage=File volume=TestVolume004
70 messages
71 @$out $tmp/log1.out
72 run level=full job=$JobName yes
73 wait
74 messages
75 list volume
76 @$out $tmp/log1.out
77 update volume=TestVolume004 volstatus=Used
78 label storage=File volume=TestVolume005
79 run level=full job=$JobName yes
80 wait
81 messages
82 @$out $tmp/log7.out
83 @#########################################################
84 @# test that we cannot truncate a volume that is not purged
85 @# TestVolume001 - Used
86 @# TestVolume002 - Full
87 @# TestVolume005 - Append
88 @#########################################################
89 llist volume=TestVolume001
90 llist volume=TestVolume002
91 llist volume=TestVolume005
92 @exec "du -s -b $tmp/TestVolume001"
93 truncate volume=TestVolume001 storage=File
94 truncate volume=TestVolume002 storage=File
95 truncate volume=TestVolume005 storage=File
96 @exec "du -s -b $tmp/TestVolume001"
97 messages
98 @#########################################################
99 @# tests
100 @#########################################################
101 update volume=TestVolume002 actiononpurge=none
102 purge volume=TestVolume001
103 purge volume=TestVolume002
104 purge volume=TestVolume003
105 purge volume=TestVolume004
106 list volume
107 sql
108 select VolumeName, VolStatus, ActionOnPurge FROM Media;
109
110 setdebug level=100 director
111 messages
112 wait
113 quit
114 END_OF_DATA
115
116 run_bacula
117 check_for_zombie_jobs storage=File
118
119 cd $tmp
120
121 # First check if volumes which were not purged were truncated
122 TV1=`grep "The volume \"TestVolume001\" has been truncated" $tmp/log7.out`
123 TV2=`grep "The volume \"TestVolume002\" has been truncated" $tmp/log7.out`
124 TV3=`grep "The volume \"TestVolume005\" has been truncated" $tmp/log7.out`
125 if test "x$TV1" != "x" -o "x$TV2" != "x" -o "x$TV3" != "x"
126 then
127   # error, the volumes in non purge status should not be truncated
128   dstat=1
129   print_debug "ERROR 1: Volumes not in Purged status Truncated!!!"
130 fi
131
132 if test "$debug" -eq 1 ; then
133   echo "Volume sizes before truncate ..."
134   ls -l TestVolume*
135 fi
136
137 print_debug "Check all media"
138
139 for i in 1 2 3 4 5 ; do
140   size=`du -b TestVolume00$i|cut -f1`
141   if test $size -lt 5000 ; then
142      print_debug "ERROR 2: Volume TestVolum00$i is too small $size"
143      ls -l TestVolume00$i
144      estat=2
145   fi
146 done
147
148 cd $cwd
149
150 echo "truncate volume=TestVolume001 storage=File" > $tmp/bconcmds
151 run_bconsole
152
153 cd $tmp
154
155 if test "$debug" -eq 1 ; then
156   echo "Volume TestVolume001 should be truncated ..."
157   ls -l TestVolume*
158 fi
159
160 for i in  2 3 4 5 ; do
161   size=`du -b TestVolume00$i|cut -f1`
162   if test $size -lt 5000 ; then
163      print_debug "ERROR 3: Volume TestVolume00$i is too small $size"
164      ls -l TestVolume00$i
165      estat=3
166   fi
167 done
168 for i in 1 ; do
169   size=`du -b TestVolume00${i} | cut -f1`
170   if test $size -gt 5000 ; then
171      print_debug "ERROR 4: Volume TestVolume00$i is not truncated (too big) $size"
172      ls -l TestVolume00$i
173      estat=4
174   fi
175 done
176
177 cd $cwd
178
179 echo "truncate volume storage=File" > $tmp/bconcmds
180 run_bconsole
181
182 cd $tmp
183 if test "$debug" -eq 1 ; then
184   echo "Volumes 001, 003, and 004 should be truncated ..."
185   ls -l TestVolume*
186 fi
187
188 for i in 2 5 ; do
189   size=`du -b TestVolume00$i | cut -f1`
190   if test $size -lt 5000 ; then
191      print_debug "ERROR 5: Volume TestVolume00$i is too small $size"
192      ls -l TestVolume00$i
193      estat=5
194   fi
195 done
196 for i in 1 3 4 ; do
197   size=`du -b TestVolume00$i | cut -f1`
198   if test $size -gt 5000 ; then
199      print_debug "ERROR 6: Volume TestVolume00$i is not truncated (too big) $size"
200      ls -l TestVolume00$i
201      estat=6
202   fi
203 done
204
205 cd $cwd
206
207 cat <<END_OF_DATA > $tmp/bconcmds
208 @#########################################################
209 @# Display catalog settings for Pool and Media
210 @#########################################################
211 @$out $tmp/log4.out
212 setdebug level=0 director
213 sql
214 select VolumeName, ActionOnPurge FROM Media;
215 select Name, ActionOnPurge FROM Pool;
216
217 wait
218 messages
219 quit
220 END_OF_DATA
221
222 run_bconsole
223
224 stop_bacula
225
226 touch $tmp/log2.out
227 check_two_logs
228
229 print_debug "Test if Pool record is ok"
230 r=`awk '/Default/ { print $4 }' $tmp/log4.out`
231 if [ "$r" != 1 ]; then
232     print_debug "ERROR 5: ActionOnPurge on Pool record should be 1 ($r)"
233     estat=5
234 fi
235
236 print_debug "Test TestVolume001 if Media record is ok"
237 r=`awk '/TestVolume001/ { print $4 }' $tmp/log4.out`
238 if [ "$r" != 1 ]; then
239     print_debug "ERROR 6: ActionOnPurge on Media record should be 1"
240     estat=6
241 fi
242
243 print_debug "Test TestVolume002 if Media record is ok"
244 r=`awk '/TestVolume002/ { print $4 }' $tmp/log4.out`
245 if [ "$r" != 0 ]; then
246     print_debug "ERROR 7: ActionOnPurge on Media record should be 0"
247     estat=7
248 fi
249
250 # Now test if the truncate command truncates labeled Volumes
251 cat >tmp/bconcmds <<END_OF_DATA
252 truncate allpools storage=File
253 messages
254 wait
255 @$out $tmp/log6.out
256 @# These truncates should not truncate any Volumes
257 truncate allpools storage=File
258 truncate allpools storage=File
259 truncate allpools storage=File
260 wait
261 messages
262 quit
263 END_OF_DATA
264
265 run_bacula
266 stop_bacula
267
268 grep "has been truncated" $tmp/log6.out >$tmp/log8.out
269 if [ $? = 0 ] ; then
270     cat $tmp/log8.out
271     print_debug "ERROR 8: truncated volumes are truncated multiple times"
272     estat=8
273 fi
274
275 end_test