1 # Copyright (c) 2009-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 => 21;
22 use lib "@amperldir@";
26 use Amanda::Constants;
29 use Installcheck::Application;
32 unless ($Amanda::Constants::GNUTAR and -x $Amanda::Constants::GNUTAR) {
34 skip("GNU tar is not available", Test::More->builder->expected_tests);
39 my $app = Installcheck::Application->new('amgtar');
41 my $support = $app->support();
42 is($support->{'INDEX-LINE'}, 'YES', "supports indexing");
43 is($support->{'MESSAGE-LINE'}, 'YES', "supports messages");
44 is($support->{'CALCSIZE'}, 'YES', "supports calcsize");
46 my $root_dir = "$Installcheck::TMP/installcheck-amgtar";
47 my $back_dir = "$root_dir/to_backup";
48 my $rest_dir = "$root_dir/restore";
49 my $list_dir = "$root_dir/list";
53 my $stringify = shift @_;
58 foreach my $elm (@list) {
59 my $elm_str = $stringify? $stringify->($elm) : "$elm";
60 push @errors, "on element $elm_str: $@" unless eval {$code->($elm); 1;};
62 unless (ok(!@errors, $name)) {
63 foreach my $err (@errors) {
75 "emptied directories",
76 $back_dir, $rest_dir, $list_dir);
85 $back_dir, $rest_dir, $list_dir);
89 {'type' => 'f', 'name' => 'foo'},
90 {'type' => 'd', 'name' => 'bar/baz/bat/'},
91 {'type' => 'h', 'name' => 'hard', 'to' => 'foo'},
92 {'type' => 's', 'name' => 'sym', 'to' => 'bar'},
93 {'type' => 's', 'name' => 'a', 'to' => 'b'},
94 {'type' => 's', 'name' => 'b', 'to' => 'a'},
101 if ($obj->{'type'} eq 'f') {
102 my $fh = new IO::File("$back_dir/$obj->{'name'}", '>');
103 ok($fh, "created file $obj->{'name'}");
105 } elsif ($obj->{'type'} eq 'd') {
106 mkpath("$back_dir/$obj->{'name'}");
107 } elsif ($obj->{'type'} eq 'h') {
108 link("$back_dir/$obj->{'to'}", "$back_dir/$obj->{'name'}") or die "$!";
109 } elsif ($obj->{'type'} eq 's') {
110 symlink("$obj->{'to'}", "$back_dir/$obj->{'name'}") or die "$!";
112 die "unknown object type $obj->{'type'} for $obj->{'name'}";
115 sub {shift(@_)->{'name'}},
116 "create directory structure",
119 $app->add_property('gnutar-listdir', $list_dir);
120 # GNU tar on Solaris doesn't support this, so avoid it
121 $app->add_property('atime-preserve', 'no');
123 my $selfcheck = $app->selfcheck('device' => $back_dir, 'level' => 0, 'index' => 'line');
124 is($selfcheck->{'exit_status'}, 0, "error status ok");
125 ok(!@{$selfcheck->{'errors'}}, "no errors during selfcheck");
127 my $backup = $app->backup('device' => $back_dir, 'level' => 0, 'index' => 'line');
128 is($backup->{'exit_status'}, 0, "error status ok");
129 ok(!@{$backup->{'errors'}}, "no errors during backup")
130 or diag(@{$backup->{'errors'}});
132 is(length($backup->{'data'}), $backup->{'size'}, "reported and actual size match");
134 ok(@{$backup->{'index'}}, "index is not empty");
138 my $name = $obj->{'name'};
139 die "missing $name" unless
140 grep {"/$name" eq $_} @{$backup->{'index'}};
142 sub {shift(@_)->{'name'}},
143 "index contains all names/paths",
146 my $orig_cur_dir = POSIX::getcwd();
147 ok($orig_cur_dir, "got current directory");
149 ok(chdir($rest_dir), "changed working directory (for restore)");
151 my $restore = $app->restore('objects' => ['./foo', './bar'], 'data' => $backup->{'data'});
152 is($restore->{'exit_status'}, 0, "error status ok");
154 ok(chdir($orig_cur_dir), "changed working directory (back to original)");
156 ok(-f "$rest_dir/foo", "foo restored");
157 ok(-d "$rest_dir/bar", "bar/ restored");
158 ok(-d "$rest_dir/bar", "bar/baz/bat/ restored");