|
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | 3 | use Cwd; |
| 4 | +use Config; |
4 | 5 | use TestLib; |
5 | 6 | use Test::More tests => 51; |
6 | 7 |
|
|
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( |
|
62 | 59 | 'tar format'); |
63 | 60 | ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created'); |
64 | 61 |
|
65 | | -my $superlongname = "superlongname_" . ("x" x 100); |
66 | | - |
67 | | -system_or_bail 'touch', "$tempdir/pgdata/$superlongname"; |
68 | | -command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l1", '-Ft' ], |
69 | | - 'pg_basebackup tar with long name fails'); |
70 | | -unlink "$tempdir/pgdata/$superlongname"; |
71 | | - |
72 | | -# Create a temporary directory in the system location and symlink it |
73 | | -# to our physical temp location. That way we can use shorter names |
74 | | -# for the tablespace directories, which hopefully won't run afoul of |
75 | | -# the 99 character length limit. |
76 | | -my $shorter_tempdir = tempdir_short . "/tempdir"; |
77 | | -symlink "$tempdir", $shorter_tempdir; |
78 | | - |
79 | | -mkdir "$tempdir/tblspc1"; |
80 | | -psql 'postgres', |
81 | | - "CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';"; |
82 | | -psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;"; |
83 | | -command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft' ], |
84 | | - 'tar format with tablespaces'); |
85 | | -ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created'); |
86 | | -my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar"; |
87 | | -is(scalar(@tblspc_tars), 1, 'one tablespace tar was created'); |
88 | | - |
89 | | -command_fails( |
90 | | - [ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp' ], |
91 | | - 'plain format with tablespaces fails without tablespace mapping'); |
92 | | - |
93 | | -command_ok( |
94 | | - [ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp', |
95 | | - "-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ], |
96 | | - 'plain format with tablespaces succeeds with tablespace mapping'); |
97 | | -ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated'); |
98 | | -opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die; |
99 | | -ok( ( grep { |
100 | | - -l "$tempdir/backup1/pg_tblspc/$_" |
101 | | - and readlink "$tempdir/backup1/pg_tblspc/$_" eq |
102 | | - "$tempdir/tbackup/tblspc1" |
103 | | - } readdir($dh)), |
104 | | - "tablespace symlink was updated"); |
105 | | -closedir $dh; |
106 | | - |
107 | | -mkdir "$tempdir/tbl=spc2"; |
108 | | -psql 'postgres', "DROP TABLE test1;"; |
109 | | -psql 'postgres', "DROP TABLESPACE tblspc1;"; |
110 | | -psql 'postgres', |
111 | | - "CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';"; |
112 | | -command_ok( |
113 | | - [ 'pg_basebackup', '-D', "$tempdir/backup3", '-Fp', |
114 | | - "-T$shorter_tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2" ], |
115 | | - 'mapping tablespace with = sign in path'); |
116 | | -ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated'); |
117 | | - |
118 | | -psql 'postgres', "DROP TABLESPACE tblspc2;"; |
119 | | - |
120 | 62 | command_fails( |
121 | 63 | [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ], |
122 | 64 | '-T with empty old directory fails'); |
|
137 | 79 | [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ], |
138 | 80 | '-T with invalid format fails'); |
139 | 81 |
|
140 | | -mkdir "$tempdir/$superlongname"; |
141 | | -psql 'postgres', |
142 | | - "CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';"; |
143 | | -command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ], |
144 | | - 'pg_basebackup tar with long symlink target'); |
145 | | -psql 'postgres', "DROP TABLESPACE tblspc3;"; |
| 82 | +# Tar format doesn't support filenames longer than 100 bytes. |
| 83 | +my $superlongname = "superlongname_" . ("x" x 100); |
| 84 | +my $superlongpath = "$tempdir/pgdata/$superlongname"; |
| 85 | + |
| 86 | +open FILE, ">$superlongpath" or die "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", 10 if ($Config{osname} eq "MSWin32"); |
| 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") or die; |
| 124 | + ok( ( grep { |
| 125 | + -l "$tempdir/backup1/pg_tblspc/$_" |
| 126 | + and readlink "$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 | +} |
146 | 151 |
|
147 | 152 | command_ok([ 'pg_basebackup', '-D', "$tempdir/backupR", '-R' ], |
148 | 153 | 'pg_basebackup -R runs'); |
|
169 | 174 | command_ok([ 'pg_basebackup', '-D', "$tempdir/backupxs_sl", '-X', 'stream', '-S', 'slot1' ], |
170 | 175 | 'pg_basebackup -X stream with replication slot runs'); |
171 | 176 | $lsn = psql 'postgres', q{SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot1'}; |
172 | | -like($lsn, qr!^0/[0-9A-Z]{8}$!, 'restart LSN of slot has advanced'); |
| 177 | +like($lsn, qr!^0/[0-9A-Z]{7,8}$!, 'restart LSN of slot has advanced'); |
173 | 178 |
|
174 | 179 | command_ok([ 'pg_basebackup', '-D', "$tempdir/backupxs_sl_R", '-X', 'stream', '-S', 'slot1', '-R' ], |
175 | 180 | 'pg_basebackup with replication slot and -R runs'); |
|
0 commit comments