1 # Copyright (c) 2009-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 => 21;
21 use lib "@amperldir@";
25 use Amanda::Constants;
28 use Installcheck::Application;
31 unless ($Amanda::Constants::GNUTAR and -x $Amanda::Constants::GNUTAR) {
33 skip("GNU tar is not available", Test::More->builder->expected_tests);
38 my $app = Installcheck::Application->new('amgtar');
40 my $support = $app->support();
41 is($support->{'INDEX-LINE'}, 'YES', "supports indexing");
42 is($support->{'MESSAGE-LINE'}, 'YES', "supports messages");
43 is($support->{'CALCSIZE'}, 'YES', "supports calcsize");
45 my $root_dir = "$Installcheck::TMP/installcheck-amgtar";
46 my $back_dir = "$root_dir/to_backup";
47 my $rest_dir = "$root_dir/restore";
48 my $list_dir = "$root_dir/list";
52 my $stringify = shift @_;
57 foreach my $elm (@list) {
58 my $elm_str = $stringify? $stringify->($elm) : "$elm";
59 push @errors, "on element $elm_str: $@" unless eval {$code->($elm); 1;};
61 unless (ok(!@errors, $name)) {
62 foreach my $err (@errors) {
74 "emptied directories",
75 $back_dir, $rest_dir, $list_dir);
84 $back_dir, $rest_dir, $list_dir);
88 {'type' => 'f', 'name' => 'foo'},
89 {'type' => 'd', 'name' => 'bar/baz/bat/'},
90 {'type' => 'h', 'name' => 'hard', 'to' => 'foo'},
91 {'type' => 's', 'name' => 'sym', 'to' => 'bar'},
92 {'type' => 's', 'name' => 'a', 'to' => 'b'},
93 {'type' => 's', 'name' => 'b', 'to' => 'a'},
100 if ($obj->{'type'} eq 'f') {
101 my $fh = new IO::File("$back_dir/$obj->{'name'}", '>');
102 ok($fh, "created file $obj->{'name'}");
104 } elsif ($obj->{'type'} eq 'd') {
105 mkpath("$back_dir/$obj->{'name'}");
106 } elsif ($obj->{'type'} eq 'h') {
107 link("$back_dir/$obj->{'to'}", "$back_dir/$obj->{'name'}") or die "$!";
108 } elsif ($obj->{'type'} eq 's') {
109 symlink("$obj->{'to'}", "$back_dir/$obj->{'name'}") or die "$!";
111 die "unknown object type $obj->{'type'} for $obj->{'name'}";
114 sub {shift(@_)->{'name'}},
115 "create directory structure",
118 $app->add_property('gnutar-listdir', $list_dir);
119 # GNU tar on Solaris doesn't support this, so avoid it
120 $app->add_property('atime-preserve', 'no');
122 my $selfcheck = $app->selfcheck('device' => $back_dir, 'level' => 0, 'index' => 'line');
123 is($selfcheck->{'exit_status'}, 0, "error status ok");
124 ok(!@{$selfcheck->{'errors'}}, "no errors during selfcheck");
126 my $backup = $app->backup('device' => $back_dir, 'level' => 0, 'index' => 'line');
127 is($backup->{'exit_status'}, 0, "error status ok");
128 ok(!@{$backup->{'errors'}}, "no errors during backup")
129 or diag(@{$backup->{'errors'}});
131 is(length($backup->{'data'}), $backup->{'size'}, "reported and actual size match");
133 ok(@{$backup->{'index'}}, "index is not empty");
137 my $name = $obj->{'name'};
138 die "missing $name" unless
139 grep {"/$name" eq $_} @{$backup->{'index'}};
141 sub {shift(@_)->{'name'}},
142 "index contains all names/paths",
145 my $orig_cur_dir = POSIX::getcwd();
146 ok($orig_cur_dir, "got current directory");
148 ok(chdir($rest_dir), "changed working directory (for restore)");
150 my $restore = $app->restore('objects' => ['./foo', './bar'], 'data' => $backup->{'data'});
151 is($restore->{'exit_status'}, 0, "error status ok");
153 ok(chdir($orig_cur_dir), "changed working directory (back to original)");
155 ok(-f "$rest_dir/foo", "foo restored");
156 ok(-d "$rest_dir/bar", "bar/ restored");
157 ok(-d "$rest_dir/bar", "bar/baz/bat/ restored");