20
20
21
21
# Make sure pg_hba.conf is set up to allow connections from backupuser.
22
22
# This is only needed on Windows machines that don't use UNIX sockets.
23
- $node -> init(' allows_streaming' => 1,
24
- ' auth_extra' => [ ' --create-role' , ' backupuser' ]);
23
+ $node -> init(
24
+ ' allows_streaming' => 1,
25
+ ' auth_extra' => [ ' --create-role' , ' backupuser' ]);
25
26
26
27
$node -> append_conf(' postgresql.conf' ,
27
- " shared_preload_libraries = 'basebackup_to_shell'" );
28
+ " shared_preload_libraries = 'basebackup_to_shell'" );
28
29
$node -> start;
29
30
$node -> safe_psql(' postgres' , ' CREATE USER backupuser REPLICATION' );
30
31
$node -> safe_psql(' postgres' , ' CREATE ROLE trustworthy' );
41
42
42
43
# Can't use this module without setting basebackup_to_shell.command.
43
44
$node -> command_fails_like(
44
- [ @pg_basebackup_cmd , ' --target' , ' shell' ],
45
+ [ @pg_basebackup_cmd , ' --target' , ' shell' ],
45
46
qr / shell command for backup is not configured/ ,
46
47
' fails if basebackup_to_shell.command is not set' );
47
48
48
49
# Configure basebackup_to_shell.command and reload the configuation file.
49
- my $backup_path = PostgreSQL::Test::Utils::tempdir;
50
+ my $backup_path = PostgreSQL::Test::Utils::tempdir;
50
51
my $escaped_backup_path = $backup_path ;
51
- $escaped_backup_path =~ s {\\ } { \\\\ } g if ($PostgreSQL::Test::Utils::windows_os );
52
+ $escaped_backup_path =~ s {\\ } { \\\\ } g
53
+ if ($PostgreSQL::Test::Utils::windows_os );
52
54
my $shell_command =
53
- $PostgreSQL::Test::Utils::windows_os
54
- ? qq{ $gzip --fast > "$escaped_backup_path \\\\ %f .gz"}
55
- : qq{ $gzip --fast > "$escaped_backup_path /%f .gz"} ;
55
+ $PostgreSQL::Test::Utils::windows_os
56
+ ? qq{ $gzip --fast > "$escaped_backup_path \\\\ %f .gz"}
57
+ : qq{ $gzip --fast > "$escaped_backup_path /%f .gz"} ;
56
58
$node -> append_conf(' postgresql.conf' ,
57
- " basebackup_to_shell.command='$shell_command '" );
59
+ " basebackup_to_shell.command='$shell_command '" );
58
60
$node -> reload();
59
61
60
62
# Should work now.
61
63
$node -> command_ok(
62
- [ @pg_basebackup_cmd , ' --target' , ' shell' ],
64
+ [ @pg_basebackup_cmd , ' --target' , ' shell' ],
63
65
' backup with no detail: pg_basebackup' );
64
66
verify_backup(' ' , $backup_path , " backup with no detail" );
65
67
66
68
# Should fail with a detail.
67
69
$node -> command_fails_like(
68
- [ @pg_basebackup_cmd , ' --target' , ' shell:foo' ],
70
+ [ @pg_basebackup_cmd , ' --target' , ' shell:foo' ],
69
71
qr / a target detail is not permitted because the configured command does not include %d / ,
70
72
' fails if detail provided without %d' );
71
73
72
74
# Reconfigure to restrict access and require a detail.
73
75
$shell_command =
74
- $PostgreSQL::Test::Utils::windows_os
75
- ? qq{ $gzip --fast > "$escaped_backup_path \\\\ %d .%f .gz"}
76
- : qq{ $gzip --fast > "$escaped_backup_path /%d .%f .gz"} ;
76
+ $PostgreSQL::Test::Utils::windows_os
77
+ ? qq{ $gzip --fast > "$escaped_backup_path \\\\ %d .%f .gz"}
78
+ : qq{ $gzip --fast > "$escaped_backup_path /%d .%f .gz"} ;
77
79
$node -> append_conf(' postgresql.conf' ,
78
- " basebackup_to_shell.command='$shell_command '" );
80
+ " basebackup_to_shell.command='$shell_command '" );
79
81
$node -> append_conf(' postgresql.conf' ,
80
- " basebackup_to_shell.required_role='trustworthy'" );
82
+ " basebackup_to_shell.required_role='trustworthy'" );
81
83
$node -> reload();
82
84
83
85
# Should fail due to lack of permission.
84
86
$node -> command_fails_like(
85
- [ @pg_basebackup_cmd , ' --target' , ' shell' ],
87
+ [ @pg_basebackup_cmd , ' --target' , ' shell' ],
86
88
qr / permission denied to use basebackup_to_shell/ ,
87
89
' fails if required_role not granted' );
88
90
89
91
# Should fail due to lack of a detail.
90
92
$node -> safe_psql(' postgres' , ' GRANT trustworthy TO backupuser' );
91
93
$node -> command_fails_like(
92
- [ @pg_basebackup_cmd , ' --target' , ' shell' ],
94
+ [ @pg_basebackup_cmd , ' --target' , ' shell' ],
93
95
qr / a target detail is required because the configured command includes %d / ,
94
96
' fails if %d is present and detail not given' );
95
97
96
98
# Should work.
97
- $node -> command_ok(
98
- [ @pg_basebackup_cmd , ' --target' , ' shell:bar' ],
99
+ $node -> command_ok([ @pg_basebackup_cmd , ' --target' , ' shell:bar' ],
99
100
' backup with detail: pg_basebackup' );
100
101
verify_backup(' bar.' , $backup_path , " backup with detail" );
101
102
@@ -105,30 +106,34 @@ sub verify_backup
105
106
{
106
107
my ($prefix , $backup_dir , $test_name ) = @_ ;
107
108
108
- ok(-f " $backup_dir /${prefix} backup_manifest.gz" ,
109
- " $test_name : backup_manifest.gz was created" );
110
- ok(-f " $backup_dir /${prefix} base.tar.gz" ,
111
- " $test_name : base.tar.gz was created" );
109
+ ok( -f " $backup_dir /${prefix} backup_manifest.gz" ,
110
+ " $test_name : backup_manifest.gz was created" );
111
+ ok( -f " $backup_dir /${prefix} base.tar.gz" ,
112
+ " $test_name : base.tar.gz was created" );
112
113
113
- SKIP: {
114
+ SKIP:
115
+ {
114
116
my $tar = $ENV {TAR };
115
117
skip " no tar program available" , 1 if (!defined $tar || $tar eq ' ' );
116
118
117
119
# Decompress.
118
120
system_or_bail($gzip , ' -d' ,
119
- $backup_dir . ' /' . $prefix . ' backup_manifest.gz' );
121
+ $backup_dir . ' /' . $prefix . ' backup_manifest.gz' );
120
122
system_or_bail($gzip , ' -d' ,
121
- $backup_dir . ' /' . $prefix . ' base.tar.gz' );
123
+ $backup_dir . ' /' . $prefix . ' base.tar.gz' );
122
124
123
125
# Untar.
124
126
my $extract_path = PostgreSQL::Test::Utils::tempdir;
125
127
system_or_bail($tar , ' xf' , $backup_dir . ' /' . $prefix . ' base.tar' ,
126
- ' -C' , $extract_path );
128
+ ' -C' , $extract_path );
127
129
128
130
# Verify.
129
- $node -> command_ok([ ' pg_verifybackup' , ' -n' ,
130
- ' -m' , " ${backup_dir} /${prefix} backup_manifest" ,
131
- ' -e' , $extract_path ],
132
- " $test_name : backup verifies ok" );
131
+ $node -> command_ok(
132
+ [
133
+ ' pg_verifybackup' , ' -n' ,
134
+ ' -m' , " ${backup_dir} /${prefix} backup_manifest" ,
135
+ ' -e' , $extract_path
136
+ ],
137
+ " $test_name : backup verifies ok" );
133
138
}
134
139
}
0 commit comments