|
1 | 1 | use strict;
|
2 | 2 | use warnings;
|
3 | 3 | use Cwd;
|
| 4 | +use Config; |
4 | 5 | use TestLib;
|
5 |
| -use Test::Moretests=>35; |
| 6 | +use Test::Moretests=>46; |
6 | 7 |
|
7 | 8 | program_help_ok('pg_basebackup');
|
8 | 9 | program_version_ok('pg_basebackup');
|
|
25 | 26 | close BADCHARS;
|
26 | 27 | }
|
27 | 28 |
|
28 |
| -open HBA,">>$tempdir/pgdata/pg_hba.conf"; |
29 |
| -print HBA"local replication all trust\n"; |
30 |
| -print HBA"host replication all 127.0.0.1/32 trust\n"; |
31 |
| -print HBA"host replication all ::1/128 trust\n"; |
32 |
| -close HBA; |
| 29 | +configure_hba_for_replication"$tempdir/pgdata"; |
33 | 30 | system_or_bail'pg_ctl','-D',"$tempdir/pgdata",'reload';
|
34 | 31 |
|
35 | 32 | command_fails(
|
36 | 33 | ['pg_basebackup','-D',"$tempdir/backup" ],
|
37 | 34 | 'pg_basebackup fails because of WAL configuration');
|
38 | 35 |
|
39 | 36 | open CONF,">>$tempdir/pgdata/postgresql.conf";
|
| 37 | +print CONF"max_replication_slots = 10\n"; |
40 | 38 | print CONF"max_wal_senders = 10\n";
|
41 | 39 | print CONF"wal_level = archive\n";
|
42 | 40 | close CONF;
|
|
46 | 44 | 'pg_basebackup runs');
|
47 | 45 | ok(-f"$tempdir/backup/PG_VERSION",'backup was created');
|
48 | 46 |
|
| 47 | +is_deeply([sort(slurp_dir("$tempdir/backup/pg_xlog/"))], |
| 48 | + [sortqw(. .. archive_status)], |
| 49 | +'no WAL files copied'); |
| 50 | + |
49 | 51 | command_ok(
|
50 | 52 | ['pg_basebackup','-D',"$tempdir/backup2",'--xlogdir',
|
51 | 53 | "$tempdir/xlog2" ],
|
|
57 | 59 | 'tar format');
|
58 | 60 | ok(-f"$tempdir/tarbackup/base.tar",'backup tar was created');
|
59 | 61 |
|
60 |
| -my$superlongname ="superlongname_" . ("x"x100); |
61 |
| - |
62 |
| -system_or_bail'touch',"$tempdir/pgdata/$superlongname"; |
63 |
| -command_fails(['pg_basebackup','-D',"$tempdir/tarbackup_l1",'-Ft' ], |
64 |
| -'pg_basebackup tar with long name fails'); |
65 |
| -unlink"$tempdir/pgdata/$superlongname"; |
66 |
| - |
67 |
| -# Create a temporary directory in the system location and symlink it |
68 |
| -# to our physical temp location. That way we can use shorter names |
69 |
| -# for the tablespace directories, which hopefully won't run afoul of |
70 |
| -# the 99 character length limit. |
71 |
| -my$shorter_tempdir = tempdir_short ."/tempdir"; |
72 |
| -symlink"$tempdir",$shorter_tempdir; |
73 |
| - |
74 |
| -mkdir"$tempdir/tblspc1"; |
75 |
| -psql'postgres', |
76 |
| -"CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';"; |
77 |
| -psql'postgres',"CREATE TABLE test1 (a int) TABLESPACE tblspc1;"; |
78 |
| -command_ok(['pg_basebackup','-D',"$tempdir/tarbackup2",'-Ft' ], |
79 |
| -'tar format with tablespaces'); |
80 |
| -ok(-f"$tempdir/tarbackup2/base.tar",'backup tar was created'); |
81 |
| -my@tblspc_tars =glob"$tempdir/tarbackup2/[0-9]*.tar"; |
82 |
| -is(scalar(@tblspc_tars), 1,'one tablespace tar was created'); |
83 |
| - |
84 |
| -command_fails( |
85 |
| -['pg_basebackup','-D',"$tempdir/backup1",'-Fp' ], |
86 |
| -'plain format with tablespaces fails without tablespace mapping'); |
87 |
| - |
88 |
| -command_ok( |
89 |
| -['pg_basebackup','-D',"$tempdir/backup1",'-Fp', |
90 |
| -"-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ], |
91 |
| -'plain format with tablespaces succeeds with tablespace mapping'); |
92 |
| -ok(-d"$tempdir/tbackup/tblspc1",'tablespace was relocated'); |
93 |
| -opendir(my$dh,"$tempdir/pgdata/pg_tblspc")ordie; |
94 |
| -ok( (grep { |
95 |
| --l"$tempdir/backup1/pg_tblspc/$_" |
96 |
| -andreadlink"$tempdir/backup1/pg_tblspc/$_"eq |
97 |
| -"$tempdir/tbackup/tblspc1" |
98 |
| - }readdir($dh)), |
99 |
| -"tablespace symlink was updated"); |
100 |
| -closedir$dh; |
101 |
| - |
102 |
| -mkdir"$tempdir/tbl=spc2"; |
103 |
| -psql'postgres',"DROP TABLE test1;"; |
104 |
| -psql'postgres',"DROP TABLESPACE tblspc1;"; |
105 |
| -psql'postgres', |
106 |
| -"CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';"; |
107 |
| -command_ok( |
108 |
| -['pg_basebackup','-D',"$tempdir/backup3",'-Fp', |
109 |
| -"-T$shorter_tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2" ], |
110 |
| -'mapping tablespace with = sign in path'); |
111 |
| -ok(-d"$tempdir/tbackup/tbl=spc2",'tablespace with = sign was relocated'); |
112 |
| - |
113 |
| -psql'postgres',"DROP TABLESPACE tblspc2;"; |
114 |
| - |
115 | 62 | command_fails(
|
116 | 63 | ['pg_basebackup','-D',"$tempdir/backup_foo",'-Fp',"-T=/foo" ],
|
117 | 64 | '-T with empty old directory fails');
|
|
132 | 79 | ['pg_basebackup','-D',"$tempdir/backup_foo",'-Fp',"-Tfoo" ],
|
133 | 80 | '-T with invalid format fails');
|
134 | 81 |
|
135 |
| -mkdir"$tempdir/$superlongname"; |
136 |
| -psql'postgres', |
137 |
| -"CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';"; |
138 |
| -command_ok(['pg_basebackup','-D',"$tempdir/tarbackup_l3",'-Ft' ], |
139 |
| -'pg_basebackup tar with long symlink target'); |
140 |
| -psql'postgres',"DROP TABLESPACE tblspc3;"; |
| 82 | +# Tar format doesn't support filenames longer than 100 bytes. |
| 83 | +my$superlongname ="superlongname_" . ("x"x100); |
| 84 | +my$superlongpath ="$tempdir/pgdata/$superlongname"; |
| 85 | + |
| 86 | +open FILE,">$superlongpath"ordie"unable to create file$superlongpath"; |
| 87 | +close FILE; |
| 88 | +command_fails(['pg_basebackup','-D',"$tempdir/tarbackup_l1",'-Ft' ], |
| 89 | +'pg_basebackup tar with long name fails'); |
| 90 | +unlink"$tempdir/pgdata/$superlongname"; |
| 91 | + |
| 92 | +# The following tests test symlinks. Windows doesn't have symlinks, so |
| 93 | +# skip on Windows. |
| 94 | +SKIP: { |
| 95 | + skip"symlinks not supported on Windows", 10if ($windows_os); |
| 96 | + |
| 97 | +# Create a temporary directory in the system location and symlink it |
| 98 | +# to our physical temp location. That way we can use shorter names |
| 99 | +# for the tablespace directories, which hopefully won't run afoul of |
| 100 | +# the 99 character length limit. |
| 101 | +my$shorter_tempdir = tempdir_short ."/tempdir"; |
| 102 | +symlink"$tempdir",$shorter_tempdir; |
| 103 | + |
| 104 | +mkdir"$tempdir/tblspc1"; |
| 105 | +psql'postgres', |
| 106 | +"CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';"; |
| 107 | +psql'postgres',"CREATE TABLE test1 (a int) TABLESPACE tblspc1;"; |
| 108 | +command_ok(['pg_basebackup','-D',"$tempdir/tarbackup2",'-Ft' ], |
| 109 | +'tar format with tablespaces'); |
| 110 | +ok(-f"$tempdir/tarbackup2/base.tar",'backup tar was created'); |
| 111 | +my@tblspc_tars =glob"$tempdir/tarbackup2/[0-9]*.tar"; |
| 112 | +is(scalar(@tblspc_tars), 1,'one tablespace tar was created'); |
| 113 | + |
| 114 | +command_fails( |
| 115 | +['pg_basebackup','-D',"$tempdir/backup1",'-Fp' ], |
| 116 | +'plain format with tablespaces fails without tablespace mapping'); |
| 117 | + |
| 118 | +command_ok( |
| 119 | +['pg_basebackup','-D',"$tempdir/backup1",'-Fp', |
| 120 | +"-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ], |
| 121 | +'plain format with tablespaces succeeds with tablespace mapping'); |
| 122 | +ok(-d"$tempdir/tbackup/tblspc1",'tablespace was relocated'); |
| 123 | +opendir(my$dh,"$tempdir/pgdata/pg_tblspc")ordie; |
| 124 | +ok( (grep { |
| 125 | +-l"$tempdir/backup1/pg_tblspc/$_" |
| 126 | +andreadlink"$tempdir/backup1/pg_tblspc/$_"eq |
| 127 | +"$tempdir/tbackup/tblspc1" |
| 128 | +}readdir($dh)), |
| 129 | +"tablespace symlink was updated"); |
| 130 | +closedir$dh; |
| 131 | + |
| 132 | +mkdir"$tempdir/tbl=spc2"; |
| 133 | +psql'postgres',"DROP TABLE test1;"; |
| 134 | +psql'postgres',"DROP TABLESPACE tblspc1;"; |
| 135 | +psql'postgres', |
| 136 | +"CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';"; |
| 137 | +command_ok( |
| 138 | +['pg_basebackup','-D',"$tempdir/backup3",'-Fp', |
| 139 | +"-T$shorter_tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2" ], |
| 140 | +'mapping tablespace with = sign in path'); |
| 141 | +ok(-d"$tempdir/tbackup/tbl=spc2",'tablespace with = sign was relocated'); |
| 142 | +psql'postgres',"DROP TABLESPACE tblspc2;"; |
| 143 | + |
| 144 | +mkdir"$tempdir/$superlongname"; |
| 145 | +psql'postgres', |
| 146 | +"CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';"; |
| 147 | +command_ok(['pg_basebackup','-D',"$tempdir/tarbackup_l3",'-Ft' ], |
| 148 | +'pg_basebackup tar with long symlink target'); |
| 149 | +psql'postgres',"DROP TABLESPACE tblspc3;"; |
| 150 | +} |
| 151 | + |
| 152 | +command_ok(['pg_basebackup','-D',"$tempdir/backupR",'-R' ], |
| 153 | +'pg_basebackup -R runs'); |
| 154 | +ok(-f"$tempdir/backupR/recovery.conf",'recovery.conf was created'); |
| 155 | +my$recovery_conf = slurp_file"$tempdir/backupR/recovery.conf"; |
| 156 | +# using a character class for the final "'" here works around an apparent |
| 157 | +# bug in several version of the Msys DTK perl |
| 158 | +like($recovery_conf,qr/^standby_mode = 'on[']$/m,'recovery.conf sets standby_mode'); |
| 159 | +like($recovery_conf,qr/^primary_conninfo = '.*port=$ENV{PGPORT}.*'$/m,'recovery.conf sets primary_conninfo'); |
| 160 | + |
| 161 | +command_ok(['pg_basebackup','-D',"$tempdir/backupxf",'-X','fetch' ], |
| 162 | +'pg_basebackup -X fetch runs'); |
| 163 | +ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_xlog")),'WAL files copied'); |
| 164 | +command_ok(['pg_basebackup','-D',"$tempdir/backupxs",'-X','stream' ], |
| 165 | +'pg_basebackup -X stream runs'); |
| 166 | +ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_xlog")),'WAL files copied'); |
| 167 | + |
| 168 | +command_fails(['pg_basebackup','-D',"$tempdir/fail",'-S','slot1' ], |
| 169 | +'pg_basebackup with replication slot fails without -X stream'); |
| 170 | +command_fails(['pg_basebackup','-D',"$tempdir/backupxs_sl_fail",'-X','stream','-S','slot1' ], |
| 171 | +'pg_basebackup fails with nonexistent replication slot'); |