1 # Copyright (c) 2010-2012 Zmanda Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 use Test::More tests => 11;
25 use lib "@amperldir@";
26 use Installcheck::Run;
27 use Installcheck::Catalogs;
28 use Amanda::Config qw( :init :getconf config_dir_relative );
31 use Amanda::DB::Catalog;
32 use Amanda::Recovery::Planner;
35 use Amanda::Xfer qw( :constants );
37 # disable Debug's die() and warn() overrides
38 Amanda::Debug::disable_die_override();
40 # put the debug messages somewhere
41 Amanda::Debug::dbopen("installcheck");
42 Installcheck::log_test_output();
45 $testconf = Installcheck::Run->setup();
48 # install the 'bigdb' catalog to test against
49 my $cat = Installcheck::Catalogs::load("bigdb");
52 my $cfg_result = config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
53 if ($cfg_result != $CFGERR_OK) {
54 my ($level, @errors) = Amanda::Config::config_errors();
55 die(join "\n", @errors);
65 Amanda::Recovery::Planner::make_plan(@_,
68 (my $err, $plan) = @_;
70 Amanda::MainLoop::quit();
73 Amanda::MainLoop::run();
78 return Amanda::Cmdline::dumpspec_t->new($_[0], $_[1], $_[2], $_[3], undef);
82 my ($got, $exp, $msg) = @_;
83 my $got_dumps = $got->{'dumps'};
85 # make an "abbreviated" version of the plan for comparison with the
88 for my $d (@$got_dumps) {
93 $d->{'dump_timestamp'},
94 "$d->{'level'}"+0, # strip bigints
97 for my $p (@{$d->{'parts'}}) {
98 next unless defined $p;
99 if (exists $p->{'holding_file'}) {
100 # extract the last two filename components, since the rest is variable
101 my $hf = $p->{'holding_file'};
102 $hf =~ s/^.*\/([^\/]*\/[^\/]*)$/$1/;
107 "$p->{filenum}"+0; # strip bigints
112 is_deeply(\@got_abbrev, $exp, $msg)
113 or diag("got:\n" . Dumper(\@got_abbrev));
116 my $changer = undef; # not needed yet
118 is_plan(make_plan_sync(
119 dumpspec => ds("no-box-at-all"),
120 changer => $changer),
122 "empty plan for nonexistent host");
124 is_plan(make_plan_sync(
125 dumpspec => ds("oldbox", "^/opt"),
126 changer => $changer),
128 [ "oldbox", "/opt", "20080414144444", 0, [
129 '20080414144444/oldbox._opt',
133 "simple plan for a dump on holding disk");
135 is_plan(make_plan_sync(
136 dumpspec => ds("somebox", "^/lib", "200801"),
137 changer => $changer),
139 [ "somebox", "/lib", "20080111000000", 0, [
144 "simple plan for just one dump");
146 is_plan(make_plan_sync(
147 dumpspec => ds("somebox", "^/usr/bin"),
148 changer => $changer),
150 [ 'somebox', '/usr/bin', '20080313133333', 1, [
154 [ 'somebox', '/usr/bin', '20080515155555', 1, [
158 [ 'somebox', '/usr/bin', '20080616166666', 1, [
163 "plan for three dumps, in order by tape write time");
165 is_plan(make_plan_sync(
166 dumpspec => ds("otherbox", "^/lib"),
167 changer => $changer),
169 [ "otherbox", "/lib", "20080414144444", 1, [
170 '20080414144444/otherbox._lib',
173 [ 'otherbox', '/lib', '20080313133333', 0, [
177 [ "otherbox", "/lib", "20080511151555", 0, [
182 "plan for three dumps, one on holding disk; holding dumps prioritized first");
184 is_plan(make_plan_sync(
186 ds("somebox", "^/lib", "20080111"),
187 ds("somebox", "^/lib", "20080222"),
189 changer => $changer),
191 [ "somebox", "/lib", "20080111000000", 0, [
195 [ 'somebox', '/lib', '20080222222222', 0, [
201 "plan for two dumps, one of them spanned, in order by tape write time");
203 is_plan(make_plan_sync(
204 dumpspec => ds("somebox", "^/lib", "200803"),
205 one_dump_per_part => 1,
206 changer => $changer),
208 [ "somebox", "/lib", "20080313133333", 0, [
212 [ "somebox", "/lib", "20080313133333", 0, [
216 [ "somebox", "/lib", "20080313133333", 0, [
220 [ "somebox", "/lib", "20080313133333", 0, [
224 [ "somebox", "/lib", "20080313133333", 0, [
228 [ "somebox", "/lib", "20080313133333", 0, [
232 [ "somebox", "/lib", "20080313133333", 0, [
236 [ "somebox", "/lib", "20080313133333", 0, [
240 [ "somebox", "/lib", "20080313133333", 0, [
244 [ "somebox", "/lib", "20080313133333", 0, [
249 "plan for a multipart dump, one_dump_per_part");
251 is_plan(make_plan_sync(
252 dumpspec => ds("oldbox", "^/opt", "20080414144444"),
253 holding_file => $cat->holding_filename('oldbox_opt_20080414144444_holding')),
255 [ "oldbox", "/opt", "20080414144444", 0, [
256 '20080414144444/oldbox._opt',
260 "make_plan creates an appropriate plan for an explicit holding-disk recovery");
262 is_plan(make_plan_sync(
263 holding_file => $cat->holding_filename('oldbox_opt_20080414144444_holding')),
265 [ "oldbox", "/opt", "20080414144444", 0, [
266 '20080414144444/oldbox._opt',
270 "same, without a dumpspec");
272 is_plan(make_plan_sync(
273 dumpspec => ds("somebox", "/lib", "20080515155555"),
275 'Conf-006' => [2, 3, 4, 5, 8, 9, 10, 11],
276 # (make_plan should fill in files 6 and 7)
278 changer => $changer),
280 [ 'somebox', '/lib', '20080515155555', 0, [
294 "plan based on filelist, with a dumpspec");
296 is_plan(make_plan_sync(
298 'Conf-006' => [2, 3, 4, 5, 8, 9, 10, 11],
299 # (make_plan should fill in files 6 and 7)
301 changer => $changer),
303 [ 'somebox', '/lib', '20080515155555', 0, [
317 "plan based on filelist, without a dumpspec");