Skip to content

Commit 35a7b28

Browse files
committed
Add PG_TEST_PG_COMBINEBACKUP_MODE
Introduces an environment variable PG_TEST_PG_COMBINEBACKUP_MODE, that determines copy mode used by pg_combinebackup in TAP tests. Defaults to "--copy" but may be set to "--clone" or "--copy-file-range" to use the alternative stategies. Reported-by: Peter Eisentraut Discussion: https://postgr.es/m/48da4a1f-ccd9-4988-9622-24f37b1de2b4%40eisentraut.org
1 parent a9577ba commit 35a7b28

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

src/bin/pg_combinebackup/t/002_compare_backups.pl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
my $tempdir = PostgreSQL::Test::Utils::tempdir_short();
1111

12+
# Can be changed to test the other modes.
13+
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
14+
15+
note "testing using mode $mode";
16+
1217
# Set up a new database instance.
1318
my $primary = PostgreSQL::Test::Cluster->new('primary');
1419
$primary->init(has_archiving => 1, allows_streaming => 1);
@@ -134,7 +139,8 @@
134139
standby => 1,
135140
has_restoring => 1,
136141
combine_with_prior => ['backup1'],
137-
tablespace_map => { $tsbackup2path => $tspitr2path });
142+
tablespace_map => { $tsbackup2path => $tspitr2path },
143+
combine_mode => $mode);
138144
$pitr2->append_conf(
139145
'postgresql.conf', qq{
140146
recovery_target_lsn = '$lsn'

src/bin/pg_combinebackup/t/003_timeline.pl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
use PostgreSQL::Test::Utils;
1111
use Test::More;
1212

13+
# Can be changed to test the other modes.
14+
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
15+
16+
note "testing using mode $mode";
17+
1318
# Set up a new database instance.
1419
my $node1 = PostgreSQL::Test::Cluster->new('node1');
1520
$node1->init(has_archiving => 1, allows_streaming => 1);
@@ -68,7 +73,8 @@
6873
# Restore the incremental backup and use it to create a new node.
6974
my $node3 = PostgreSQL::Test::Cluster->new('node3');
7075
$node3->init_from_backup($node1, 'backup3',
71-
combine_with_prior => [ 'backup1', 'backup2' ]);
76+
combine_with_prior => [ 'backup1', 'backup2' ],
77+
combine_mode => $mode);
7278
$node3->start();
7379

7480
# Let's insert one more row.

src/bin/pg_combinebackup/t/004_manifest.pl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
use PostgreSQL::Test::Utils;
1313
use Test::More;
1414

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+
1520
# Set up a new database instance.
1621
my $node = PostgreSQL::Test::Cluster->new('node');
1722
$node->init(has_archiving => 1, allows_streaming => 1);
@@ -53,9 +58,9 @@ sub combine_and_test_one_backup
5358
combine_and_test_one_backup('nomanifest',
5459
qr/could not open file.*backup_manifest/,
5560
'--no-manifest');
56-
combine_and_test_one_backup('csum_none', undef, '--manifest-checksums=NONE');
61+
combine_and_test_one_backup('csum_none', undef, '--manifest-checksums=NONE', $mode);
5762
combine_and_test_one_backup('csum_sha224',
58-
undef, '--manifest-checksums=SHA224');
63+
undef, '--manifest-checksums=SHA224', $mode);
5964

6065
# Verify that SHA224 is mentioned in the SHA224 manifest lots of times.
6166
my $sha224_manifest =

src/bin/pg_combinebackup/t/005_integrity.pl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
use PostgreSQL::Test::Utils;
1414
use Test::More;
1515

16+
# Can be changed to test the other modes.
17+
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
18+
19+
note "testing using mode $mode";
20+
1621
# Set up a new database instance.
1722
my $node1 = PostgreSQL::Test::Cluster->new('node1');
1823
$node1->init(has_archiving => 1, allows_streaming => 1);
@@ -79,21 +84,21 @@
7984

8085
# Can't combine 2 full backups.
8186
$node1->command_fails_like(
82-
[ 'pg_combinebackup', $backup1path, $backup1path, '-o', $resultpath ],
87+
[ 'pg_combinebackup', $backup1path, $backup1path, '-o', $resultpath, $mode ],
8388
qr/is a full backup, but only the first backup should be a full backup/,
8489
"can't combine full backups");
8590

