| 1 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 2 |
# |
| 3 |
# This test aims to validate that pg_combinebackup works in the degenerate |
| 4 |
# case where it is invoked on a single full backup and that it can produce |
| 5 |
# a new, valid manifest when it does. Secondarily, it checks that |
| 6 |
# pg_combinebackup does not produce a manifest when run with --no-manifest. |
| 7 |
|
| 8 |
use strict; |
| 9 |
use warnings FATAL => 'all'; |
| 10 |
use File::Compare; |
| 11 |
use PostgreSQL::Test::Cluster; |
| 12 |
use PostgreSQL::Test::Utils; |
| 13 |
use Test::More; |
| 14 |
|
| 15 |
# Can be changed to test the other modes. |
| 16 |
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy'; |
| 17 |
|
| 18 |
note "testing using mode $mode"; |
| 19 |
|
| 20 |
# Set up a new database instance. |
| 21 |
my $node = PostgreSQL::Test::Cluster->new('node'); |
| 22 |
$node->init(has_archiving => 1, allows_streaming => 1); |
| 23 |
$node->start; |
| 24 |
|
| 25 |
# Take a full backup. |
| 26 |
my $original_backup_path = $node->backup_dir . '/original'; |
| 27 |
$node->command_ok( |
| 28 |
[ |
| 29 |
'pg_basebackup', |
| 30 |
'--pgdata' => $original_backup_path, |
| 31 |
'--no-sync', |
| 32 |
'--checkpoint' => 'fast', |
| 33 |
], |
| 34 |
"full backup"); |
| 35 |
|
| 36 |
# Verify the full backup. |
| 37 |
$node->command_ok([ 'pg_verifybackup', $original_backup_path ], |
| 38 |
"verify original backup"); |
| 39 |
|
| 40 |
# Process the backup with pg_combinebackup using various manifest options. |
| 41 |
sub combine_and_test_one_backup |
| 42 |
{ |
| 43 |
my ($backup_name, $failure_pattern, @extra_options) = @_; |
| 44 |
my $revised_backup_path = $node->backup_dir . '/' . $backup_name; |
| 45 |
$node->command_ok( |
| 46 |
[ |
| 47 |
'pg_combinebackup', |
| 48 |
$original_backup_path, |
| 49 |
'--output' => $revised_backup_path, |
| 50 |
'--no-sync', |
| 51 |
@extra_options, |
| 52 |
], |
| 53 |
"pg_combinebackup with @extra_options"); |
| 54 |
if (defined $failure_pattern) |
| 55 |
{ |
| 56 |
$node->command_fails_like([ 'pg_verifybackup', $revised_backup_path ], |
| 57 |
$failure_pattern, "unable to verify backup $backup_name"); |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
$node->command_ok([ 'pg_verifybackup', $revised_backup_path ], |
| 62 |
"verify backup $backup_name"); |
| 63 |
} |
| 64 |
} |
| 65 |
combine_and_test_one_backup('nomanifest', |
| 66 |
qr/could not open file.*backup_manifest/, |
| 67 |
'--no-manifest'); |
| 68 |
combine_and_test_one_backup('csum_none', undef, '--manifest-checksums=NONE', |
| 69 |
$mode); |
| 70 |
combine_and_test_one_backup('csum_sha224', |
| 71 |
undef, '--manifest-checksums=SHA224', $mode); |
| 72 |
|
| 73 |
# Verify that SHA224 is mentioned in the SHA224 manifest lots of times. |
| 74 |
my $sha224_manifest = |
| 75 |
slurp_file($node->backup_dir . '/csum_sha224/backup_manifest'); |
| 76 |
my $sha224_count = (() = $sha224_manifest =~ /SHA224/mig); |
| 77 |
cmp_ok($sha224_count, |
| 78 |
'>', 100, "SHA224 is mentioned many times in SHA224 manifest"); |
| 79 |
|
| 80 |
# Verify that SHA224 is mentioned in the SHA224 manifest lots of times. |
| 81 |
my $nocsum_manifest = |
| 82 |
slurp_file($node->backup_dir . '/csum_none/backup_manifest'); |
| 83 |
my $nocsum_count = (() = $nocsum_manifest =~ /Checksum-Algorithm/mig); |
| 84 |
is($nocsum_count, 0, |
| 85 |
"Checksum-Algorithm is not mentioned in no-checksum manifest"); |
| 86 |
|
| 87 |
# OK, that's all. |
| 88 |
done_testing(); |