Skip to content

Commit d68714b

Browse files
committed
Allow pg_basebackup compressed tar output to stdout
1 parent 1b6dabc commit d68714b

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ PostgreSQL documentation
174174
<listitem>
175175
<para>
176176
Enables gzip compression of tar file output. Compression is only
177-
available when generating tar files, and is not available when sending
178-
output to standard output.
177+
available when using the tar format.
179178
</para>
180179
</listitem>
181180
</varlistentry>

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,22 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
261261
* Base tablespaces
262262
*/
263263
if (strcmp(basedir, "-") == 0)
264-
tarfile = stdout;
264+
{
265+
#ifdef HAVE_LIBZ
266+
if (compresslevel > 0)
267+
{
268+
ztarfile = gzdopen(dup(fileno(stdout)), "wb");
269+
if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK)
270+
{
271+
fprintf(stderr, _("%s: could not set compression level %i: %s\n"),
272+
progname, compresslevel, get_gz_error(ztarfile));
273+
disconnect_and_exit(1);
274+
}
275+
}
276+
else
277+
#endif
278+
tarfile = stdout;
279+
}
265280
else
266281
{
267282
#ifdef HAVE_LIBZ
@@ -384,7 +399,14 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
384399
}
385400
}
386401

387-
if (strcmp(basedir, "-") != 0)
402+
if (strcmp(basedir, "-") == 0)
403+
{
404+
#ifdef HAVE_LIBZ
405+
if (ztarfile)
406+
gzclose(ztarfile);
407+
#endif
408+
}
409+
else
388410
{
389411
#ifdef HAVE_LIBZ
390412
if (ztarfile != NULL)
@@ -1076,14 +1098,6 @@ main(int argc, char **argv)
10761098
progname);
10771099
exit(1);
10781100
}
1079-
#else
1080-
if (compresslevel > 0 && strcmp(basedir, "-") == 0)
1081-
{
1082-
fprintf(stderr,
1083-
_("%s: compression is not supported on standard output\n"),
1084-
progname);
1085-
exit(1);
1086-
}
10871101
#endif
10881102

10891103
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy