This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
/
action-on-purge-test
executable file
·199 lines (171 loc) · 5.13 KB
/
action-on-purge-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/sh
#
#
TestName="action-on-purge-test"
JobName=FIFOTest
. scripts/functions
cwd=`pwd`
scripts/cleanup
scripts/copy-test-confs
echo $src > $tmp/file-list
sed 's/Pool Type = Backup/Pool Type = Backup; ActionOnPurge = Truncate/' $conf/bareos-dir.conf > $tmp/1
cp $tmp/1 $conf/bareos-dir.conf
start_test
cat >tmp/bconcmds <<END_OF_DATA
@$out /dev/null
messages
@$out $tmp/log1.out
label storage=File volume=TestVolume001
@########################################################
@# Run a first job on TestVolume001
@########################################################
run level=full job=$JobName yes
wait
messages
@#@$out $tmp/log2.out
@#restore where=${cwd}/tmp/bareos-restores select all storage=File done
@#yes
@#wait
@#messages
@#########################################################
@# Run a second job on TestVolume002
@#########################################################
@$out $tmp/log3.out
update volume=TestVolume001 volstatus=Used
label storage=File volume=TestVolume002
messages
show pool
@$out $tmp/log1.out
run level=full job=$JobName yes
wait
messages
@#########################################################
@# Run a 3th job on TestVolume003
@#########################################################
@$out $tmp/log3.out
update volume=TestVolume002 volstatus=Used
label storage=File volume=TestVolume003
messages
show pool
@$out $tmp/log1.out
run level=full job=$JobName yes
wait
messages
@#########################################################
@# Run a 4th job
@#########################################################
@$out $tmp/log5.out
update volume=TestVolume003 volstatus=Used
label storage=File volume=TestVolume004
messages
@$out $tmp/log1.out
run level=full job=$JobName yes
wait
messages
@#########################################################
@# Run a 5th job
@#########################################################
@$out $tmp/log1.out
update volume=TestVolume004 volstatus=Used
label storage=File volume=TestVolume005
run level=full job=$JobName yes
wait
messages
list volume
END_OF_DATA
run_bareos
check_for_zombie_jobs storage=File
cat >tmp/bconcmds <<END_OF_DATA
@$out $tmp/log6.out
@#########################################################
@# purge media 1-4, without action.
@#########################################################
update volume=TestVolume002 actiononpurge=none
purge volume=TestVolume001
purge volume=TestVolume002
purge volume=TestVolume003
purge volume=TestVolume004
list volume
sql
select VolumeName, VolStatus, ActionOnPurge FROM Media;
setdebug level=100 director
quit
END_OF_DATA
run_bconsole
print_debug "Check if all media contain data"
perl -Mscripts::functions -e 'foreach $i (1..5){check_min_volume_size(4096,"TestVolume00$i")}'
if [ $? != 0 ]; then
print_debug "`ls -l $tmp`"
set_error "not all volumes contain data"
fi
cat >tmp/bconcmds <<END_OF_DATA
@#########################################################
@# purge volume 1 and perform action.
@#########################################################
purge volume=TestVolume001 action storage=File
END_OF_DATA
run_bconsole
perl -Mscripts::functions -e '
check_min_volume_size(4096, "TestVolume002","TestVolume003","TestVolume004","TestVolume005");
check_max_volume_size(4096, "TestVolume001")'
if [ $? != 0 ]; then
print_debug "`ls -l $tmp/TestVolume*`"
set_error "purging volume 1 did fail"
fi
# V1: already truncated
# V2: action=None, no action should be performed
# V3: truncate
# V4: truncate
# V5: not purged. Purge is only performed if a specific volume is given.
# However, truncate is performed non the less (on a purged volume).
cat >tmp/bconcmds <<END_OF_DATA
@#########################################################
@# purge all volumes (1-5) and perform action.
@# This should affect volume 3 and 4.
@#########################################################
purge volume action storage=File
END_OF_DATA
run_bconsole
sleep 1;
perl -Mscripts::functions -e '
check_min_volume_size(4096, "TestVolume002", "TestVolume005");
check_max_volume_size(4096, "TestVolume001", "TestVolume003", "TestVolume004")'
if [ $? != 0 ]; then
print_debug "`ls -l $tmp/TestVolume*`"
set_error "purging all volumes did not succeed."
fi
cat <<END_OF_DATA > $tmp/bconcmds
@#########################################################
@# Display catalog settings for Pool and Media
@#########################################################
@$out $tmp/log4.out
setdebug level=0 director
sql
select VolumeName, ActionOnPurge FROM Media;
select Name, ActionOnPurge FROM Pool;
wait
quit
END_OF_DATA
run_bconsole
stop_bareos
touch $tmp/log2.out
check_two_logs
print_debug "Test if Pool record is ok"
r=`awk '/Default/ { print $4 }' $tmp/log4.out`
if [ "$r" != 1 ]; then
print_debug "ActionOnPurge on Pool record should be 1 ($r)"
estat=2
fi
print_debug "Test TestVolume001 if Media record is ok"
r=`awk '/TestVolume001/ { print $4 }' $tmp/log4.out`
if [ "$r" != 1 ]; then
print_debug "ActionOnPurge on Media record should be 1"
estat=2
fi
print_debug "Test TestVolume002 if Media record is ok"
r=`awk '/TestVolume002/ { print $4 }' $tmp/log4.out`
if [ "$r" != 0 ]; then
print_debug "ActionOnPurge on Media record should be 0"
estat=2
fi
end_test