8691
# Can't combine 2 incremental backups.
8792
$node1->command_fails_like(
88-
[ 'pg_combinebackup', $backup2path, $backup2path, '-o', $resultpath ],
93+
[ 'pg_combinebackup', $backup2path, $backup2path, '-o', $resultpath, $mode ],
8994
qr/is an incremental backup, but the first backup should be a full backup/,
9095
"can't combine full backups");
9196

9297
# Can't combine full backup with an incremental backup from a different system.
9398
$node1->command_fails_like(
9499
[
95100
'pg_combinebackup', $backup1path, $backupother2path, '-o',
96-
$resultpath
101+
$resultpath, $mode
97102
],
98103
qr/expected system identifier.*but found/,
99104
"can't combine backups from different nodes");
@@ -106,7 +111,7 @@
106111
$node1->command_fails_like(
107112
[
108113
'pg_combinebackup', $backup1path, $backup2path, $backup3path,
109-
'-o', $resultpath
114+
'-o', $resultpath, $mode
110115
],
111116
qr/ manifest system identifier is .*, but control file has /,
112117
"can't combine backups with different manifest system identifier ");
@@ -116,15 +121,15 @@
116121

117122
# Can't omit a required backup.
118123
$node1->command_fails_like(
119-
[ 'pg_combinebackup', $backup1path, $backup3path, '-o', $resultpath ],
124+
[ 'pg_combinebackup', $backup1path, $backup3path, '-o', $resultpath, $mode ],
120125
qr/starts at LSN.*but expected/,
121126
"can't omit a required backup");
122127

123128
# Can't combine backups in the wrong order.
124129
$node1->command_fails_like(
125130
[
126131
'pg_combinebackup', $backup1path, $backup3path, $backup2path,
127-
'-o', $resultpath
132+
'-o', $resultpath, $mode
128133
],
129134
qr/starts at LSN.*but expected/,
130135
"can't combine backups in the wrong order");
@@ -133,7 +138,7 @@
133138
$node1->command_ok(
134139
[
135140
'pg_combinebackup', $backup1path, $backup2path, $backup3path,
136-
'-o', $resultpath
141+
'-o', $resultpath, $mode
137142
],
138143
"can combine 3 matching backups");
139144
rmtree($resultpath);
@@ -143,19 +148,19 @@
143148
$node1->command_ok(
144149
[
145150
'pg_combinebackup', $backup1path, $backup2path, '-o',
146-
$synthetic12path
151+
$synthetic12path, $mode
147152
],
148153
"can combine 2 matching backups");
149154

150155
# Can combine result of previous step with second incremental.
151156
$node1->command_ok(
152-
[ 'pg_combinebackup', $synthetic12path, $backup3path, '-o', $resultpath ],
157+
[ 'pg_combinebackup', $synthetic12path, $backup3path, '-o', $resultpath, $mode ],
153158
"can combine synthetic backup with later incremental");
154159
rmtree($resultpath);
155160

156161
# Can't combine result of 1+2 with 2.
157162
$node1->command_fails_like(
158-
[ 'pg_combinebackup', $synthetic12path, $backup2path, '-o', $resultpath ],
163+
[ 'pg_combinebackup', $synthetic12path, $backup2path, '-o', $resultpath, $mode ],
159164
qr/starts at LSN.*but expected/,
160165
"can't combine synthetic backup with included incremental");
161166

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use PostgreSQL::Test::Utils;
88
use Test::More;
99

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+
1015
# Set up a new database instance.
1116
my $primary = PostgreSQL::Test::Cluster->new('primary');
1217
$primary->init(has_archiving => 1, allows_streaming => 1);
@@ -45,7 +50,8 @@
4550
# Recover the incremental backup.
4651
my $restore = PostgreSQL::Test::Cluster->new('restore');
4752
$restore->init_from_backup($primary, 'backup2',
48-
combine_with_prior => ['backup1']);
53+
combine_with_prior => ['backup1'],
54+
combine_mode => $mode);
4955
$restore->start();
5056

5157
# Query the DB.

src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ sub init_from_backup
856856
push @combineargs, "-T$olddir=$newdir";
857857
}
858858
}
859+
# use the combine mode (clone/copy-file-range) if specified
860+
if (defined $params{combine_mode})
861+
{
862+
push @combineargs, $params{combine_mode};
863+
}
859864
push @combineargs, @prior_backup_path, $backup_path, '-o', $data_path;
860865
PostgreSQL::Test::Utils::system_or_bail(@combineargs);
861866
}

0 commit comments

Comments
 (0)