-## add log entries
-
-# one to an existing logfile, same tape
-Amanda::DB::Catalog::add_dump({
- 'write_timestamp' => '20080111',
- 'dump_timestamp' => '20080707070707',
- 'hostname' => 'newbox',
- 'diskname' => '/newdisk',
- 'level' => 3,
- 'label' => 'Conf-001',
- 'filenum' => 2,
- 'partnum' => 1,
- 'nparts' => 1,
- 'status' => 'OK',
- 'sec' => 13.0,
- 'kb' => 12380,
-});
-
-is_deeply([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'newbox') ],
- [ sortdumps {
- 'write_timestamp' => '20080111000000',
- 'dump_timestamp' => '20080707070707',
- 'hostname' => 'newbox',
- 'diskname' => '/newdisk',
- 'level' => 3,
- 'label' => 'Conf-001',
- 'filenum' => 2,
- 'partnum' => 1,
- 'nparts' => 1,
- 'status' => 'OK',
- 'sec' => 13.0,
- 'kb' => 12380,
- } ],
- "successfully re-read an added dump in an existing logfile");
-
-# and again, to test the last-logfile cache in Amanda::DB::Catalog
-Amanda::DB::Catalog::add_dump({
- 'write_timestamp' => '20080111',
- 'dump_timestamp' => '20080707070707',
- 'hostname' => 'newbox',
- 'diskname' => '/newdisk2',
- 'level' => 0,
- 'label' => 'Conf-001',
- 'filenum' => 3,
- 'partnum' => 1,
- 'nparts' => 1,
- 'status' => 'OK',
- 'sec' => 27.0,
- 'kb' => 32380,
-});
-
-is(scalar Amanda::DB::Catalog::get_dumps(hostname => 'newbox'), 2,
- "adding another dump to that logfile and re-reading gives 2 dumps");
-
-# and another in a new file, as well as a tapelist entry
-Amanda::DB::Catalog::add_dump({
- 'write_timestamp' => '20080707070707',
- 'dump_timestamp' => '20080707070707',
- 'hostname' => 'newlog',
- 'diskname' => '/newdisk',
- 'level' => 3,
- 'label' => 'Conf-009',
- 'filenum' => 1,
- 'partnum' => 1,
- 'nparts' => 1,
- 'status' => 'OK',
- 'sec' => 13.0,
- 'kb' => 12380,
-});
-
-is_deeply([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'newlog') ],
- [ sortdumps {
- 'write_timestamp' => '20080707070707',
- 'dump_timestamp' => '20080707070707',
- 'hostname' => 'newlog',
- 'diskname' => '/newdisk',
- 'level' => 3,
- 'label' => 'Conf-009',
- 'filenum' => 1,
- 'partnum' => 1,
- 'nparts' => 1,
- 'status' => 'OK',
- 'sec' => 13.0,
- 'kb' => 12380,
- } ],
- "successfully re-read an added dump in a new logfile");
-
-# and add a multipart dump to that same logfile
-for (my $i = 1; $i <= 5; $i++) {
- Amanda::DB::Catalog::add_dump({
- 'write_timestamp' => '20080707070707',
- 'dump_timestamp' => '20080707070707',
- 'hostname' => 'newlog',
- 'diskname' => '/bigdisk',
- 'level' => 1,
- 'label' => 'Conf-009',
- 'filenum' => $i+1,
- 'partnum' => $i,
- 'nparts' => 5,
- 'status' => 'OK',
- 'sec' => 13.0,
- 'kb' => 12380,
- });
-}
+got_parts([ Amanda::DB::Catalog::sort_parts(['filenum'],
+ @parts{
+ 'somebox_lib_20080313133333_p9',
+ 'somebox_lib_20080313133333_p10',
+ 'somebox_lib_20080313133333_p1',
+ }) ],
+ [ @parts{
+ 'somebox_lib_20080313133333_p1',
+ 'somebox_lib_20080313133333_p9',
+ 'somebox_lib_20080313133333_p10',
+ } ],
+ "filenum is sorted numerically, not lexically");
+
+got_parts([ Amanda::DB::Catalog::sort_parts(['-partnum'],
+ @parts{
+ 'somebox_lib_20080313133333_p9',
+ 'somebox_lib_20080313133333_p10',
+ 'somebox_lib_20080313133333_p1',
+ }) ],
+ [ @parts{
+ 'somebox_lib_20080313133333_p10',
+ 'somebox_lib_20080313133333_p9',
+ 'somebox_lib_20080313133333_p1',
+ } ],
+ "partnum is sorted numerically (and in reverse!), not lexically");
+
+got_parts([ Amanda::DB::Catalog::sort_parts(['nparts'],
+ @parts{
+ 'somebox_lib_20080313133333_p9', # nparts=10
+ 'somebox_lib_20080222222222_p2', # nparts=2
+ }) ],
+ [ @parts{
+ 'somebox_lib_20080222222222_p2', # nparts=2
+ 'somebox_lib_20080313133333_p9', # nparts=10
+ } ],
+ "nparts is sorted numerically, not lexically");
+
+got_parts([ Amanda::DB::Catalog::sort_parts(['label'],
+ @parts{
+ 'somebox_lib_20080313133333_p9', # Conf-003
+ 'somebox_lib_20080222222222_p2', # Conf-002
+ }) ],
+ [ @parts{
+ 'somebox_lib_20080222222222_p2', # Conf-002
+ 'somebox_lib_20080313133333_p9', # Conf-003
+ } ],
+ "labels sort correctly");
+
+### test dump selecting
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps() ],
+ [ sortdumps dumps_named qr/.*/ ],
+ "get_dumps returns all dumps when given no parameters");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamp => '20080111000000') ],
+ [ sortdumps dumps_named qr/somebox_lib_20080111/ ],
+ "get_dumps parameter write_timestamp");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamp => '20080111') ],
+ [ sortdumps dumps_named qr/somebox_lib_20080111/ ],
+ "get_dumps accepts a short write_timestamp and zero-pads it");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(write_timestamps => ['20080111000000','20080222222222']) ],
+ [ sortdumps dumps_named qr/(20080111|20080222222222)$/ ],
+ "get_dumps parameter write_timestamps");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'otherbox') ],
+ [ sortdumps dumps_named qr/^otherbox/ ],
+ "get_dumps parameter hostname");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname => 'oldbox') ],
+ [ sortdumps dumps_named qr/^oldbox_.*_holding/ ],
+ "get_dumps parameter hostname, holding");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostnames => ['notthere', 'otherbox']) ],
+ [ sortdumps dumps_named qr/^otherbox/ ],
+ "get_dumps parameter hostnames");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(hostname_match => 'other*') ],
+ [ sortdumps dumps_named qr/^otherbox/ ],
+ "get_dumps parameter hostname_match");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(diskname => '/lib') ],
+ [ sortdumps dumps_named qr/^[^_]*_lib_/ ],
+ "get_dumps parameter diskname");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(disknames => ['/lib', '/usr/bin']) ],
+ [ sortdumps dumps_named qr/^[^_]*_(usr_bin|lib)_/ ],
+ "get_dumps parameter disknames");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(diskname_match => 'bin') ],
+ [ sortdumps dumps_named qr/.*_bin_/ ],
+ "get_dumps parameter diskname_match");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dump_timestamp => '20080414144444') ],
+ [ sortdumps dumps_matching { $_->{'dump_timestamp'} eq '20080414144444' } ],
+ "get_dumps parameter dump_timestamp");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(
+ dump_timestamps => ['20080414144444', '20080311131133']) ],
+ [ sortdumps dumps_matching { $_->{'dump_timestamp'} eq '20080414144444'
+ or $_->{'dump_timestamp'} eq '20080311131133' } ],
+ "get_dumps parameter dump_timestamps");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dump_timestamp_match => '200804-7') ],
+ [ sortdumps dumps_matching { $_->{'dump_timestamp'} =~ /^20080[4567]/ } ],
+ "get_dumps parameter dump_timestamp_match");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(level => 0) ],
+ [ sortdumps dumps_matching { $_->{'level'} == 0 } ],
+ "get_dumps parameter level");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(levels => [ 1 ]) ],
+ [ sortdumps dumps_matching { $_->{'level'} == 1 } ],
+ "get_dumps parameter levels");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "OK") ],
+ [ sortdumps dumps_matching { $_->{'status'} eq "OK" } ],
+ "get_dumps parameter status = OK");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "PARTIAL") ],
+ [ sortdumps dumps_matching { $_->{'status'} eq "PARTIAL" } ],
+ "get_dumps parameter status = PARTIAL");
+
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(status => "FAIL") ],
+ [ sortdumps dumps_matching { $_->{'status'} eq "FAIL" } ],
+ "get_dumps parameter status = FAIL");
+
+@dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
+ [ sortdumps dumps_named qr/_lib_/ ],
+ "get_dumps parameter dumpspecs with one dumpspec");
+
+@dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib"], 0);
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ], holding => 1) ],
+ [ sortdumps dumps_named qr/_lib_.*_holding/ ],
+ "get_dumps parameter dumpspecs with one dumpspec");
+
+@dumpspecs = Amanda::Cmdline::parse_dumpspecs([".*", "/lib", "somebox"], 0);
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
+ [ sortdumps dumps_matching { $_->{'diskname'} eq '/lib'
+ or $_->{'hostname'} eq 'somebox' } ],
+ "get_dumps parameter dumpspecs with two dumpspecs");
+
+@dumpspecs = Amanda::Cmdline::parse_dumpspecs(["otherbox", "*", "somebox"], 0);
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
+ [ sortdumps dumps_matching { $_->{'hostname'} eq 'otherbox'
+ or $_->{'hostname'} eq 'somebox' } ],
+ "get_dumps parameter dumpspecs with two non-overlapping dumpspecs");
+
+@dumpspecs = Amanda::Cmdline::parse_dumpspecs(["does-not-exist"], 0);
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
+ [ ],
+ "get_dumps parameter dumpspecs with a dumpspec that matches nothing",
+ zero_dumps_expected => 1);
+
+@dumpspecs = Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, undef, '20080222222222');
+got_dumps([ sortdumps Amanda::DB::Catalog::get_dumps(dumpspecs => [ @dumpspecs ]) ],
+ [ sortdumps dumps_matching { $_->{'write_timestamp'} eq '20080222222222' }],
+ "get_dumps parameter dumpspecs with write_timestamp");
+
+## test dump sorting
+
+got_dumps([ Amanda::DB::Catalog::sort_dumps(['write_timestamp'],
+ @dumps{'somebox_lib_20080222222222','somebox_lib_20080111'}) ],
+ [ @dumps{'somebox_lib_20080111','somebox_lib_20080222222222'} ],
+ "sort dumps by write_timestamps");
+got_dumps([ Amanda::DB::Catalog::sort_dumps(['-write_timestamp'],
+ @dumps{'somebox_lib_20080111','somebox_lib_20080222222222'}) ],
+ [ @dumps{'somebox_lib_20080222222222','somebox_lib_20080111'} ],
+ "sort dumps by write_timestamps, reverse");
+
+got_dumps([ Amanda::DB::Catalog::sort_dumps(['hostname', '-diskname', 'write_timestamp'],
+ @dumps{
+ 'somebox_lib_20080222222222',
+ 'somebox_usr_bin_20080313133333',
+ 'somebox_lib_20080313133333',
+ 'otherbox_lib_20080313133333',
+ 'somebox_lib_20080111',
+ }) ],
+ [ @dumps{
+ 'otherbox_lib_20080313133333',
+ 'somebox_usr_bin_20080313133333',
+ 'somebox_lib_20080111',
+ 'somebox_lib_20080222222222',
+ 'somebox_lib_20080313133333',
+ } ],
+ "multi-key dump sort");
+
+got_dumps([ Amanda::DB::Catalog::sort_dumps(['nparts'],
+ @dumps{
+ 'somebox_lib_20080313133333', # nparts=10
+ 'somebox_lib_20080222222222', # nparts=2
+ }) ],
+ [ @dumps{
+ 'somebox_lib_20080222222222', # nparts=2
+ 'somebox_lib_20080313133333', # nparts=10
+ } ],
+ "dumps' nparts is sorted numerically, not lexically");
+
+got_dumps([ Amanda::DB::Catalog::sort_dumps(['-level'],
+ @dumps{
+ 'somebox_lib_20080313133333', # level=0
+ 'somebox_usr_bin_20080313133333', # level=1
+ }) ],
+ [ @dumps{
+ 'somebox_usr_bin_20080313133333', # level=1
+ 'somebox_lib_20080313133333', # level=0
+ } ],
+ "sort dumps by level, reversed");
+
+got_dumps([ Amanda::DB::Catalog::sort_dumps(['dump_timestamp'],
+ @dumps{
+ 'somebox_lib_20080313133333', # dts=20080313133333
+ 'otherbox_usr_bin_20080313133333_1', # dts=20080311131133
+ }) ],
+ [ @dumps{
+ 'otherbox_usr_bin_20080313133333_1', # dts=20080311131133
+ 'somebox_lib_20080313133333', # dts=20080313133333
+ } ],
+ "sort dumps by write_timestamp");
+
+
+# install the multi-taper catalog
+$cat = Installcheck::Catalogs::load("multi-taper");
+$cat->install();
+%dumps = $cat->get_dumps();
+%parts = $cat->get_parts();
+
+Amanda::DB::Catalog::_clear_cache();
+
+got_parts([ sortparts Amanda::DB::Catalog::get_parts() ],
+ [ sortparts parts_named qr/.*/ ],
+ "get_parts returns all parts when given no parameters");