/usr/lib/amanda/amcheck-device is in amanda-common 1:3.3.6-4.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | #! /usr/bin/perl
# Copyright (c) 2009-2013 Zmanda Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
use lib '/usr/lib/amanda/perl';
use strict;
use warnings;
use Amanda::Util qw( :constants );
use Amanda::Config qw( :init :getconf );
use Amanda::Logfile qw( :logtype_t log_add $amanda_log_trace_log );
use Amanda::Debug;
use Amanda::Device qw( :constants );
use Amanda::MainLoop;
use Amanda::Changer;
use Amanda::Taper::Scan;
use Amanda::Interactivity;
use Getopt::Long;
Amanda::Util::setup_application("amcheck-device", "server", $CONTEXT_CMDLINE);
my $config_overrides = new_config_overrides($#ARGV+1);
my $overwrite = 0;
Getopt::Long::Configure(qw{bundling});
GetOptions(
'version' => \&Amanda::Util::version_opt,
'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
'w' => \$overwrite,
) or usage();
sub usage {
print STDERR "USAGE: amcheck-device <config> [-w] <config-overwrites>";
exit 1;
}
if (@ARGV != 1) {
usage();
}
set_config_overrides($config_overrides);
config_init($CONFIG_INIT_EXPLICIT_NAME, $ARGV[0]);
my ($cfgerr_level, @cfgerr_errors) = config_errors();
if ($cfgerr_level >= $CFGERR_WARNINGS) {
config_print_errors();
if ($cfgerr_level >= $CFGERR_ERRORS) {
print STDERR "Errors processing config file";
exit 1;
}
}
Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
my $exit_status = 0;
sub _user_msg_fn {
my %params = @_;
if (exists $params{'scan_failed'}) {
print STDERR "Taper scan algorithm did not find an acceptable volume.\n";
if ($params{'expected_label'} or $params{'expected_new'}) {
my @exp;
if ($params{'expected_label'}) {
push @exp, "volume '$params{expected_label}'";
}
if ($params{'expected_new'}) {
push @exp, "a new volume";
}
my $exp = join(" or ", @exp);
print STDERR " (expecting $exp)\n";
}
} elsif (exists($params{'text'})) {
print STDERR "$params{'text'}\n";
} elsif (exists($params{'scan_slot'})) {
print STDERR "slot $params{'slot'}:";
} elsif (exists($params{'search_label'})) {
print STDERR "Searching for label '$params{'label'}':";
} elsif (exists($params{'slot_result'}) ||
exists($params{'search_result'})) {
if (defined($params{'err'}) and ref($params{'err'}) eq "HASH") {
if (exists($params{'search_result'}) &&
defined($params{'err'}->{'this_slot'})) {
print STDERR "slot $params{'err'}->{'this_slot'}:";
}
print STDERR " $params{'err'}\n";
} elsif (!$params{'res'}) {
my $volume_label = $params{'label'};
if ($params{'slot'}) {
print STDERR "slot $params{'slot'}:";
}
if ($params{'active'}) {
print STDERR " volume '$volume_label' is still active and cannot be overwritten\n";
} elsif ($params{'does_not_match_labelstr'}) {
print STDERR " volume '$volume_label' does not match labelstr '$params{'labelstr'}'\n";
} elsif ($params{'not_in_tapelist'}) {
print STDERR " volume '$volume_label' is not in the tapelist\n"
} elsif ($params{'non_amanda'}) {
print STDERR " not an amanda volume\n";
} elsif ($params{'volume_error'}) {
print STDERR " $params{'err'}\n";
} elsif ($params{'not_autolabel'}) {
print STDERR " The volume can't be labelled\n";
} elsif ($params{'empty'}) {
print STDERR " The volume is empty\n";
} elsif ($params{'not_success'}) {
print STDERR " $params{'err'}\n";
} else {
print STDERR " volume '$volume_label'\n";
}
} else { # res must be defined
my $directtcp = "";
my $res = $params{'res'};
my $dev = $res->{'device'};
if ($dev->directtcp_supported()) {
$directtcp = "DIRECTTCP ";
}
print STDOUT "DATA-PATH AMANDA $directtcp\n";
if (exists($params{'search_result'})) {
print STDERR "found in slot $res->{'this_slot'}:";
}
if ($dev->status == $DEVICE_STATUS_SUCCESS) {
my $volume_label = $res->{device}->volume_label;
if ($params{'active'}) {
print STDERR " volume '$volume_label' is still active and cannot be overwritten\n";
} elsif ($params{'does_not_match_labelstr'}) {
print STDERR " volume '$volume_label' does not match labelstr '$params{'labelstr'}'\n";
} elsif ($params{'not_in_tapelist'}) {
print STDERR " volume '$volume_label' is not in the tapelist\n"
} else {
print STDERR " volume '$volume_label'\n";
}
} elsif ($dev->status & $DEVICE_STATUS_VOLUME_UNLABELED and
$dev->volume_header and
$dev->volume_header->{'type'} == $Amanda::Header::F_EMPTY) {
print STDERR " contains an empty volume\n";
} elsif ($dev->status & $DEVICE_STATUS_VOLUME_UNLABELED and
$dev->volume_header and
$dev->volume_header->{'type'} == $Amanda::Header::F_WEIRD) {
my $autolabel = getconf($CNF_AUTOLABEL);
if ($autolabel->{'non_amanda'}) {
print STDERR " contains a non-Amanda volume\n";
} else {
print STDERR " contains a non-Amanda volume; check and relabel it with 'amlabel -f'\n";
}
} elsif ($dev->status & $DEVICE_STATUS_VOLUME_ERROR) {
my $message = $dev->error_or_status();
print STDERR " Can't read label: $message\n";
} else {
my $errmsg = $res->{device}->error_or_status();
print STDERR " $errmsg\n";
}
}
} else {
print STDERR "UNKNOWN\n";
}
}
sub failure {
my ($msg, $finished_cb) = @_;
print STDERR "ERROR: $msg\n";
$exit_status = 1;
$finished_cb->();
}
sub do_check {
my ($finished_cb) = @_;
my ($res, $label, $mode);
my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
my $tl = Amanda::Tapelist->new($tlf);
my $chg = Amanda::Changer->new(undef, tapelist => $tl);
return failure($chg, $finished_cb) if ($chg->isa("Amanda::Changer::Error"));
my $interactivity = Amanda::Interactivity->new(
name => getconf($CNF_INTERACTIVITY));
my $scan_name = getconf($CNF_TAPERSCAN);
my $taperscan = Amanda::Taper::Scan->new(algorithm => $scan_name,
changer => $chg,
interactivity => $interactivity,
tapelist => $tl);
my $steps = define_steps
cb_ref => \$finished_cb,
finalize => sub { $taperscan->quit(); };
step start => sub {
$taperscan->scan(
result_cb => $steps->{'result_cb'},
user_msg_fn => \&_user_msg_fn
);
};
step result_cb => sub {
(my $err, $res, $label, $mode) = @_;
if ($err) {
if ($res) {
$res->release(finished_cb => sub {
return failure($err, $finished_cb);
});
return;
} else {
return failure($err, $finished_cb);
}
}
my $modestr = ($mode == $ACCESS_APPEND)? "append" : "write";
my $slot = $res->{'this_slot'};
if (defined $res->{'device'} and defined $res->{'device'}->volume_label()) {
print "Will $modestr to volume '$label' in slot $slot.\n";
} else {
my $header = $res->{'device'}->volume_header();
if (defined $header and defined $header->{'type'} and
$header->{'type'} == $Amanda::Header::F_WEIRD) {
print "Will $modestr label '$label' to non-Amanda volume in slot $slot.\n";
} else {
print "Will $modestr label '$label' to new volume in slot $slot.\n";
}
}
$steps->{'check_access_type'}->();
};
step check_access_type => sub {
my $mat = $res->{'device'}->property_get('medium_access_type');
if (defined $mat and $mat == $MEDIA_ACCESS_MODE_WRITE_ONLY) {
print "WARNING: Media access mode is WRITE_ONLY; dumps may not be recoverable\n";
}
if (getconf_seen($CNF_DEVICE_OUTPUT_BUFFER_SIZE)) {
my $dobs = getconf($CNF_DEVICE_OUTPUT_BUFFER_SIZE);
my $block_size = $res->{'device'}->property_get("BLOCK_SIZE");
if ($block_size * 2 > $dobs) {
print "WARNING: DEVICE-OUTPUT-BUFFER-SIZE is not at least twice the block size of the device, it should be increased for better throughput\n";
}
}
$steps->{'check_overwrite'}->();
};
step check_overwrite => sub {
# if we're not overwriting, just release the reservation
if (!$overwrite) {
print "NOTE: skipping tape-writable test\n";
return $steps->{'release'}->();
}
if ($mode != $ACCESS_WRITE) {
my $modestr = Amanda::Device::DeviceAccessMode_to_string($mode);
print "NOTE: taperscan specified access mode $modestr; skipping volume-writeable test\n";
return $steps->{'release'}->();
}
print "Writing label '$label' to check writablility\n";
if (!$res->{'device'}->start($ACCESS_WRITE, $label, "X")) {
print "ERROR: writing to volume: " . $res->{'device'}->error_or_status(), "\n";
$exit_status = 1;
} else {
print "Volume '$label' is writeable.\n";
}
$steps->{'release'}->();
};
step release => sub {
$res->release(finished_cb => $steps->{'released'});
};
step released => sub {
my ($err) = @_;
return failure($err, $finished_cb) if $err;
$finished_cb->();
};
}
Amanda::MainLoop::call_later(\&do_check, \&Amanda::MainLoop::quit);
Amanda::MainLoop::run();
Amanda::Util::finish_application();
exit($exit_status);
|