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