X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=application-src%2Fampgsql.pl;h=5c930ed323eaf099a202112a8945125de7c64474;hb=7a410be9a313db41cc40d3f4cc8a4e988cef6046;hp=e8056d5de12f84ad6879588ba7a2ad681f30185b;hpb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;p=debian%2Famanda diff --git a/application-src/ampgsql.pl b/application-src/ampgsql.pl index e8056d5..5c930ed 100644 --- a/application-src/ampgsql.pl +++ b/application-src/ampgsql.pl @@ -39,6 +39,7 @@ use Amanda::Config qw( :init :getconf config_dir_relative string_to_boolean ); 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"; @@ -89,10 +90,10 @@ sub new { $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; @@ -208,12 +209,62 @@ sub _run_psql_command { 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 { @@ -491,7 +542,7 @@ sub _get_backup_info { # 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); @@ -676,13 +727,13 @@ sub _base_backup { '--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); @@ -719,11 +770,11 @@ sub _incr_backup { $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); } @@ -808,6 +859,7 @@ sub command_restore { 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; @@ -817,7 +869,7 @@ sub command_restore { 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");