1 # Copyright (c) 2010-2012 Zmanda Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use Test::More tests => 11;
26 use lib "@amperldir@";
27 use Installcheck::Run;
28 use Installcheck::Catalogs;
29 use Amanda::Config qw( :init :getconf config_dir_relative );
32 use Amanda::DB::Catalog;
33 use Amanda::Recovery::Planner;
36 use Amanda::Xfer qw( :constants );
38 # disable Debug's die() and warn() overrides
39 Amanda::Debug::disable_die_override();
41 # put the debug messages somewhere
42 Amanda::Debug::dbopen("installcheck");
43 Installcheck::log_test_output();
46 $testconf = Installcheck::Run->setup();
49 # install the 'bigdb' catalog to test against
50 my $cat = Installcheck::Catalogs::load("bigdb");
53 my $cfg_result = config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
54 if ($cfg_result != $CFGERR_OK) {
55 my ($level, @errors) = Amanda::Config::config_errors();
56 die(join "\n", @errors);
66 Amanda::Recovery::Planner::make_plan(@_,
69 (my $err, $plan) = @_;
71 Amanda::MainLoop::quit();
74 Amanda::MainLoop::run();
79 return Amanda::Cmdline::dumpspec_t->new($_[0], $_[1], $_[2], $_[3], undef);
83 my ($got, $exp, $msg) = @_;
84 my $got_dumps = $got->{'dumps'};
86 # make an "abbreviated" version of the plan for comparison with the
89 for my $d (@$got_dumps) {
94 $d->{'dump_timestamp'},
95 "$d->{'level'}"+0, # strip bigints
98 for my $p (@{$d->{'parts'}}) {
99 next unless defined $p;
100 if (exists $p->{'holding_file'}) {
101 # extract the last two filename components, since the rest is variable
102 my $hf = $p->{'holding_file'};
103 $hf =~ s/^.*\/([^\/]*\/[^\/]*)$/$1/;
108 "$p->{filenum}"+0; # strip bigints
113 is_deeply(\@got_abbrev, $exp, $msg)
114 or diag("got:\n" . Dumper(\@got_abbrev));
117 my $changer = undef; # not needed yet
119 is_plan(make_plan_sync(
120 dumpspec => ds("no-box-at-all"),
121 changer => $changer),
123 "empty plan for nonexistent host");
125 is_plan(make_plan_sync(
126 dumpspec => ds("oldbox", "^/opt"),
127 changer => $changer),
129 [ "oldbox", "/opt", "20080414144444", 0, [
130 '20080414144444/oldbox._opt',
134 "simple plan for a dump on holding disk");
136 is_plan(make_plan_sync(
137 dumpspec => ds("somebox", "^/lib", "200801"),
138 changer => $changer),
140 [ "somebox", "/lib", "20080111000000", 0, [
145 "simple plan for just one dump");
147 is_plan(make_plan_sync(
148 dumpspec => ds("somebox", "^/usr/bin"),
149 changer => $changer),
151 [ 'somebox', '/usr/bin', '20080313133333', 1, [
155 [ 'somebox', '/usr/bin', '20080515155555', 1, [
159 [ 'somebox', '/usr/bin', '20080616166666', 1, [
164 "plan for three dumps, in order by tape write time");
166 is_plan(make_plan_sync(
167 dumpspec => ds("otherbox", "^/lib"),
168 changer => $changer),
170 [ "otherbox", "/lib", "20080414144444", 1, [
171 '20080414144444/otherbox._lib',
174 [ 'otherbox', '/lib', '20080313133333', 0, [
178 [ "otherbox", "/lib", "20080511151555", 0, [
183 "plan for three dumps, one on holding disk; holding dumps prioritized first");
185 is_plan(make_plan_sync(
187 ds("somebox", "^/lib", "20080111"),
188 ds("somebox", "^/lib", "20080222"),
190 changer => $changer),
192 [ "somebox", "/lib", "20080111000000", 0, [
196 [ 'somebox', '/lib', '20080222222222', 0, [
202 "plan for two dumps, one of them spanned, in order by tape write time");
204 is_plan(make_plan_sync(
205 dumpspec => ds("somebox", "^/lib", "200803"),
206 one_dump_per_part => 1,
207 changer => $changer),
209 [ "somebox", "/lib", "20080313133333", 0, [
213 [ "somebox", "/lib", "20080313133333", 0, [
217 [ "somebox", "/lib", "20080313133333", 0, [
221 [ "somebox", "/lib", "20080313133333", 0, [
225 [ "somebox", "/lib", "20080313133333", 0, [
229 [ "somebox", "/lib", "20080313133333", 0, [
233 [ "somebox", "/lib", "20080313133333", 0, [
237 [ "somebox", "/lib", "20080313133333", 0, [
241 [ "somebox", "/lib", "20080313133333", 0, [
245 [ "somebox", "/lib", "20080313133333", 0, [
250 "plan for a multipart dump, one_dump_per_part");
252 is_plan(make_plan_sync(
253 dumpspec => ds("oldbox", "^/opt", "20080414144444"),
254 holding_file => $cat->holding_filename('oldbox_opt_20080414144444_holding')),
256 [ "oldbox", "/opt", "20080414144444", 0, [
257 '20080414144444/oldbox._opt',
261 "make_plan creates an appropriate plan for an explicit holding-disk recovery");
263 is_plan(make_plan_sync(
264 holding_file => $cat->holding_filename('oldbox_opt_20080414144444_holding')),
266 [ "oldbox", "/opt", "20080414144444", 0, [
267 '20080414144444/oldbox._opt',
271 "same, without a dumpspec");
273 is_plan(make_plan_sync(
274 dumpspec => ds("somebox", "/lib", "20080515155555"),
276 'Conf-006' => [2, 3, 4, 5, 8, 9, 10, 11],
277 # (make_plan should fill in files 6 and 7)
279 changer => $changer),
281 [ 'somebox', '/lib', '20080515155555', 0, [
295 "plan based on filelist, with a dumpspec");
297 is_plan(make_plan_sync(
299 'Conf-006' => [2, 3, 4, 5, 8, 9, 10, 11],
300 # (make_plan should fill in files 6 and 7)
302 changer => $changer),
304 [ 'somebox', '/lib', '20080515155555', 0, [
318 "plan based on filelist, without a dumpspec");