1#!/bin/sh
2#
3#
4TestName="duplicate-job-test"
5. scripts/functions
6
7scripts/cleanup
8scripts/copy-test-confs
9
10# increase the maximum concurrent jobs for FD, SD and DIR
11perl -Mscripts::functions -e 'set_maximum_concurrent_jobs("$conf/bareos-dir.conf",100)'
12perl -Mscripts::functions -e 'set_maximum_concurrent_jobs("$conf/bareos-sd.conf",100)'
13perl -Mscripts::functions -e 'set_maximum_concurrent_jobs("$conf/bareos-fd.conf",100)'
14
15# extract a Job and add a runscript on it
16perl -Mscripts::functions \
17    -e "extract_resource('$conf/bareos-dir.conf', 'Job', 'CompressedTest')" \
18    | sed 's%Standard%Standard; ClientRunBeforeJob="sleep 6"%' > $tmp/1
19
20
21outf="$tmp/sed_tmp"
22echo 's%CompressedTest%AllowDuplicateYes%' > $outf
23echo 's%Backup%Backup; AllowDuplicateJobs = yes%' >> $outf
24sed -f $outf $tmp/1 >> $conf/bareos-dir.conf
25
26echo 's%CompressedTest%CancelLowerLevelDuplicatesYes%' > $outf
27echo 's%Backup%Backup; AllowDuplicateJobs = no; CancelLowerLevelDuplicates=yes%' >> $outf
28sed -f $outf $tmp/1 >> $conf/bareos-dir.conf
29
30echo 's%CompressedTest%CancelQueueDuplicatesYes%' > $outf
31echo 's%Backup%Backup; AllowDuplicateJobs = no;CancelLowerLevelDuplicates=no;CancelQueuedDuplicates=yes %' >> $outf
32sed -f $outf $tmp/1 >> $conf/bareos-dir.conf
33
34echo 's%CompressedTest%CancelRunningDuplicatesYes%' > $outf
35echo 's%Backup%Backup; AllowDuplicateJobs = no;CancelLowerLevelDuplicates=no;CancelQueuedDuplicates=no; CancelRunningDuplicates=yes%' >> $outf
36sed -f $outf $tmp/1 >> $conf/bareos-dir.conf
37
38echo 's%CompressedTest%CancelRunningDuplicatesNo%' > $outf
39echo 's%Backup%Backup; AllowDuplicateJobs = no;CancelLowerLevelDuplicates=no;CancelQueuedDuplicates=no; CancelRunningDuplicates=no%' >> $outf
40sed -f $outf $tmp/1 >> $conf/bareos-dir.conf
41
42# Directory to backup.
43# This directory will be created by setup_data().
44BackupDirectory="${tmp}/data"
45
46# Use a tgz to setup data to be backuped.
47# Data will be placed at "${tmp}/data/".
48setup_data data/small.tgz
49
50# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
51echo "${BackupDirectory}" >${tmp}/file-list
52
53when=`perl -Mscripts::functions -e "get_time(300)"`
54
55
56start_test
57
58cat <<END_OF_DATA >${cwd}/tmp/bconcmds
59@$out /dev/null
60messages
61@$out ${cwd}/tmp/log1.out
62messages
63label storage=File volume=TestVolume001
64@#setdebug level=100 storage=File
65@##############################################
66@# AllowDuplicates = Yes, both jobs should work
67@##############################################
68run comment="Should work" level=Full job=AllowDuplicateYes yes
69@sleep 2
70run comment="Should work" level=Full job=AllowDuplicateYes yes
71wait
72messages
73@$out $tmp/log3.out
74@###############################################################
75@# Run two jobs with the same level and see wich one is canceled
76@###############################################################
77run comment="Should work" level=Full job=CancelLowerLevelDuplicatesYes yes
78@sleep 2
79run comment="Should fail" level=Full job=CancelLowerLevelDuplicatesYes yes
80wait
81messages
82@####################################################################
83@# Run two jobs with the different level and see wich one is canceled
84@####################################################################
85run comment="Should fail" level=Incremental job=CancelLowerLevelDuplicatesYes yes
86@sleep 2
87run comment="Should work" level=Full job=CancelLowerLevelDuplicatesYes yes
88wait
89messages
90run comment="Should fail" level=Differential job=CancelLowerLevelDuplicatesYes yes
91@sleep 2
92run comment="Should work" level=Full job=CancelLowerLevelDuplicatesYes yes
93wait
94messages
95run comment="Should work" level=Differential job=CancelLowerLevelDuplicatesYes yes
96@sleep 2
97run comment="Should fail" level=Incremental job=CancelLowerLevelDuplicatesYes yes
98wait
99messages
100@#####################################################################################
101@# Run two jobs with the different level and see wich one is canceled (reversed order)
102@#####################################################################################
103run comment="Should work" level=Full job=CancelLowerLevelDuplicatesYes yes
104@sleep 2
105run comment="Should fail" level=Incremental job=CancelLowerLevelDuplicatesYes yes
106wait
107messages
108@$out $tmp/log4.out
109@####################################################################
110@# Run two jobs, the second one can't cancel the 1st, and should fail
111@####################################################################
112run comment="Should work" level=Full job=CancelQueueDuplicatesYes yes
113@sleep 2
114run comment="Should fail" level=Full job=CancelQueueDuplicatesYes yes
115wait
116messages
117@#################################################################
118@# The first job should stay queued, the second one will cancel it
119@#################################################################
120run comment="Should fail" level=Full job=CancelQueueDuplicatesYes when="$when" yes
121@sleep 2
122run comment="Should work" level=Full job=CancelQueueDuplicatesYes yes
123wait
124messages
125@$out $tmp/log5.out
126@########################################
127@# The second job will kill the first one
128@########################################
129run comment="Should fail" level=Full job=CancelRunningDuplicatesYes yes
130@sleep 2
131run comment="Should work" level=Full job=CancelRunningDuplicatesYes yes
132wait
133messages
134@$out $tmp/log6.out
135@##########################
136@# The second job won't run
137@##########################
138run comment="Should work" level=Full job=CancelRunningDuplicatesNo yes
139@sleep 2
140run comment="Should fail" level=Full job=CancelRunningDuplicatesNo yes
141wait
142messages
143@$out $tmp/log7.out
144sql
145SELECT JobId, Name, Level, Comment, JobStatus from Job
146WHERE Comment='Should fail' and JobStatus='T' ORDER By JobId;
147
148@$out $tmp/log8.out
149sql
150SELECT JobId, Name, Level, Comment, JobStatus from Job
151WHERE Comment='Should work' and JobStatus != 'T' ORDER By JobId;
152
153@$out $tmp/log9.out
154sql
155SELECT JobId, Name, Level, Comment, JobStatus from Job order by JobId;
156
157quit
158END_OF_DATA
159
160run_bareos
161check_for_zombie_jobs storage=File
162stop_bareos
163
164touch $tmp/log2.out
165check_two_logs
166
167grep '^| *[0-9]' $tmp/log7.out > /dev/null
168if [ $? = 0 ]; then
169    print_debug "ERROR: Found errors in $tmp/log7.out"
170    print_debug `cat $tmp/log7.out`
171    estat=1
172fi
173
174grep '^| *[0-9]' $tmp/log8.out > /dev/null
175if [ $? = 0 ]; then
176    print_debug "ERROR: Found errors in $tmp/log8.out"
177    print_debug `cat $tmp/log8.out`
178    estat=1
179fi
180
181nb=`grep '^| *[0-9]' $tmp/log9.out | wc -l`
182if [ $nb -lt 10 ]; then
183    print_debug "ERROR: no enough results in $tmp/log9.out"
184    print_debug `cat $tmp/log9.out`
185    estat=1
186fi
187
188end_test
189