|
3 | 3 | use Cwd;
|
4 | 4 | use Config;
|
5 | 5 | use File::Basename qw(basename dirname);
|
| 6 | +use File::Path qw(rmtree); |
6 | 7 | use PostgresNode;
|
7 | 8 | use TestLib;
|
8 | 9 | use Test::More tests => 104;
|
|
135 | 136 | # Make sure existing backup_label was ignored.
|
136 | 137 | isnt(slurp_file("$tempdir/backup/backup_label"),
|
137 | 138 | 'DONOTCOPY', 'existing backup_label not copied');
|
| 139 | +rmtree("$tempdir/backup"); |
138 | 140 |
|
139 | 141 | $node->command_ok(
|
140 | 142 | [ 'pg_basebackup', '-D', "$tempdir/backup2", '--waldir',
|
141 | 143 | "$tempdir/xlog2" ],
|
142 | 144 | 'separate xlog directory');
|
143 | 145 | ok(-f "$tempdir/backup2/PG_VERSION", 'backup was created');
|
144 | 146 | ok(-d "$tempdir/xlog2/", 'xlog directory was created');
|
| 147 | +rmtree("$tempdir/backup2"); |
| 148 | +rmtree("$tempdir/xlog2"); |
145 | 149 |
|
146 | 150 | $node->command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup", '-Ft' ],
|
147 | 151 | 'tar format');
|
148 | 152 | ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created');
|
| 153 | +rmtree("$tempdir/tarbackup"); |
149 | 154 |
|
150 | 155 | $node->command_fails(
|
151 | 156 | [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ],
|
|
212 | 217 | ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
|
213 | 218 | my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
|
214 | 219 | is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
|
| 220 | + rmtree("$tempdir/tarbackup2"); |
215 | 221 |
|
216 | 222 | # Create an unlogged table to test that forks other than init are not copied.
|
217 | 223 | $node->safe_psql('postgres',
|
|
281 | 287 |
|
282 | 288 | ok( -d "$tempdir/backup1/pg_replslot",
|
283 | 289 | 'pg_replslot symlink copied as directory');
|
| 290 | + rmtree("$tempdir/backup1"); |
284 | 291 |
|
285 | 292 | mkdir "$tempdir/tbl=spc2";
|
286 | 293 | $node->safe_psql('postgres', "DROP TABLE test1;");
|
|
295 | 302 | ok(-d "$tempdir/tbackup/tbl=spc2",
|
296 | 303 | 'tablespace with = sign was relocated');
|
297 | 304 | $node->safe_psql('postgres', "DROP TABLESPACE tblspc2;");
|
| 305 | + rmtree("$tempdir/backup3"); |
298 | 306 |
|
299 | 307 | mkdir "$tempdir/$superlongname";
|
300 | 308 | $node->safe_psql('postgres',
|
|
303 | 311 | [ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ],
|
304 | 312 | 'pg_basebackup tar with long symlink target');
|
305 | 313 | $node->safe_psql('postgres', "DROP TABLESPACE tblspc3;");
|
| 314 | + rmtree("$tempdir/tarbackup_l3"); |
306 | 315 | }
|
307 | 316 |
|
308 | 317 | $node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backupR", '-R' ],
|
309 | 318 | 'pg_basebackup -R runs');
|
310 | 319 | ok(-f "$tempdir/backupR/recovery.conf", 'recovery.conf was created');
|
311 | 320 | my $recovery_conf = slurp_file "$tempdir/backupR/recovery.conf";
|
| 321 | +rmtree("$tempdir/backupR"); |
312 | 322 |
|
313 | 323 | my $port = $node->port;
|
314 | 324 | like(
|
|
325 | 335 | 'pg_basebackup runs in default xlog mode');
|
326 | 336 | ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxd/pg_wal")),
|
327 | 337 | 'WAL files copied');
|
| 338 | +rmtree("$tempdir/backupxd"); |
328 | 339 |
|
329 | 340 | $node->command_ok(
|
330 | 341 | [ 'pg_basebackup', '-D', "$tempdir/backupxf", '-X', 'fetch' ],
|
331 | 342 | 'pg_basebackup -X fetch runs');
|
332 | 343 | ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_wal")),
|
333 | 344 | 'WAL files copied');
|
| 345 | +rmtree("$tempdir/backupxf"); |
334 | 346 | $node->command_ok(
|
335 | 347 | [ 'pg_basebackup', '-D', "$tempdir/backupxs", '-X', 'stream' ],
|
336 | 348 | 'pg_basebackup -X stream runs');
|
337 | 349 | ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxs/pg_wal")),
|
338 | 350 | 'WAL files copied');
|
| 351 | +rmtree("$tempdir/backupxs"); |
339 | 352 | $node->command_ok(
|
340 | 353 | [ 'pg_basebackup', '-D', "$tempdir/backupxst", '-X', 'stream', '-Ft' ],
|
341 | 354 | 'pg_basebackup -X stream runs in tar mode');
|
342 | 355 | ok(-f "$tempdir/backupxst/pg_wal.tar", "tar file was created");
|
| 356 | +rmtree("$tempdir/backupxst"); |
343 | 357 | $node->command_ok(
|
344 | 358 | [ 'pg_basebackup', '-D',
|
345 | 359 | "$tempdir/backupnoslot", '-X',
|
346 | 360 | 'stream', '--no-slot' ],
|
347 | 361 | 'pg_basebackup -X stream runs with --no-slot');
|
| 362 | +rmtree("$tempdir/backupnoslot"); |
348 | 363 |
|
349 | 364 | $node->command_fails(
|
350 | 365 | [ 'pg_basebackup', '-D',
|
|
364 | 379 | $node->command_ok(
|
365 | 380 | [ 'pg_basebackup', '-D', "$tempdir/backupxs_slot", '-C', '-S', 'slot0' ],
|
366 | 381 | 'pg_basebackup -C runs');
|
| 382 | +rmtree("$tempdir/backupxs_slot"); |
367 | 383 |
|
368 | 384 | is($node->safe_psql('postgres', q{SELECT slot_name FROM pg_replication_slots WHERE slot_name = 'slot0'}),
|
369 | 385 | 'slot0',
|
|
393 | 409 | q{SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot1'}
|
394 | 410 | );
|
395 | 411 | like($lsn, qr!^0/[0-9A-Z]{7,8}$!, 'restart LSN of slot has advanced');
|
| 412 | +rmtree("$tempdir/backupxs_sl"); |
396 | 413 |
|
397 | 414 | $node->command_ok(
|
398 | 415 | [ 'pg_basebackup', '-D', "$tempdir/backupxs_sl_R", '-X',
|
|
405 | 422 |
|
406 | 423 | my $checksum = $node->safe_psql('postgres', 'SHOW data_checksums;');
|
407 | 424 | is($checksum, 'on', 'checksums are enabled');
|
| 425 | +rmtree("$tempdir/backupxs_sl_R"); |
408 | 426 |
|
409 | 427 | # create tables to corrupt and get their relfilenodes
|
410 | 428 | my $file_corrupt1 = $node->safe_psql('postgres',
|
|
432 | 450 | [qr/^WARNING.*checksum verification failed/s],
|
433 | 451 | 'pg_basebackup reports checksum mismatch'
|
434 | 452 | );
|
| 453 | +rmtree("$tempdir/backup_corrupt"); |
435 | 454 |
|
436 | 455 | # induce further corruption in 5 more blocks
|
437 | 456 | system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
|
|
450 | 469 | [qr/^WARNING.*further.*failures.*will.not.be.reported/s],
|
451 | 470 | 'pg_basebackup does not report more than 5 checksum mismatches'
|
452 | 471 | );
|
| 472 | +rmtree("$tempdir/backup_corrupt2"); |
453 | 473 |
|
454 | 474 | # induce corruption in a second file
|
455 | 475 | system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
|
|
465 | 485 | [qr/^WARNING.*7 total checksum verification failures/s],
|
466 | 486 | 'pg_basebackup correctly report the total number of checksum mismatches'
|
467 | 487 | );
|
| 488 | +rmtree("$tempdir/backup_corrupt3"); |
468 | 489 |
|
469 | 490 | # do not verify checksums, should return ok
|
470 | 491 | $node->command_ok(
|
471 | 492 | [ 'pg_basebackup', '-D', "$tempdir/backup_corrupt4", '-k' ],
|
472 | 493 | 'pg_basebackup with -k does not report checksum mismatch');
|
| 494 | +rmtree("$tempdir/backup_corrupt4"); |
473 | 495 |
|
474 | 496 | $node->safe_psql('postgres', "DROP TABLE corrupt1;");
|
475 | 497 | $node->safe_psql('postgres', "DROP TABLE corrupt2;");
|
0 commit comments