3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # Test truncate command (replaces old purge action=truncate ...)
9 TestName="truncate-test"
15 scripts/copy-test-confs
17 echo $src > $tmp/file-list
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
24 cat >tmp/bconcmds <<END_OF_DATA
28 label storage=File volume=TestVolume001
29 @########################################################
30 @# Run a first job on TestVolume001
31 @########################################################
32 run level=full job=$JobName yes
36 @#restore where=${cwd}/tmp/bacula-restores select all storage=File done
40 @#########################################################
41 @# Run a second job on TestVolume002
42 @#########################################################
44 label storage=File volume=TestVolume002
45 update volume=TestVolume001 volstatus=Used
49 run level=full job=$JobName yes
52 @#########################################################
53 @# Run a 3th job on TestVolume003
54 @#########################################################
56 update volume=TestVolume002 volstatus=Used
57 label storage=File volume=TestVolume003
61 run level=full job=$JobName yes
64 @#########################################################
66 @#########################################################
68 update volume=TestVolume003 volstatus=Used
69 label storage=File volume=TestVolume004
72 run level=full job=$JobName yes
77 update volume=TestVolume004 volstatus=Used
78 label storage=File volume=TestVolume005
79 run level=full job=$JobName yes
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"
90 @#########################################################
92 @#########################################################
93 update volume=TestVolume002 actiononpurge=none
94 purge volume=TestVolume001
95 purge volume=TestVolume002
96 purge volume=TestVolume003
97 purge volume=TestVolume004
100 select VolumeName, VolStatus, ActionOnPurge FROM Media;
102 setdebug level=100 director
109 check_for_zombie_jobs storage=File
112 if test "$debug" -eq 1 ; then
113 echo "Volume sizes before truncate ..."
117 print_debug "Check all media"
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"
130 echo "truncate volume=TestVolume001 storage=File" > $tmp/bconcmds
135 if test "$debug" -eq 1 ; then
136 echo "Volume TestVolume001 should be truncated ..."
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"
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"
159 echo "truncate volume storage=File" > $tmp/bconcmds
163 if test "$debug" -eq 1 ; then
164 echo "Volumes 001, 003, and 004 should be truncated ..."
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"
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"
187 cat <<END_OF_DATA > $tmp/bconcmds
188 @#########################################################
189 @# Display catalog settings for Pool and Media
190 @#########################################################
192 setdebug level=0 director
194 select VolumeName, ActionOnPurge FROM Media;
195 select Name, ActionOnPurge FROM Pool;
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)"
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"
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"
230 # Now test if the truncate command truncates labeled Volumes
231 cat >tmp/bconcmds <<END_OF_DATA
232 truncate allpools storage=File
236 @# These truncates should not truncate any Volumes
237 truncate allpools storage=File
238 truncate allpools storage=File
239 truncate allpools storage=File
248 grep "has been truncated" $tmp/log6.out >$tmp/log7.out
251 print_debug "ERROR 8: truncated volumes are truncated multiple times"