]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/base-job-test
baculum: Add strip_prefix, add_prefix, add_suffix and regex_where restore options...
[bacula/bacula] / regress / tests / base-job-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # Run a basejob backup of the Bacula build directory
7 #   then restore it.
8 #
9
10 TestName="base-job-test"
11 JobName=backup
12 . scripts/functions
13 $rscripts/cleanup
14
15 copy_test_confs
16 echo 's/backup_advance/base_backup/' > $tmp/s
17 echo 's/Name = backup/Name = backup; Base = base_backup, backup/' >> $tmp/s
18 sed -f $tmp/s $rscripts/bacula-dir.conf.accurate > $conf/bacula-dir.conf
19 rm -f $tmp/s
20
21 sed s/all,/all,saved,/ $conf/bacula-fd.conf > tmp/1
22 cp tmp/1 $conf/bacula-fd.conf
23
24 change_jobname BackupClient1 $JobName
25
26 p() {
27     echo "##############################################" >> ${cwd}/tmp/log1.out
28     echo "$*" >> ${cwd}/tmp/log1.out
29     echo "##############################################" >> ${cwd}/tmp/log2.out
30     echo "$*" >> ${cwd}/tmp/log2.out
31 }
32
33 # cleanup
34 rm -rf ${cwd}/build/accurate.new
35 rm -rf ${cwd}/build/accurate
36
37
38 # add extra files
39 mkdir ${cwd}/build/accurate
40 mkdir ${cwd}/build/accurate/dirtest
41 echo "test test" > ${cwd}/build/accurate/dirtest/hello
42 echo "test test" > ${cwd}/build/accurate/xxx
43 echo "test test" > ${cwd}/build/accurate/yyy
44 echo "test test" > ${cwd}/build/accurate/zzz
45 echo "test test" > ${cwd}/build/accurate/zzzzzz
46 echo "test test" > ${cwd}/build/accurate/xxxxxx
47 echo "test test" > ${cwd}/build/accurate/yyyyyy
48 echo "test test" > ${cwd}/build/accurate/xxxxxxxxx
49 echo "test test" > ${cwd}/build/accurate/yyyyyyyyy
50 echo "test test" > ${cwd}/build/accurate/zzzzzzzzz
51 echo ${cwd}/build > ${cwd}/tmp/file-list
52
53 start_test
54
55 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
56 @output /dev/null
57 messages
58 label volume=TestVolume001 storage=File pool=Default
59 messages
60 END_OF_DATA
61
62 run_bacula
63
64 ################################################################
65 p Now do a backup using base backup
66 ################################################################
67
68 echo ${cwd}/bin >> ${cwd}/tmp/file-list
69
70 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
71 @$out ${cwd}/tmp/log1.out
72 run job=base_backup level=base yes
73 wait
74 messages
75 update volume=TestVolume001 volstatus=Used
76 END_OF_DATA
77
78 run_bconsole
79
80 echo ${cwd}/build > ${cwd}/tmp/file-list
81
82 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
83 @$out ${cwd}/tmp/log4.out
84 label volume=TestVolume002 storage=File pool=Default
85 run job=backup level=full yes
86 wait
87 messages
88 @# 
89 @# now do a restore
90 @#
91 @$out ${cwd}/tmp/log2.out  
92 restore fileset=FS_TESTJOB where=${cwd}/tmp/bacula-restores select all done
93 yes
94 wait
95 messages
96 END_OF_DATA
97
98
99 run_bconsole
100 check_for_zombie_jobs storage=File
101
102 check_two_logs
103 check_restore_diff
104
105 rm -rf ${cwd}/tmp/bacula-restores
106
107 grep -e 'FD Bytes Written: *0' ${cwd}/tmp/log4.out > /dev/null
108 if [ $? -ne 0 ]; then
109     print_debug "ERROR: The first full job should have 0 byte in log4.out"
110     bstat=2
111 fi
112
113 grep -e 'Using BaseJobId(s): 1$'  ${cwd}/tmp/log4.out > /dev/null
114 if [ $? -ne 0 ]; then
115     print_debug "ERROR: The first full job should use only jobid=1 as basejob"
116     bstat=2
117 fi
118
119 ################################################################
120 p Now do a backup after making few changes
121 ################################################################
122 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
123 @$out ${cwd}/tmp/log1.out
124 update volume=TestVolume002 volstatus=Used
125 label volume=TestVolume003 storage=File pool=Default
126 run job=backup level=incremental yes
127 wait
128 messages
129 list files jobid=4
130 @# 
131 @# now do a restore
132 @#
133 @$out ${cwd}/tmp/log2.out  
134 restore fileset=FS_TESTJOB where=${cwd}/tmp/bacula-restores select all done
135 yes
136 wait
137 messages
138 END_OF_DATA
139
140 rm ${cwd}/build/accurate/yyyyyy  # delete a file
141 rm -rf ${cwd}/build/accurate/dirtest
142
143
144 run_bconsole
145 check_for_zombie_jobs storage=File
146
147 check_two_logs
148 check_restore_diff
149 check_files_written ${cwd}/tmp/log1.out 4
150
151 rm -rf ${cwd}/tmp/bacula-restores
152
153 ################################################################
154 p Test the job purge
155 ################################################################
156 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
157 @$out ${cwd}/tmp/log3.out
158 sql
159 SELECT count(*) FROM BaseFiles;
160
161 purge volume=TestVolume002
162 messages
163 sql
164 SELECT count(*) FROM BaseFiles;
165
166 END_OF_DATA
167
168 run_bconsole
169
170 grep -e ' 0 *|' ${cwd}/tmp/log3.out > /dev/null
171 if [ $? -ne 0 ]; then
172     print_debug "ERROR: Can't purge the base job"
173     estat=1
174 fi
175
176
177 ################################################################
178 p Test list commands
179 ################################################################
180
181 touch ${cwd}/build/po/fr.po
182
183 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
184 run level=full job=backup yes
185 wait
186 messages
187 @out ${cwd}/tmp/log5.out
188 list basefiles jobid=6
189 @out ${cwd}/tmp/log6.out
190 list files jobid=6
191 messages
192 END_OF_DATA
193
194 run_bconsole
195
196 grep "po/fr.po^" ${cwd}/tmp/log5.out > /dev/null
197 if [ $? -eq 0 ]; then
198     print_debug "ERROR: Should not display fr.po as basefile"
199     estat=2
200 fi
201
202 export bstat dstat estat
203
204 stop_bacula
205 end_test