|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use Cwd; |
| 4 | +use TestLib; |
| 5 | +use Test::More tests => 28; |
| 6 | + |
| 7 | +program_help_ok('pg_basebackup'); |
| 8 | +program_version_ok('pg_basebackup'); |
| 9 | +program_options_handling_ok('pg_basebackup'); |
| 10 | + |
| 11 | +my $tempdir = tempdir; |
| 12 | +start_test_server $tempdir; |
| 13 | + |
| 14 | +command_fails(['pg_basebackup'], 'pg_basebackup needs target directory specified'); |
| 15 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup fails because of hba'); |
| 16 | + |
| 17 | +open HBA, ">>$tempdir/pgdata/pg_hba.conf"; |
| 18 | +print HBA "local replication all trust\n"; |
| 19 | +print HBA "host replication all 127.0.0.1/32 trust\n"; |
| 20 | +print HBA "host replication all ::1/128 trust\n"; |
| 21 | +close HBA; |
| 22 | +system_or_bail 'pg_ctl', '-s', '-D', "$tempdir/pgdata", 'reload'; |
| 23 | + |
| 24 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup fails because of WAL configuration'); |
| 25 | + |
| 26 | +open CONF, ">>$tempdir/pgdata/postgresql.conf"; |
| 27 | +print CONF "max_wal_senders = 10\n"; |
| 28 | +print CONF "wal_level = archive\n"; |
| 29 | +close CONF; |
| 30 | +restart_test_server; |
| 31 | + |
| 32 | +command_ok(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup runs'); |
| 33 | +ok(-f "$tempdir/backup/PG_VERSION", 'backup was created'); |
| 34 | + |
| 35 | +command_ok(['pg_basebackup', '-D', "$tempdir/backup2", '--xlogdir', "$tempdir/xlog2"], 'separate xlog directory'); |
| 36 | +ok(-f "$tempdir/backup2/PG_VERSION", 'backup was created'); |
| 37 | +ok(-d "$tempdir/xlog2/", 'xlog directory was created'); |
| 38 | + |
| 39 | +command_ok(['pg_basebackup', '-D', "$tempdir/tarbackup", '-Ft'], 'tar format'); |
| 40 | +ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created'); |
| 41 | + |
| 42 | +mkdir "$tempdir/tblspc1"; |
| 43 | +psql 'postgres', "CREATE TABLESPACE tblspc1 LOCATION '$tempdir/tblspc1';"; |
| 44 | +psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;"; |
| 45 | +command_ok(['pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft'], 'tar format with tablespaces'); |
| 46 | +ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created'); |
| 47 | +my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar"; |
| 48 | +is(scalar(@tblspc_tars), 1, 'one tablespace tar was created'); |
| 49 | + |
| 50 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup1", '-Fp'], |
| 51 | + 'plain format with tablespaces fails without tablespace mapping'); |
| 52 | + |
| 53 | +command_ok(['pg_basebackup', '-D', "$tempdir/backup1", '-Fp', |
| 54 | + "-T$tempdir/tblspc1=$tempdir/tbackup/tblspc1"], |
| 55 | + 'plain format with tablespaces succeeds with tablespace mapping'); |
| 56 | +ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated'); |
| 57 | +opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die; |
| 58 | +ok((grep { -l "$tempdir/backup1/pg_tblspc/$_" and readlink "$tempdir/backup1/pg_tblspc/$_" eq "$tempdir/tbackup/tblspc1" } readdir($dh)), |
| 59 | + "tablespace symlink was updated"); |
| 60 | +closedir $dh; |
| 61 | + |
| 62 | +mkdir "$tempdir/tbl=spc2"; |
| 63 | +psql 'postgres', "DROP TABLE test1;"; |
| 64 | +psql 'postgres', "DROP TABLESPACE tblspc1;"; |
| 65 | +psql 'postgres', "CREATE TABLESPACE tblspc2 LOCATION '$tempdir/tbl=spc2';"; |
| 66 | +command_ok(['pg_basebackup', '-D', "$tempdir/backup3", '-Fp', |
| 67 | + "-T$tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2"], |
| 68 | + 'mapping tablespace with = sign in path'); |
| 69 | +ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated'); |
| 70 | + |
| 71 | +psql 'postgres', "DROP TABLESPACE tblspc2;"; |
| 72 | + |
| 73 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', |
| 74 | + "-T=/foo"], |
| 75 | + '-T with empty old directory fails'); |
| 76 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', |
| 77 | + "-T/foo="], |
| 78 | + '-T with empty new directory fails'); |
| 79 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', |
| 80 | + "-T/foo=/bar=/baz"], |
| 81 | + '-T with multiple = fails'); |
| 82 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', |
| 83 | + "-Tfoo=/bar"], |
| 84 | + '-T with old directory not absolute fails'); |
| 85 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', |
| 86 | + "-T/foo=bar"], |
| 87 | + '-T with new directory not absolute fails'); |
| 88 | +command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', |
| 89 | + "-Tfoo"], |
| 90 | + '-T with invalid format fails'); |
0 commit comments