Debian Codegraph @

src/bin/pg_combinebackup/t/009_no_full_file.pl

raw
1 # Copyright (c) 2021-2025, 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 [
25 'pg_basebackup',
26 '--pgdata' => $backup1path,
27 '--no-sync',
28 '--checkpoint' => 'fast'
29 ],
30 "full backup");
31
32 # Take an incremental backup.
33 my $backup2path = $primary->backup_dir . '/backup2';
34 $primary->command_ok(
35 [
36 'pg_basebackup',
37 '--pgdata' => $backup2path,
38 '--no-sync',
39 '--checkpoint' => 'fast',
40 '--incremental' => $backup1path . '/backup_manifest'
41 ],
42 "incremental backup");
43
44 # Find an incremental file in the incremental backup for which there is a full
45 # file in the full backup. When we find one, replace the full file with an
46 # incremental file.
47 my @filelist = grep { /^INCREMENTAL\./ } slurp_dir("$backup2path/base/1");
48 my $success = 0;
49 for my $iname (@filelist)
50 {
51 my $name = $iname;
52 $name =~ s/^INCREMENTAL.//;
53
54 if (-f "$backup1path/base/1/$name")
55 {
56 copy("$backup2path/base/1/$iname", "$backup1path/base/1/$iname")
57 || die "copy $backup2path/base/1/$iname: $!";
58 unlink("$backup1path/base/1/$name")
59 || die "unlink $backup1path/base/1/$name: $!";
60 $success = 1;
61 last;
62 }
63 }
64
65 # pg_combinebackup should fail.
66 my $outpath = $primary->backup_dir . '/out';
67 $primary->command_fails_like(
68 [
69 'pg_combinebackup', $backup1path,
70 $backup2path, '--output' => $outpath,
71 ],
72 qr/full backup contains unexpected incremental file/,
73 "pg_combinebackup fails");
74
75 done_testing();