]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/truncate-test
79ef88da5c6665b3cd5dd4fc27462de27110387a
[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=Used
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 @#########################################################
86 @exec "du -s -b $tmp/TestVolume001"
87 truncate volume=TestVolume001  storage=File
88 @exec "du -s -b $tmp/TestVolume001"
89 messages
90 @#########################################################
91 @# tests
92 @#########################################################
93 update volume=TestVolume002 actiononpurge=none
94 purge volume=TestVolume001
95 purge volume=TestVolume002
96 purge volume=TestVolume003
97 purge volume=TestVolume004
98 list volume
99 sql
100 select VolumeName, VolStatus, ActionOnPurge FROM Media;
101
102 setdebug level=100 director
103 messages
104 wait
105 quit
106 END_OF_DATA
107
108 run_bacula
109 check_for_zombie_jobs storage=File
110
111 cd $tmp
112 if test "$debug" -eq 1 ; then
113   echo "Volume sizes before truncate ..."
114   ls -l TestVolume*
115 fi
116
117 print_debug "Check all media"
118
119 for i in 1 2 3 4 5 ; do
120   size=`du -b TestVolume00$i|cut -f1`
121   if test $size -lt 5000 ; then
122      print_debug "ERROR 2: Volume TestVolum00$i is too small $size"
123      ls -l TestVolume00$i
124      estat=2
125   fi
126 done
127
128 cd $cwd
129
130 echo "truncate volume=TestVolume001 storage=File" > $tmp/bconcmds
131 run_bconsole
132
133 cd $tmp
134
135 if test "$debug" -eq 1 ; then
136   echo "Volume TestVolume001 should be truncated ..."
137   ls -l TestVolume*
138 fi
139
140 for i in  2 3 4 5 ; do
141   size=`du -b TestVolume00$i|cut -f1`
142   if test $size -lt 5000 ; then
143      print_debug "ERROR 3: Volume TestVolume00$i is too small $size"
144      ls -l TestVolume00$i
145      estat=3
146   fi
147 done
148 for i in 1 ; do
149   size=`du -b TestVolume00${i} | cut -f1`
150   if test $size -gt 5000 ; then
151      print_debug "ERROR 4: Volume TestVolume00$i is not truncated (too big) $size"
152      ls -l TestVolume00$i
153      estat=4
154   fi
155 done
156
157 cd $cwd
158
159 echo "truncate volume storage=File" > $tmp/bconcmds
160 run_bconsole
161
162 cd $tmp
163 if test "$debug" -eq 1 ; then
164   echo "Volumes 001, 003, and 004 should be truncated ..."
165   ls -l TestVolume*
166 fi
167
168 for i in 2 5 ; do
169   size=`du -b TestVolume00$i | cut -f1`
170   if test $size -lt 5000 ; then
171      print_debug "ERROR 5: Volume TestVolume00$i is too small $size"
172      ls -l TestVolume00$i
173      estat=5
174   fi
175 done
176 for i in 1 3 4 ; do
177   size=`du -b TestVolume00$i | cut -f1`
178   if test $size -gt 5000 ; then
179      print_debug "ERROR 6: Volume TestVolume00$i is not truncated (too big) $size"
180      ls -l TestVolume00$i
181      estat=6
182   fi
183 done
184
185 cd $cwd
186
187 cat <<END_OF_DATA > $tmp/bconcmds
188 @#########################################################
189 @# Display catalog settings for Pool and Media
190 @#########################################################
191 @$out $tmp/log4.out
192 setdebug level=0 director
193 sql
194 select VolumeName, ActionOnPurge FROM Media;
195 select Name, ActionOnPurge FROM Pool;
196
197 wait
198 messages
199 quit
200 END_OF_DATA
201
202 run_bconsole
203
204 stop_bacula
205
206 touch $tmp/log2.out
207 check_two_logs
208
209 print_debug "Test if Pool record is ok"
210 r=`awk '/Default/ { print $4 }' $tmp/log4.out`
211 if [ "$r" != 1 ]; then
212     print_debug "ERROR 5: ActionOnPurge on Pool record should be 1 ($r)"
213     estat=5
214 fi
215
216 print_debug "Test TestVolume001 if Media record is ok"
217 r=`awk '/TestVolume001/ { print $4 }' $tmp/log4.out`
218 if [ "$r" != 1 ]; then
219     print_debug "ERROR 6: ActionOnPurge on Media record should be 1"
220     estat=6
221 fi
222
223 print_debug "Test TestVolume002 if Media record is ok"
224 r=`awk '/TestVolume002/ { print $4 }' $tmp/log4.out`
225 if [ "$r" != 0 ]; then
226     print_debug "ERROR 7: ActionOnPurge on Media record should be 0"
227     estat=7
228 fi
229
230 # Now test if the truncate command truncates labeled Volumes
231 cat >tmp/bconcmds <<END_OF_DATA
232 truncate allpools storage=File
233 messages
234 wait
235 @$out $tmp/log6.out
236 @# These truncates should not truncate any Volumes
237 truncate allpools storage=File
238 truncate allpools storage=File
239 truncate allpools storage=File
240 wait
241 messages
242 quit
243 END_OF_DATA
244
245 run_bacula
246 stop_bacula
247
248 grep "has been truncated" $tmp/log6.out >$tmp/log7.out
249 if [ $? = 0 ] ; then
250     cat $tmp/log7.out
251     print_debug "ERROR 8: truncated volumes are truncated multiple times"
252     estat=8
253 fi
254
255 end_test