Skip to content

Commit f989f71

Browse files
committed
TAP: Add support for taking filesystem level backups
1 parent 8c361e4 commit f989f71

File tree

1 file changed

+71
-12
lines changed

1 file changed

+71
-12
lines changed

src/test/perl/PostgresNode.pm

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,81 @@ sub backup
463463
my $port = $self->port;
464464
my $name = $self->name;
465465

466-
print "# Taking backup $backup_name from node \"$name\"\n";
466+
print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
467467
TestLib::system_or_bail("pg_basebackup -D $backup_path -p $port -x");
468468
print "# Backup finished\n";
469469
}
470470

471+
=item $node->backup_fs_hot(backup_name)
472+
473+
Create a backup with a filesystem level copy in $node->backup_dir,
474+
including transaction logs. Archiving must be enabled as pg_start_backup
475+
and pg_stop_backup are used. This is not checked or enforced.
476+
477+
The backup name is passed as the backup label to pg_start_backup.
478+
479+
=cut
480+
481+
sub backup_fs_hot
482+
{
483+
my ($self, $backup_name) = @_;
484+
$self->_backup_fs($backup_name, 1);
485+
}
486+
487+
=item $node->backup_fs_cold(backup_name)
488+
489+
Create a backup with a filesystem level copy in $node->backup dir,
490+
including transaction logs. The server must be stopped as no
491+
attempt to handle concurrent writes is made.
492+
493+
Use backup or backup_fs_hot if you want to back up a running
494+
server.
495+
496+
=cut
497+
498+
sub backup_fs_cold
499+
{
500+
my ($self, $backup_name) = @_;
501+
$self->_backup_fs($backup_name, 0);
502+
}
503+
504+
505+
# Common sub of backup_fs_hot and backup_fs_cold
506+
sub _backup_fs
507+
{
508+
my ($self, $backup_name, $hot) = @_;
509+
my $backup_path = $self->backup_dir . '/' . $backup_name;
510+
my $port = $self->port;
511+
my $name = $self->name;
512+
513+
print "# Taking filesystem level backup $backup_name from node \"$name\"\n";
514+
515+
if ($hot) {
516+
my $stdout = $self->psql_check('postgres', "SELECT * FROM pg_start_backup('$backup_name');");
517+
print "# pg_start_backup: $stdout\n";
518+
}
519+
520+
RecursiveCopy::copypath($self->data_dir, $backup_path,
521+
filterfn => sub {
522+
my $src = shift;
523+
return $src !~ /\/pg_log\// && $src !~ /\/postmaster.pid$/;
524+
}
525+
);
526+
527+
if ($hot)
528+
{
529+
# We ignore pg_stop_backup's return value. We also assume archiving
530+
# is enabled; otherwise the caller will have to copy the remaining
531+
# segments.
532+
my $stdout = $self->psql_check('postgres', 'SELECT * FROM pg_stop_backup();');
533+
print "# pg_stop_backup: $stdout\n";
534+
}
535+
536+
print "# Backup finished\n";
537+
}
538+
539+
540+
471541
=pod
472542
473543
=item $node->init_from_backup(root_node, backup_name)
@@ -917,17 +987,6 @@ Pass additional parameters to psql. Must be an arrayref.
917987
918988
e.g.
919989
920-
my ($stdout, $stderr, $timed_out);
921-
my $cmdret = $psql_expert('postgres', 'SELECT pg_sleep(60)',
922-
stdout => \$stdout, stderr => \$stderr,
923-
timeout => 30, timed_out => \$timed_out,
924-
extra_params => ['--single-transaction'])
925-
926-
will set $cmdret to undef and $timed_out to a true value.
927-
928-
$psql_expert('postgres', $sql, on_error_die => 1);
929-
930-
dies with an informative message if $sql fails.
931990
932991
=cut
933992

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy