]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/prune-pool-test
fix #3269 obey the user choice of "Are you sure you want to delete X JobIds
[bacula/bacula] / regress / tests / prune-pool-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # This script will test prune algo 
7 #
8 . scripts/functions
9
10 TestName="prune-pool-test"
11 JobName=NightlySave
12
13 scripts/cleanup
14 scripts/copy-test-confs
15
16 start_test
17
18 echo $PWD/build/po > tmp/file-list
19
20 dircfg=$conf/bacula-dir.conf
21
22 # copy the Default pool to Special pool
23 cat >> $dircfg <<EOF
24 Pool {
25   Name = Special
26   Pool Type = Backup
27   Recycle = yes                       # Bacula can automatically recycle Volumes
28   AutoPrune = yes                     # Prune expired volumes
29   Volume Retention = 365d             # one year
30   Job Retention = 10m
31   File Retention = 10m
32 }
33 EOF
34
35 $bperl -e "add_attribute('$dircfg', 'AutoPrune', 'No', 'Client')"
36 $bperl -e "add_attribute('$dircfg', 'Job Retention', '1s', 'Client')"
37 $bperl -e "add_attribute('$dircfg', 'File Retention', '1s', 'Client')"
38
39 cat <<EOF > ${cwd}/tmp/bconcmds
40 @output /dev/null
41 messages
42 @$out $tmp/log1.out
43 label storage=File pool=Default volume=TestVolume001
44 label storage=File pool=Special volume=TestVolume002
45 run job=$JobName pool=Default level=full yes
46 wait
47 messages
48 @exec "touch $cwd/build/po/fr.po"
49 run job=$JobName pool=Special level=incremental yes
50 wait
51 messages
52 @exec "touch $cwd/build/po/de.po"
53 run job=$JobName pool=Special level=incremental yes
54 wait
55 messages
56 @exec "touch $cwd/build/po/es.po"
57 run job=$JobName level=incremental yes
58 wait
59 messages
60 run job=$JobName pool=Default level=Differential yes
61 wait
62 messages
63 @sleep 2
64 @$out $tmp/log3.out
65 @################################################################
66 @# Should not prune anything
67 @#setdebug level=50 director
68 prune files pool=Special yes
69 list files jobid=2
70 list files jobid=4
71 list jobs
72 prune jobs pool=Special yes
73 list jobs
74 @################################################################
75 @$out $tmp/log5.out
76 prune files pool=Default yes
77 list files jobid=4
78 list jobs
79 prune jobs pool=Default yes
80 list jobs
81 @################################################################
82 @$out $tmp/log4.out
83 @# Should prune incrementals
84 prune files yes
85 list files jobid=2
86 list jobs
87 prune jobs yes
88 list jobs
89 @#setdebug level=0 director
90 @################################################################
91 @$out $tmp/log2.out
92 restore where=${cwd}/tmp/bacula-restores select all storage=File done
93 yes
94 wait
95 messages
96 quit
97 EOF
98
99 run_bacula
100
101 check_for_zombie_jobs storage=File
102 stop_bacula
103
104 check_two_logs
105
106 estat=0
107
108 ###############################################################################
109 # Now we will verify that the pruning code is working as expected.  Each time,
110 # we run 'list jobs', 'prune', 'list jobs'. check_prune_list ensures that jobids
111 # in argument are present in the first 'list jobs', the 'prune' command deletes
112 # them (same number), and checks that the last 'list jobs' doesn't contain them
113 # anymore. See scripts/functions.pm for details.
114
115 # nothing should be pruned
116 $bperl -e "check_prune_list('$tmp/log3.out')"
117 estat=$(($estat + $?))
118
119 # should prune only Default incremental
120 # F I I I D -> F I I D
121 $bperl -e "check_prune_list('$tmp/log5.out', 4)"
122 estat=$(($estat + $?))
123
124 # we should find fr.po in list files of jobid 2
125 grep po/fr.po $tmp/log3.out > /dev/null
126 estat=$(($estat + $?))
127
128 # we should find es.po in list files of jobid 4
129 grep po/es.po $tmp/log3.out > /dev/null
130 estat=$(($estat + $?))
131
132 # jobids 2 and 3 should be pruned
133 # (F I I I D) -> (F D)
134 $bperl -e "check_prune_list('$tmp/log4.out',2,3)"
135 estat=$(($estat + $?))
136
137 # we should not find fr.po in list files of jobid 2
138 grep po/fr.po $tmp/log4.out > /dev/null
139 if [ $? = 0 ]; then
140     print_debug "ERROR: found fr.po in $tmp/log4.out after the prune file"
141     estat=$(($estat + 1))
142 fi
143
144 # we should not find es.po in list files of jobid 3
145 grep po/es.po $tmp/log5.out > /dev/null
146 if [ $? = 0 ]; then
147     print_debug "ERROR: found es.po in $tmp/log5.out after the prune file"
148     estat=$(($estat + 1))
149 fi
150
151 end_test