Debian Codegraph @

src/bin/pg_combinebackup/t/006_db_file_copy.pl

raw
1 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
2
3 use strict;
4 use warnings FATAL => 'all';
5 use File::Compare;
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 # Initial setup.
22 $primary->safe_psql('postgres', <<EOM);
23 CREATE DATABASE lakh OID = 100000 STRATEGY = FILE_COPY
24 EOM
25 $primary->safe_psql('lakh', <<EOM);
26 CREATE TABLE t1 (a int)
27 EOM
28
29 # Take a full backup.
30 my $backup1path = $primary->backup_dir . '/backup1';
31 $primary->command_ok(
32 [
33 'pg_basebackup',
34 '--pgdata' => $backup1path,
35 '--no-sync',
36 '--checkpoint' => 'fast'
37 ],
38 "full backup");
39
40 # Now make some database changes.
41 $primary->safe_psql('postgres', <<EOM);
42 DROP DATABASE lakh;
43 CREATE DATABASE lakh OID = 100000 STRATEGY = FILE_COPY
44 EOM
45
46 # Take an incremental backup.
47 my $backup2path = $primary->backup_dir . '/backup2';
48 $primary->command_ok(
49 [
50 'pg_basebackup',
51 '--pgdata' => $backup2path,
52 '--no-sync',
53 '--checkpoint' => 'fast',
54 '--incremental' => $backup1path . '/backup_manifest'
55 ],
56 "incremental backup");
57
58 # Recover the incremental backup.
59 my $restore = PostgreSQL::Test::Cluster->new('restore');
60 $restore->init_from_backup(
61 $primary, 'backup2',
62 combine_with_prior => ['backup1'],
63 combine_mode => $mode);
64 $restore->start();
65
66 # Query the DB.
67 my $stdout;
68 my $stderr;
69 $restore->psql(
70 'lakh', 'SELECT * FROM t1',
71 stdout => \$stdout,
72 stderr => \$stderr);
73 is($stdout, '', 'SELECT * FROM t1: no stdout');
74 like(
75 $stderr,
76 qr/relation "t1" does not exist/,
77 'SELECT * FROM t1: stderr missing table');
78
79 done_testing();