|
6 | 6 | use File::Path qw(rmtree);
|
7 | 7 | use PostgresNode;
|
8 | 8 | use TestLib;
|
9 |
| -use Test::More tests => 109; |
| 9 | +use Test::More tests => 110; |
10 | 10 |
|
11 | 11 | program_help_ok('pg_basebackup');
|
12 | 12 | program_version_ok('pg_basebackup');
|
|
229 | 229 |
|
230 | 230 | $node->start;
|
231 | 231 |
|
| 232 | +# Test backup of a tablespace using tar format. |
232 | 233 | # Create a temporary directory in the system location and symlink it
|
233 | 234 | # to our physical temp location. That way we can use shorter names
|
234 | 235 | # for the tablespace directories, which hopefully won't run afoul of
|
|
242 | 243 | $node->safe_psql('postgres',
|
243 | 244 | "CREATE TABLESPACE tblspc1 LOCATION '$realTsDir';");
|
244 | 245 | $node->safe_psql('postgres',
|
245 |
| - "CREATE TABLE test1 (a int) TABLESPACE tblspc1;"); |
246 |
| -$node->command_ok( |
247 |
| - [ 'pg_basebackup', '-D', "$real_tempdir/tarbackup2", '-Ft' ], |
248 |
| - 'tar format with tablespaces'); |
249 |
| -ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created'); |
250 |
| -my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar"; |
| 246 | + "CREATE TABLE test1 (a int) TABLESPACE tblspc1;" |
| 247 | + . "INSERT INTO test1 VALUES (1234);"); |
| 248 | +$node->backup('tarbackup2', backup_options => ['-Ft']); |
| 249 | +# empty test1, just so that it's different from the to-be-restored data |
| 250 | +$node->safe_psql('postgres', "TRUNCATE TABLE test1;"); |
| 251 | + |
| 252 | +# basic checks on the output |
| 253 | +my $backupdir = $node->backup_dir . '/tarbackup2'; |
| 254 | +ok(-f "$backupdir/base.tar", 'backup tar was created'); |
| 255 | +ok(-f "$backupdir/pg_wal.tar", 'WAL tar was created'); |
| 256 | +my @tblspc_tars = glob "$backupdir/[0-9]*.tar"; |
251 | 257 | is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
|
252 |
| -rmtree("$tempdir/tarbackup2"); |
| 258 | + |
| 259 | +# Try to verify the tar-format backup by restoring it. |
| 260 | +# For this, we use the tar program identified by configure. |
| 261 | +SKIP: |
| 262 | +{ |
| 263 | + my $tar = $ENV{TAR}; |
| 264 | + skip "no tar program available", 1 |
| 265 | + if (!defined $tar || $tar eq ''); |
| 266 | + |
| 267 | + my $node2 = get_new_node('replica'); |
| 268 | + |
| 269 | + # Recover main data directory |
| 270 | + $node2->init_from_backup($node, 'tarbackup2', tar_program => $tar); |
| 271 | + |
| 272 | + # Recover tablespace into a new directory (not where it was!) |
| 273 | + mkdir "$tempdir/tblspc1replica"; |
| 274 | + my $realRepTsDir = TestLib::perl2host("$shorter_tempdir/tblspc1replica"); |
| 275 | + TestLib::system_or_bail($tar, 'xf', $tblspc_tars[0], '-C', $realRepTsDir); |
| 276 | + |
| 277 | + # Update tablespace map to point to new directory. |
| 278 | + # XXX Ideally pg_basebackup would handle this. |
| 279 | + $tblspc_tars[0] =~ m|/([0-9]*)\.tar$|; |
| 280 | + my $tblspcoid = $1; |
| 281 | + my $escapedRepTsDir = $realRepTsDir; |
| 282 | + $escapedRepTsDir =~ s/\\/\\\\/g; |
| 283 | + open my $mapfile, '>', $node2->data_dir . '/tablespace_map'; |
| 284 | + print $mapfile "$tblspcoid $escapedRepTsDir\n"; |
| 285 | + close $mapfile; |
| 286 | + |
| 287 | + $node2->start; |
| 288 | + my $result = $node2->safe_psql('postgres', 'SELECT * FROM test1'); |
| 289 | + is($result, '1234', "tablespace data restored from tar-format backup"); |
| 290 | + $node2->stop; |
| 291 | +} |
253 | 292 |
|
254 | 293 | # Create an unlogged table to test that forks other than init are not copied.
|
255 | 294 | $node->safe_psql('postgres',
|
|
0 commit comments