1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add end-to-end testing of pg_basebackup's tar-format output.

The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case.  (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)

Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.

This test assumes that the local "tar" has the "-C directory"
switch.  Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.

Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
This commit is contained in:
Tom Lane
2021-03-17 14:52:55 -04:00
parent c783e656d4
commit 081876d75e
3 changed files with 78 additions and 14 deletions

View File

@ -538,8 +538,11 @@ sub append_conf
=item $node->backup(backup_name)
Create a hot backup with B<pg_basebackup> in subdirectory B<backup_name> of
B<< $node->backup_dir >>, including the WAL. WAL files
fetched at the end of the backup, not streamed.
B<< $node->backup_dir >>, including the WAL.
By default, WAL files are fetched at the end of the backup, not streamed.
You can adjust that and other things by passing an array of additional
B<pg_basebackup> command line options in the keyword parameter backup_options.
You'll have to configure a suitable B<max_wal_senders> on the
target server since it isn't done by default.
@ -548,7 +551,7 @@ target server since it isn't done by default.
sub backup
{
my ($self, $backup_name) = @_;
my ($self, $backup_name, %params) = @_;
my $backup_path = $self->backup_dir . '/' . $backup_name;
my $name = $self->name;
@ -556,7 +559,8 @@ sub backup
TestLib::system_or_bail(
'pg_basebackup', '-D', $backup_path, '-h',
$self->host, '-p', $self->port, '--checkpoint',
'fast', '--no-sync');
'fast', '--no-sync',
@{ $params{backup_options} });
print "# Backup finished\n";
return;
}
@ -650,6 +654,11 @@ of a backup previously created on that node with $node->backup.
Does not start the node after initializing it.
By default, the backup is assumed to be plain format. To restore from
a tar-format backup, pass the name of the tar program to use in the
keyword parameter tar_program. Note that tablespace tar files aren't
handled here.
Streaming replication can be enabled on this node by passing the keyword
parameter has_streaming => 1. This is disabled by default.
@ -687,8 +696,21 @@ sub init_from_backup
mkdir $self->archive_dir;
my $data_path = $self->data_dir;
rmdir($data_path);
RecursiveCopy::copypath($backup_path, $data_path);
if (defined $params{tar_program})
{
mkdir($data_path);
TestLib::system_or_bail($params{tar_program}, 'xf',
$backup_path . '/base.tar',
'-C', $data_path);
TestLib::system_or_bail($params{tar_program}, 'xf',
$backup_path . '/pg_wal.tar',
'-C', $data_path . '/pg_wal');
}
else
{
rmdir($data_path);
RecursiveCopy::copypath($backup_path, $data_path);
}
chmod(0700, $data_path);
# Base configuration for this node