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.bareos.org/downloads/depkgs-mingw32/strawberry-perl-5.10.1.0.msi
9# * Install the latest version of Bareos 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 bareos, and run the "systemstate" backup job, then
26#  restore it.
27#
28TestName="win32-full-systemstate-test"
29. scripts/functions
30
31scripts/cleanup
32scripts/copy-test-confs
33cp scripts/win32-bareos-dir-systemstate.conf bin/bareos-dir.conf
34
35URL=http://$WIN32_ADDR:8091
36echo "Connect with Win32 server $URL"
37wget -qO $tmp/stop.log "$URL/stop"
38if [ $? != 0 ]; then
39   print_debug "ERROR: Stop Windows Bareos FD daemon failed."
40fi
41wget -qO $tmp/update.log "$URL/set_director_name?name=$HOST-dir;pass=$WIN32_PASSWORD"
42if [ $? != 0 ]; then
43   print_debug "ERROR: Set Windows Bareos director name, pasword failed"
44fi
45wget -qO $tmp/start.log "$URL/start"
46if [ $? != 0 ]; then
47   print_debug "ERROR: Restart Windows Bareos FD failed"
48fi
49if [ 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
54fi
55wget -qO - "$URL/add_registry_key?key=Test$$;val=Val$$" | grep OK > /dev/null
56if [ $? != 0 ]; then
57   print_debug "ERROR: Can't add registry key Test$$"
58fi
59wget -qO - "$URL/add_registry_key?key=RemovedAtRestore$$;val=Val$$" | grep OK > /dev/null
60if [ $? != 0 ]; then
61   print_debug "ERROR: Can't add registry key RemovedAtRestore$$"
62fi
63
64echo "Start test"
65start_test
66
67cat <<END_OF_DATA >${cwd}/tmp/bconcmds
68@output
69messages
70@$out ${cwd}/tmp/log1.out
71status client=$WIN32_CLIENT
72label storage=File volume=TestVolume001
73run job=SystemstateJob storage=File yes
74wait
75messages
76quit
77END_OF_DATA
78
79echo "Run bareos"
80run_bareos
81
82wget -qO -  "$URL/del_registry_key?key=RemovedAtRestore$$" | grep OK > /dev/null
83if [ $? -ne 0 ]; then
84    print_debug "ERROR: can't remove key RemovedAtRestore$$ from registry"
85    estat=1
86fi
87
88wget -qO -  "$URL/add_registry_key?key=NewTest$$;val=Val$$" |grep OK > /dev/null
89if [ $? -ne 0 ]; then
90    print_debug "ERROR: can't add key NewTest$$ to registry"
91    estat=1
92fi
93
94cat <<END_OF_DATA >${cwd}/tmp/bconcmds
95@$out ${cwd}/tmp/log1.out
96run job=SystemstateJob storage=File yes
97wait
98messages
99quit
100END_OF_DATA
101
102run_bconsole
103
104wget -qO -  "$URL/add_registry_key?key=OtherTest$$;val=Val$$" |grep OK > /dev/null
105if [ $? -ne 0 ]; then
106    print_debug "ERROR: can't add key OtherTest$$ to registry"
107    estat=1
108fi
109
110run_bconsole
111
112wget -qO -  "$URL/add_registry_key?key=Other$$;val=Val$$" |grep OK > /dev/null
113if [ $? -ne 0 ]; then
114    print_debug "ERROR: can't add key Other$$ to registry"
115    estat=1
116fi
117
118run_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/bareos-dir.conf", "ClientRunAfterJob", "c:/del.cmd", "Job", "SystemstateJob")'
123
124wget -qO -  "$URL/remove_dir?file=c:/windows/winsxs/*help*;dest=c:/del.cmd" | grep OK > /dev/null
125if [ $? -ne 0 ]; then
126    print_debug "ERROR: can't create c:/del.cmd"
127    estat=1
128fi
129
130# should not backup many things, just run the del.cmd command at the end
131cat <<END_OF_DATA >${cwd}/tmp/bconcmds
132reload
133@$out ${cwd}/tmp/log1.out
134run job=SystemstateJob storage=File yes
135wait
136messages
137quit
138END_OF_DATA
139
140run_bconsole
141
142wget -qO -  "$URL/del_registry_key?key=NewTest$$" | grep OK > /dev/null
143if [ $? -ne 0 ]; then
144    print_debug "ERROR: can't remove key NewTest$$ from registry"
145    estat=1
146fi
147
148cat <<END_OF_DATA >${cwd}/tmp/bconcmds
149@#
150@# now do a restore
151@#
152@$out ${cwd}/tmp/log2.out
153restore where=/ storage=File
1545
155cd @SYSTEMSTATE
156mark "Registry Writer"
157done
158yes
159wait
160messages
161quit
162END_OF_DATA
163
164run_bconsole
165
166wget -qO $tmp/start.log "$URL/reboot"
167
168# we need a way to start the regress-win32.pl at the start
169while ! ping -c 1 $WIN32_ADDR > /dev/null; do
170    sleep 5
171done
172echo "Machine $URL supposedly rebooted"
173
174echo "If the autologon doesn't work, you can double click on c:\\autologon.reg"
175i=0
176while ! 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
183done
184
185wget -qO - "$URL/get_registry_key?key=Test$$;val=Val$$" | grep OK > /dev/null
186if [ $? -ne 0 ]; then
187    print_debug "ERROR: Can't find registry key Test$$"
188    estat=1
189fi
190
191wget -qO - "$URL/get_registry_key?key=NewTest$$;val=Val$$" | grep OK > /dev/null
192if [ $? -ne 0 ]; then
193    print_debug "ERROR: Can't find registry key NewTest$$"
194    estat=1
195fi
196
197wget -qO - "$URL/get_registry_key?key=RemovedAtRestore$$;val=Val$$" | grep ERR > /dev/null
198if [ $? -ne 0 ]; then
199    print_debug "ERROR: Should not find registry key RemovedAtRestore$$"
200    estat=1
201fi
202
203################################################################
204# Do a complete restore
205
206cat <<END_OF_DATA >${cwd}/tmp/bconcmds
207@#
208@# now do a complete restore
209@#
210@$out ${cwd}/tmp/log2.out
211restore where=/ storage=File
2125
213cd @SYSTEMSTATE
214mark *
215done
216yes
217wait
218messages
219quit
220END_OF_DATA
221
222run_bconsole
223
224check_for_zombie_jobs storage=File
225stop_bareos
226
227check_two_logs
228
229wget -qO $tmp/start.log "$URL/reboot"
230
231# we need a way to start the regress-win32.pl at the start
232while ! ping -c 1 $WIN32_ADDR > /dev/null; do
233    sleep 5
234done
235echo "Machine $URL supposedly rebooted"
236
237echo "If the autologon doesn't work, you can double click on c:\\autologon.reg"
238while ! 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
245done
246
247wget -qO - "$URL/get_registry_key?key=Test$$;val=Val$$" | grep OK > /dev/null
248if [ $? -ne 0 ]; then
249    print_debug "ERROR: Can't find registry key Test$$"
250    estat=1
251fi
252
253wget -qO - "$URL/get_registry_key?key=NewTest$$;val=Val$$" | grep OK > /dev/null
254if [ $? -ne 0 ]; then
255    print_debug "ERROR: Can't find registry key NewTest$$"
256    estat=1
257fi
258
259wget -qO - "$URL/get_registry_key?key=RemovedAtRestore$$;val=Val$$" | grep ERR > /dev/null
260if [ $? -ne 0 ]; then
261    print_debug "ERROR: Should not find registry key RemovedAtRestore$$"
262    estat=1
263fi
264
265end_test
266