|
| 1 | +# Copyright (c) 2021-2024, PostgreSQL Global Development Group |
| 2 | + |
| 3 | +use strict; |
| 4 | +use warnings FATAL => 'all'; |
| 5 | +use File::Copy; |
| 6 | +use PostgreSQL::Test::Cluster; |
| 7 | +use PostgreSQL::Test::Utils; |
| 8 | +use Test::More; |
| 9 | + |
| 10 | +# Can be changed to test the other modes. |
| 11 | +my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy'; |
| 12 | + |
| 13 | +note "testing using mode $mode"; |
| 14 | + |
| 15 | +# Set up a new database instance. |
| 16 | +my $primary = PostgreSQL::Test::Cluster->new('primary'); |
| 17 | +$primary->init(has_archiving => 1, allows_streaming => 1); |
| 18 | +$primary->append_conf('postgresql.conf', 'summarize_wal = on'); |
| 19 | +$primary->start; |
| 20 | + |
| 21 | +# Take a full backup. |
| 22 | +my $backup1path = $primary->backup_dir . '/backup1'; |
| 23 | +$primary->command_ok( |
| 24 | + [ 'pg_basebackup', '-D', $backup1path, '--no-sync', '-cfast' ], |
| 25 | + "full backup"); |
| 26 | + |
| 27 | +# Take an incremental backup. |
| 28 | +my $backup2path = $primary->backup_dir . '/backup2'; |
| 29 | +$primary->command_ok( |
| 30 | + [ |
| 31 | + 'pg_basebackup', '-D', $backup2path, '--no-sync', '-cfast', |
| 32 | + '--incremental', $backup1path . '/backup_manifest' |
| 33 | + ], |
| 34 | + "incremental backup"); |
| 35 | + |
| 36 | +# Find an incremental file in the incremental backup for which there is a full |
| 37 | +# file in the full backup. When we find one, replace the full file with an |
| 38 | +# incremental file. |
| 39 | +my @filelist = grep { /^INCREMENTAL\./ } slurp_dir("$backup2path/base/1"); |
| 40 | +my $success = 0; |
| 41 | +for my $iname (@filelist) |
| 42 | +{ |
| 43 | + my $name = $iname; |
| 44 | + $name =~ s/^INCREMENTAL.//; |
| 45 | + |
| 46 | + if (-f "$backup1path/base/1/$name") |
| 47 | + { |
| 48 | + copy("$backup2path/base/1/$iname", "$backup1path/base/1/$iname") |
| 49 | + || die "copy $backup2path/base/1/$iname: $!"; |
| 50 | + unlink("$backup1path/base/1/$name") |
| 51 | + || die "unlink $backup1path/base/1/$name: $!"; |
| 52 | + $success = 1; |
| 53 | + last; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +# pg_combinebackup should fail. |
| 58 | +my $outpath = $primary->backup_dir . '/out'; |
| 59 | +$primary->command_fails_like( |
| 60 | + [ |
| 61 | + 'pg_combinebackup', $backup1path, $backup2path, '-o', $outpath, |
| 62 | + ], |
| 63 | + qr/full backup contains unexpected incremental file/, |
| 64 | + "pg_combinebackup fails"); |
| 65 | + |
| 66 | +done_testing(); |
0 commit comments