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 @#########################################################
85 @#########################################################
86 update volume=TestVolume002 actiononpurge=none
87 purge volume=TestVolume001
88 purge volume=TestVolume002
89 purge volume=TestVolume003
90 purge volume=TestVolume004
93 select VolumeName, VolStatus, ActionOnPurge FROM Media;
95 setdebug level=100 director
101 check_for_zombie_jobs storage=File
104 if test "$debug" -eq 1 ; then
105 echo "Volume sizes before truncate ..."
109 print_debug "Check all media"
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"
122 echo "truncate volume=TestVolume001 storage=File" > $tmp/bconcmds
127 if test "$debug" -eq 1 ; then
128 echo "Volume TestVolume001 should be truncated ..."
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"
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"
151 echo "truncate volume storage=File" > $tmp/bconcmds
155 if test "$debug" -eq 1 ; then
156 echo "Volumes 001, 003, and 004 should be truncated ..."
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"
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"
179 cat <<END_OF_DATA > $tmp/bconcmds
180 @#########################################################
181 @# Display catalog settings for Pool and Media
182 @#########################################################
184 setdebug level=0 director
186 select VolumeName, ActionOnPurge FROM Media;
187 select Name, ActionOnPurge FROM Pool;
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)"
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"
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"