--- a/bin/amdumpext Mon Dec 16 15:29:40 2013 +0100
+++ b/bin/amdumpext Mon Dec 16 15:29:52 2013 +0100
@@ -88,7 +88,7 @@
'level=i@' => \@opt_level, # --level n
'dumpdates=s' => \$opt_dumpdates, # --dumpdates <file>
'host=s' => sub { }, # ignore
- 'disk=s' => sub { }, # ignore
+ 'disk=s' => sub { }, # ignore
) or pod2usage;
given ($command) {
@@ -121,26 +121,26 @@
# may: $opt_level
OK "$ME version $VERSION";
- OK "euid=$> (" . getpwuid($>) . ')';
+ OK "euid=$> (" . getpwuid($>) . ')';
OK "egid=" . do {
- my $gid = (split ' ', $))[0];
- my $group = getgrgid $gid;
- "$gid ($group)";
+ my $gid = (split ' ', $))[0];
+ my $group = getgrgid $gid;
+ "$gid ($group)";
};
OK "groups=" . do {
- my (undef, @gids) = split ' ', $);
- my @groups = map { '' . getgrgid $_ } @gids;
- "@gids (@groups)";
+ my (undef, @gids) = split ' ', $);
+ my @groups = map { '' . getgrgid $_ } @gids;
+ "@gids (@groups)";
};
foreach my $tool (qw(dump restore)) {
- if ($_ = (grep { -x ($_ .= "/$tool") } split /:/ => $ENV{PATH})[0]) {
- chomp(my $version = (`$_ 2>&1`)[0]);
- OK "$tool is $version";
- }
- else {
- ERROR "$tool not found in $ENV{PATH}";
- }
+ if ($_ = (grep { -x ($_ .= "/$tool") } split /:/ => $ENV{PATH})[0]) {
+ chomp(my $version = (`$_ 2>&1`)[0]);
+ OK "$tool is $version";
+ }
+ else {
+ ERROR "$tool not found in $ENV{PATH}";
+ }
}
# check the device
@@ -172,7 +172,7 @@
foreach my $level (@opt_level) {
my @cmd = (
dump => "-$level",
- '-S', # estimate
+ '-S', # estimate
$opt_record && $opt_dumpdates ? (-D => expand($opt_dumpdates)) : (),
device($opt_device),
);
@@ -218,8 +218,9 @@
my @dump = (
dump => "-$opt_level[0]",
- #'-v', # verbose
- -f => '-',
+
+ #'-v', # verbose
+ -f => '-',
$opt_record ? '-u' : (),
$opt_record && $opt_dumpdates ? (-D => expand($opt_dumpdates)) : (),
device($opt_device)
@@ -235,17 +236,18 @@
if ($opt_index) {
my $pid = fork // die "Can't fork: $!\n";
if (not $pid) {
- $0 = "$ME [about to exec dump]";
+ $0 = "$ME [about to exec dump]";
- # dump will be execed soon, first we've to establish
- # the channels - one for STDOUT, and one for STDIN
+ # dump will be execed soon, first we've to establish
+ # the channels - one for STDOUT, and one for STDIN
open(STDOUT, '|-') or do {
- # this is the child that will read
- # the STDOUT from dump
- $0 = "$ME [stdout < dump]";
+
+ # this is the child that will read
+ # the STDOUT from dump
+ $0 = "$ME [stdout < dump]";
my $pid = open(my $restore, '|-') or do {
- $0 = "$ME [toc]";
+ $0 = "$ME [toc]";
open(STDOUT, '|-') or do {
postprocess_toc($idx);
exit 0;
@@ -254,38 +256,38 @@
die "Can't exec `restore -tvf -`: $!";
};
- # the restore may close it's input, we'll get
- # a SIG{PIPE} because of this
- local $SIG{PIPE} = sub {
- close $restore;
- $restore = undef;
- $SIG{PIPE} = 'default';
- };
+ # the restore may close it's input, we'll get
+ # a SIG{PIPE} because of this
+ local $SIG{PIPE} = sub {
+ close $restore;
+ $restore = undef;
+ $SIG{PIPE} = 'default';
+ };
local $/ = \(my $x = 64 * 1024);
while (<STDIN>) {
print $_;
print $restore $_ if $restore;
}
- close($restore) if $restore;
+ close($restore) if $restore;
exit 0;
};
-
+
open(STDERR, '|-') or do {
- $0 = "$ME [stderr < dump]";
+ $0 = "$ME [stderr < dump]";
postprocess_dump_messages($msg);
exit 0;
};
- # we need to fork again, otherwise dump sees
- # the end of the above children and complains
- my $pid = fork // die "Can't fork: $!\n";
- if (not $pid) {
- exec @dump;
- die "Can't exec `@dump': $!\n";
- }
+ # we need to fork again, otherwise dump sees
+ # the end of the above children and complains
+ my $pid = fork // die "Can't fork: $!\n";
+ if (not $pid) {
+ exec @dump;
+ die "Can't exec `@dump': $!\n";
+ }
- waitpid($pid, 0);
+ waitpid($pid, 0);
}
waitpid($pid, 0);
@@ -318,11 +320,12 @@
sub postprocess_dump_messages {
- select +shift; # send output to the message channel
+ select +shift; # send output to the message channel
while (<STDIN>) {
print "| $_";
if (/^\s+DUMP: (\d+) blocks?/) {
+
# we assume a block size of 1K
say "sendbackup: size $1";
}
@@ -352,7 +355,6 @@
select +shift;
die 'IFS is not as expected!' if $/ ne "\n";
-
my $buffer = undef;
my $type = undef;
@@ -364,7 +366,8 @@
if (1 .. defined && /\Adir\s+\d+\s+(.*)\Z/) {
$buffer = '';
$type = 'dir';
- die "Unexpected end of input while reading from restore -tvf\n" if not defined;
+ die "Unexpected end of input while reading from restore -tvf\n"
+ if not defined;
next;
}