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=Full
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 @# 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"
98 @#########################################################
100 @#########################################################
101 update volume=TestVolume002 actiononpurge=none
102 purge volume=TestVolume001
103 purge volume=TestVolume002
104 purge volume=TestVolume003
105 purge volume=TestVolume004
108 select VolumeName, VolStatus, ActionOnPurge FROM Media;
110 setdebug level=100 director
117 check_for_zombie_jobs storage=File
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"
127 # error, the volumes in non purge status should not be truncated
129 print_debug "ERROR 1: Volumes not in Purged status Truncated!!!"
132 if test "$debug" -eq 1 ; then
133 echo "Volume sizes before truncate ..."
137 print_debug "Check all media"
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"
150 echo "truncate volume=TestVolume001 storage=File" > $tmp/bconcmds
155 if test "$debug" -eq 1 ; then
156 echo "Volume TestVolume001 should be truncated ..."
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"
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"
179 echo "truncate volume storage=File" > $tmp/bconcmds
183 if test "$debug" -eq 1 ; then
184 echo "Volumes 001, 003, and 004 should be truncated ..."
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"
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"
207 cat <<END_OF_DATA > $tmp/bconcmds
208 @#########################################################
209 @# Display catalog settings for Pool and Media
210 @#########################################################
212 setdebug level=0 director
214 select VolumeName, ActionOnPurge FROM Media;
215 select Name, ActionOnPurge FROM Pool;
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)"
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"
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"
250 # Now test if the truncate command truncates labeled Volumes
251 cat >tmp/bconcmds <<END_OF_DATA
252 truncate allpools storage=File
256 @# These truncates should not truncate any Volumes
257 truncate allpools storage=File
258 truncate allpools storage=File
259 truncate allpools storage=File
268 grep "has been truncated" $tmp/log6.out >$tmp/log8.out
271 print_debug "ERROR 8: truncated volumes are truncated multiple times"