diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2011-05-29 01:17:37 +0300 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2011-05-29 01:18:17 +0300 |
commit | d68714b29c42d10437b56372d6b0a1dda1e7d7f5 (patch) | |
tree | ba815b50155d271c8cc3892cf16d92c12733d7b0 /src | |
parent | 1b6dabc452b9357e39b63a94c109e2293f13a555 (diff) | |
download | postgresql-d68714b29c42d10437b56372d6b0a1dda1e7d7f5.tar.gz postgresql-d68714b29c42d10437b56372d6b0a1dda1e7d7f5.zip |
Allow pg_basebackup compressed tar output to stdout
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 1f31fe0694c..2af7b50586f 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -261,7 +261,22 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) * Base tablespaces */ if (strcmp(basedir, "-") == 0) - tarfile = stdout; + { +#ifdef HAVE_LIBZ + if (compresslevel > 0) + { + ztarfile = gzdopen(dup(fileno(stdout)), "wb"); + if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK) + { + fprintf(stderr, _("%s: could not set compression level %i: %s\n"), + progname, compresslevel, get_gz_error(ztarfile)); + disconnect_and_exit(1); + } + } + else +#endif + tarfile = stdout; + } else { #ifdef HAVE_LIBZ @@ -384,7 +399,14 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) } } - if (strcmp(basedir, "-") != 0) + if (strcmp(basedir, "-") == 0) + { +#ifdef HAVE_LIBZ + if (ztarfile) + gzclose(ztarfile); +#endif + } + else { #ifdef HAVE_LIBZ if (ztarfile != NULL) @@ -1076,14 +1098,6 @@ main(int argc, char **argv) progname); exit(1); } -#else - if (compresslevel > 0 && strcmp(basedir, "-") == 0) - { - fprintf(stderr, - _("%s: compression is not supported on standard output\n"), - progname); - exit(1); - } #endif /* |