]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/win32-full-systemstate-test
backport code from master
[bacula/bacula] / regress / tests / win32-full-systemstate-test
1 #!/bin/sh
2 #
3 # How to use this test
4 # --------------------
5 #
6 # * Get a working Windows OS on your network
7 # * Install strawberry perl version with msi to c:/strawberry
8 #   http://www.bacula.org/downloads/depkgs-mingw32/strawberry-perl-5.10.1.0.msi
9 # * Install the latest version of Bacula FD
10 # * Copy or make accessible (Network share, VirtualBox share) 
11 #     regress/scripts/regress-win32.pl
12 # * Execute the script on the Windows box
13 #     perl regress-win32.pl
14 #     Note: port 8091 must be opened in the firewall
15 # * Run this script with the proper config settings about WIN32
16 # * do "make sed" if you want to run the test on an other host
17
18 # Add user auth info to ./config file to enable autologin
19 #  WIN32_USER=Administrator
20 #  WIN32_PASS=PasswordSecret
21 #  
22 # Note, once everything is setup, and you have run the above once
23 #  you can simply run the first part of this script prior to the URL=
24 #  to get the proper conf files loaded in bin, then manually
25 #  start bacula, and run the "systemstate" backup job, then
26 #  restore it.
27 #
28 TestName="win32-full-systemstate-test"
29 . scripts/functions
30
31 scripts/cleanup
32 scripts/copy-test-confs
33 cp scripts/win32-bacula-dir-systemstate.conf bin/bacula-dir.conf
34
35 URL=http://$WIN32_ADDR:8091
36 echo "Connect with Win32 server $URL"
37 wget -qO $tmp/stop.log "$URL/stop"
38 if [ $? != 0 ]; then
39    print_debug "ERROR: Stop Windows Bacula FD daemon failed."
40 fi
41 wget -qO $tmp/update.log "$URL/set_director_name?name=$HOST-dir;pass=$WIN32_PASSWORD"
42 if [ $? != 0 ]; then
43    print_debug "ERROR: Set Windows Bacula director name, pasword failed"
44 fi
45 wget -qO $tmp/start.log "$URL/start"
46 if [ $? != 0 ]; then
47    print_debug "ERROR: Restart Windows Bacula FD failed"
48 fi
49 if [ x$WIN32_USER != x ]; then
50     wget -qO - "$URL/set_auto_logon?user=$WIN32_USER;pass=$WIN32_PASS" |grep OK
51     if [ $? != 0 ]; then
52        print_debug "ERROR: Set autologin failed"
53     fi
54 fi
55 wget -qO - "$URL/add_registry_key?key=Test$$;val=Val$$" | grep OK > /dev/null
56 if [ $? != 0 ]; then
57    print_debug "ERROR: Can't add registry key Test$$"
58 fi
59 wget -qO - "$URL/add_registry_key?key=RemovedAtRestore$$;val=Val$$" | grep OK > /dev/null
60 if [ $? != 0 ]; then
61    print_debug "ERROR: Can't add registry key RemovedAtRestore$$"
62 fi
63
64 echo "Start test"
65 start_test
66       
67 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
68 @output
69 messages
70 @$out ${cwd}/tmp/log1.out
71 status client=$WIN32_CLIENT
72 label storage=File volume=TestVolume001
73 run job=SystemstateJob storage=File yes
74 wait
75 messages
76 quit
77 END_OF_DATA
78
79 echo "Run bacula"
80 run_bacula
81
82 wget -qO -  "$URL/del_registry_key?key=RemovedAtRestore$$" | grep OK > /dev/null
83 if [ $? -ne 0 ]; then
84     print_debug "ERROR: can't remove key RemovedAtRestore$$ from registry"
85     estat=1
86 fi
87
88 wget -qO -  "$URL/add_registry_key?key=NewTest$$;val=Val$$" |grep OK > /dev/null
89 if [ $? -ne 0 ]; then
90     print_debug "ERROR: can't add key NewTest$$ to registry"
91     estat=1
92 fi
93
94 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
95 @$out ${cwd}/tmp/log1.out
96 run job=SystemstateJob storage=File yes
97 wait
98 messages
99 quit
100 END_OF_DATA
101
102 run_bconsole
103
104 wget -qO -  "$URL/add_registry_key?key=OtherTest$$;val=Val$$" |grep OK > /dev/null
105 if [ $? -ne 0 ]; then
106     print_debug "ERROR: can't add key OtherTest$$ to registry"
107     estat=1
108 fi
109
110 run_bconsole
111
112 wget -qO -  "$URL/add_registry_key?key=Other$$;val=Val$$" |grep OK > /dev/null
113 if [ $? -ne 0 ]; then
114     print_debug "ERROR: can't add key Other$$ to registry"
115     estat=1
116 fi
117
118 run_bconsole
119
120 # choose a random file in winsxs, delete it and see if it's restored at the end
121 # should work only on win2008, win2003 doesn't include this dir in systemstate
122 $bperl -e 'add_attribute("$conf/bacula-dir.conf", "ClientRunAfterJob", "c:/del.cmd", "Job", "SystemstateJob")'
123
124 wget -qO -  "$URL/remove_dir?file=c:/windows/winsxs/*help*;dest=c:/del.cmd" | grep OK > /dev/null
125 if [ $? -ne 0 ]; then
126     print_debug "ERROR: can't create c:/del.cmd"
127     estat=1
128 fi
129
130 # should not backup many things, just run the del.cmd command at the end
131 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
132 reload
133 @$out ${cwd}/tmp/log1.out
134 run job=SystemstateJob storage=File yes
135 wait
136 messages
137 quit
138 END_OF_DATA
139
140 run_bconsole
141
142 wget -qO -  "$URL/del_registry_key?key=NewTest$$" | grep OK > /dev/null
143 if [ $? -ne 0 ]; then
144     print_debug "ERROR: can't remove key NewTest$$ from registry"
145     estat=1
146 fi
147
148 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
149 @# 
150 @# now do a restore
151 @#
152 @$out ${cwd}/tmp/log2.out
153 restore where=/ storage=File
154 5
155 cd @SYSTEMSTATE
156 mark "Registry Writer"
157 done
158 yes
159 wait
160 messages
161 quit
162 END_OF_DATA
163
164 run_bconsole
165
166 wget -qO $tmp/start.log "$URL/reboot"
167
168 # we need a way to start the regress-win32.pl at the start
169 while ! ping -c 1 $WIN32_ADDR > /dev/null; do
170     sleep 5
171 done
172 echo "Machine $URL supposedly rebooted"
173
174 echo "If the autologon doesn't work, you can double click on c:\\autologon.reg"
175 i=0
176 while ! wget -qO /dev/null $URL/nop; do
177     sleep 5
178     i=`expr $i + 1`
179     if [ $i -ge 12 ]; then  # print message every minute
180        i=0
181        echo "== `date +%T` Waiting for reboot and autologin to $URL, you can also login and start regress-win32.pl by hand"
182     fi
183 done
184
185 wget -qO - "$URL/get_registry_key?key=Test$$;val=Val$$" | grep OK > /dev/null
186 if [ $? -ne 0 ]; then
187     print_debug "ERROR: Can't find registry key Test$$"
188     estat=1
189 fi
190
191 wget -qO - "$URL/get_registry_key?key=NewTest$$;val=Val$$" | grep OK > /dev/null
192 if [ $? -ne 0 ]; then
193     print_debug "ERROR: Can't find registry key NewTest$$"
194     estat=1
195 fi
196
197 wget -qO - "$URL/get_registry_key?key=RemovedAtRestore$$;val=Val$$" | grep ERR > /dev/null
198 if [ $? -ne 0 ]; then
199     print_debug "ERROR: Should not find registry key RemovedAtRestore$$"
200     estat=1
201 fi
202
203 ################################################################
204 # Do a complete restore
205
206 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
207 @# 
208 @# now do a complete restore
209 @#
210 @$out ${cwd}/tmp/log2.out
211 restore where=/ storage=File
212 5
213 cd @SYSTEMSTATE
214 mark *
215 done
216 yes
217 wait
218 messages
219 quit
220 END_OF_DATA
221
222 run_bconsole
223
224 check_for_zombie_jobs storage=File
225 stop_bacula
226
227 check_two_logs
228
229 wget -qO $tmp/start.log "$URL/reboot"
230
231 # we need a way to start the regress-win32.pl at the start
232 while ! ping -c 1 $WIN32_ADDR > /dev/null; do
233     sleep 5
234 done
235 echo "Machine $URL supposedly rebooted"
236
237 echo "If the autologon doesn't work, you can double click on c:\\autologon.reg"
238 while ! wget -qO /dev/null $URL/nop; do
239     sleep 5
240     i=`expr $i + 1`
241     if [ $i -ge 12 ]; then  # print message every minute
242        i=0
243        echo "== `date +%T` Waiting for reboot and autologin to $URL, you can also login and start regress-win32.pl by hand"
244     fi
245 done
246
247 wget -qO - "$URL/get_registry_key?key=Test$$;val=Val$$" | grep OK > /dev/null
248 if [ $? -ne 0 ]; then
249     print_debug "ERROR: Can't find registry key Test$$"
250     estat=1
251 fi
252
253 wget -qO - "$URL/get_registry_key?key=NewTest$$;val=Val$$" | grep OK > /dev/null
254 if [ $? -ne 0 ]; then
255     print_debug "ERROR: Can't find registry key NewTest$$"
256     estat=1
257 fi
258
259 wget -qO - "$URL/get_registry_key?key=RemovedAtRestore$$;val=Val$$" | grep ERR > /dev/null
260 if [ $? -ne 0 ]; then
261     print_debug "ERROR: Should not find registry key RemovedAtRestore$$"
262     estat=1
263 fi
264
265 end_test