1#!/bin/sh
2#
3# Run a simple backup then copy it
4#   to another device. We test that when the original job is purged
5#   the next copy is "upgraded" to Type=B
6#
7# This script uses the virtual disk autochanger
8#
9TestName="copy-upgrade-test"
10JobName=CopyJobSave
11. scripts/functions
12
13
14scripts/cleanup
15scripts/copy-migration-confs
16scripts/prepare-disk-changer
17sed 's/migrate/copy/g' ${cwd}/bin/bareos-dir.conf > ${cwd}/tmp/1
18sed 's/Migrate/Copy/g' ${cwd}/tmp/1 > ${cwd}/bin/bareos-dir.conf
19change_jobname NightlySave $JobName
20
21# Directory to backup.
22# This directory will be created by setup_data().
23BackupDirectory="${tmp}/data"
24
25# Use a tgz to setup data to be backuped.
26# Data will be placed at "${tmp}/data/".
27setup_data data/small.tgz
28
29
30start_test
31
32#
33# Note, we first backup into Pool Default,
34#          then Copy into Pool Full.
35#              Pool Default uses Storage=File
36#              Pool Full    uses Storage=DiskChanger
37
38# Write out bconsole commands
39cat <<END_OF_DATA >${cwd}/tmp/bconcmds
40@$out /dev/null
41messages
42@$out ${cwd}/tmp/log1.out
43@# setdebug level=100 storage=File
44label storage=File volume=FileVolume001 Pool=Default
45label storage=DiskChanger volume=ChangerVolume001 slot=1 Pool=Full drive=0
46label storage=DiskChanger volume=ChangerVolume002 slot=2 Pool=Full drive=0
47run job=$JobName yes
48wait
49messages
50END_OF_DATA
51
52run_bareos
53
54echo test > ${BackupDirectory}/test
55
56cat <<END_OF_DATA >${cwd}/tmp/bconcmds
57@$out ${cwd}/tmp/log1.out
58run job=$JobName level=incremental yes
59wait
60messages
61END_OF_DATA
62
63run_bconsole
64
65echo test1 > ${BackupDirectory}/test1
66
67cat <<END_OF_DATA >${cwd}/tmp/bconcmds
68@$out ${cwd}/tmp/log1.out
69run job=$JobName level=incremental yes
70wait
71messages
72@# we should be able to purge jobid 1 3 times
73update volume=FileVolume001 VolStatus=Used
74@# 4,5
75run job=copy-job jobid=1 yes
76wait
77@# 6,7
78run job=copy-job jobid=2 yes
79wait
80@# 8,9
81run job=copy-job jobid=3 yes
82wait
83@# 10,11
84run job=copy-job jobid=1 yes
85wait
86@# 12,13
87run job=copy-job jobid=2 yes
88wait
89@# 14,15
90run job=copy-job jobid=3 yes
91wait
92@# 16,17
93run job=copy-job jobid=1 yes
94wait
95@# 18,19
96run job=copy-job jobid=1 yes
97wait
98messages
99list jobs
100list volumes
101END_OF_DATA
102
103run_bconsole
104
105cat<<END_OF_DATA > ${cwd}/tmp/bconcmds.resto
106@#
107@# now do a restore
108@#
109@$out ${cwd}/tmp/log2.out
110list volumes
111restore where=${cwd}/tmp/bareos-restores select
112unmark *
113mark *
114done
115yes
116list volumes
117wait
118messages
119quit
120END_OF_DATA
121
122run_bconsole ${cwd}/tmp/bconcmds.resto
123check_two_logs
124check_restore_diff
125
126cat <<EOF >${cwd}/tmp/bconcmds
127@$out ${cwd}/tmp/log2.out
128@# the last restore
129@# should restore with 1,2,3
130delete jobid=1
131@# should restore with 5,2,3
132EOF
133run_bconsole
134
135rm -rf ${cwd}/tmp/bareos-restores
136run_bconsole ${cwd}/tmp/bconcmds.resto
137check_two_logs
138check_restore_diff
139
140# remove first copy of job=1
141cat <<EOF >${cwd}/tmp/bconcmds
142@$out ${cwd}/tmp/log2.out
143delete jobid=5
144@# should restore with 11,2,3
145EOF
146run_bconsole
147
148rm -rf ${cwd}/tmp/bareos-restores
149run_bconsole ${cwd}/tmp/bconcmds.resto
150check_two_logs
151check_restore_diff
152
153# remove 2 copies at the same time
154cat <<EOF >${cwd}/tmp/bconcmds
155@$out ${cwd}/tmp/log2.out
156delete jobid=11,17
157@# should restore with 19,2,3
158EOF
159run_bconsole
160
161rm -rf ${cwd}/tmp/bareos-restores
162run_bconsole ${cwd}/tmp/bconcmds.resto
163check_two_logs
164check_restore_diff
165
166# remove job and copies of jobid=3
167cat <<EOF >${cwd}/tmp/bconcmds
168@$out ${cwd}/tmp/log2.out
169delete jobid=3,9,15
170@# should restore with 19,2
171EOF
172run_bconsole
173
174rm -f ${BackupDirectory}/test1
175rm -rf ${cwd}/tmp/bareos-restores
176run_bconsole ${cwd}/tmp/bconcmds.resto
177check_two_logs
178check_restore_diff
179
180awk '/You have selected the following JobIds:/ { print $7 }' \
181      ${cwd}/tmp/log2.out > ${cwd}/tmp/real
182awk '/should restore with/ { print $5 }' \
183      ${cwd}/tmp/log2.out > ${cwd}/tmp/should
184
185diff -u ${cwd}/tmp/real ${cwd}/tmp/should
186if [ $? -ne 0 ]; then
187    print_debug "Bad job selection!!!"
188    rstat=2
189fi
190
191check_for_zombie_jobs storage=File
192stop_bareos
193end_test
194