use Amanda::Debug qw( :logging );
use Amanda::Paths;
use Amanda::Util qw( :constants :encoding );
+use Amanda::MainLoop qw( :GIOCondition );
my $_DATA_DIR_TAR = "data_dir.tar";
my $_ARCHIVE_DIR_TAR = "archive_dir.tar";
$self->{'props'}->{$pname} = $conf_props->{$pname}->{'values'}->[0];
}
}
- # check for properties like 'foo-pg-host' where the device is 'foo'
- if ($self->{'args'}->{'device'}) {
+ # check for properties like 'foo-pg-host' where the diskname is 'foo'
+ if ($self->{'args'}->{'disk'}) {
foreach my $pname (@PROP_NAMES) {
- my $tmp = "$self->{'args'}->{'device'}-$pname";
+ my $tmp = "$self->{'args'}->{'disk'}-$pname";
if ($conf_props->{$tmp}) {
debug("More than one value for $tmp. Using the first.")
if scalar(@{$conf_props->{$tmp}->{'values'}}) > 1;
push @cmd, '--quiet', '--output', '/dev/null', '--command', $cmd, $self->{'props'}->{'pg-db'};
debug("running " . join(" ", @cmd));
- my $status = system(@cmd);
+
+ my ($wtr, $rdr);
+ my $err = Symbol::gensym;
+ my $pid = open3($wtr, $rdr, $err, @cmd);
+ close($wtr);
+
+ my $file_to_close = 2;
+ my $psql_stdout_src = Amanda::MainLoop::fd_source($rdr,
+ $G_IO_IN|$G_IO_HUP|$G_IO_ERR);
+ my $psql_stderr_src = Amanda::MainLoop::fd_source($err,
+ $G_IO_IN|$G_IO_HUP|$G_IO_ERR);
+ $psql_stdout_src->set_callback(sub {
+ my $line = <$rdr>;
+ if (!defined $line) {
+ $file_to_close--;
+ $psql_stdout_src->remove();
+ Amanda::MainLoop::quit() if $file_to_close == 0;
+ return;
+ }
+ chomp $line;
+ debug("psql stdout: $line");
+ if ($line =~ /NOTICE: pg_stop_backup complete, all required WAL segments have been archived/) {
+ } else {
+ $self->print_to_server("psql stdout: $line",
+ $Amanda::Script_App::GOOD);
+ }
+ });
+ $psql_stderr_src->set_callback(sub {
+ my $line = <$err>;
+ if (!defined $line) {
+ $file_to_close--;
+ $psql_stderr_src->remove();
+ Amanda::MainLoop::quit() if $file_to_close == 0;
+ return;
+ }
+ chomp $line;
+ debug("psql stderr: $line");
+ if ($line =~ /NOTICE: pg_stop_backup complete, all required WAL segments have been archived/) {
+ } else {
+ $self->print_to_server("psql stderr: $line",
+ $Amanda::Script_App::GOOD);
+ }
+ });
+
+ close($wtr);
+ Amanda::MainLoop::run();
+ close($rdr);
+ close($err);
+
+ waitpid $pid, 0;
+ my $status = $?;
$ENV{'PGPASSWORD'} = $orig_pgpassword || '';
$ENV{'PGPASSFILE'} = $orig_pgpassfile || '';
- return 0 == ($status >>8)
+ return 0 == ($status >> 8)
}
sub command_selfcheck {
# this works!)
local *TAROUT;
my $conf = $self->{'args'}->{'config'} || 'NOCONFIG';
- my $cmd = "$self->{'runtar'} $conf $Amanda::Constants::GNUTAR --create --directory $self->{'props'}->{'pg-archivedir'} $fname | $Amanda::Constants::GNUTAR --extract --to-stdout";
+ my $cmd = "$self->{'runtar'} $conf $Amanda::Constants::GNUTAR --create --file - --directory $self->{'props'}->{'pg-archivedir'} $fname | $Amanda::Constants::GNUTAR --file - --extract --to-stdout";
debug("running: $cmd");
open(TAROUT, "$cmd |");
my ($start, $end, $lab);
'--directory', $self->{'props'}->{'pg-archivedir'}, @wal_files);
} else {
my $dummydir = $self->_make_dummy_dir();
- $self->{'done_cb'}->(_run_tar_totals($self,
+ $self->{'done_cb'}->(_run_tar_totals($self, '--file', '-',
'--directory', $dummydir, "empty-incremental"));
rmtree($dummydir);
}
# create the final tar file
- my $size = _run_tar_totals($self, '--directory', $tmp,
+ my $size = _run_tar_totals($self, '--directory', $tmp, '--file', '-',
$_ARCHIVE_DIR_TAR, $_DATA_DIR_TAR);
$self->{'state_cb'}->($self, $end_wal);
$self->{'state_cb'}->($self, $max_wal ? $max_wal : $end_wal);
if (@wal_files) {
- $self->{'done_cb'}->(_run_tar_totals($self,
+ $self->{'done_cb'}->(_run_tar_totals($self, '--file', '-',
'--directory', $self->{'props'}->{'pg-archivedir'}, @wal_files));
} else {
my $dummydir = $self->_make_dummy_dir();
- $self->{'done_cb'}->(_run_tar_totals($self,
+ $self->{'done_cb'}->(_run_tar_totals($self, '--file', '-',
'--directory', $dummydir, "empty-incremental"));
rmtree($dummydir);
}
if ($self->{'args'}->{'level'} > 0) {
debug("extracting incremental backup to $cur_dir/$_ARCHIVE_DIR_RESTORE");
$status = system($self->{'args'}->{'gnutar-path'}, '--extract',
+ '--file', '-',
'--ignore-zeros',
'--exclude', 'empty-incremental',
'--directory', $_ARCHIVE_DIR_RESTORE) >> 8;
if (!-d $_DATA_DIR_RESTORE) {
mkdir($_DATA_DIR_RESTORE) or die("could not create archive WAL directory: $!");
}
- $status = system($self->{'args'}->{'gnutar-path'}, '--extract') >> 8;
+ $status = system($self->{'args'}->{'gnutar-path'}, '--extract', '--file', '-',) >> 8;
(0 == $status) or die("Failed to extract base backup (exit status: $status)");
debug("extracting archive dir to $cur_dir/$_ARCHIVE_DIR_RESTORE");