]> granicus.if.org Git - postgresql/commitdiff
Allow pg_basebackup compressed tar output to stdout
authorPeter Eisentraut <peter_e@gmx.net>
Sat, 28 May 2011 22:17:37 +0000 (01:17 +0300)
committerPeter Eisentraut <peter_e@gmx.net>
Sat, 28 May 2011 22:18:17 +0000 (01:18 +0300)
doc/src/sgml/ref/pg_basebackup.sgml
src/bin/pg_basebackup/pg_basebackup.c

index 8a7b833f0fc3d261a3f7364139723c46e2b09477..32fa9f858ca8da8f59d60306f1d2b885cc30d125 100644 (file)
@@ -174,8 +174,7 @@ PostgreSQL documentation
       <listitem>
        <para>
         Enables gzip compression of tar file output. Compression is only
-        available when generating tar files, and is not available when sending
-        output to standard output.
+        available when using the tar format.
        </para>
       </listitem>
      </varlistentry>
index 1f31fe0694cdc90077769296707e62c7a0ff8ab3..2af7b50586f0a0b5efd94e4bb954f280a6e9fa0e 100644 (file)
@@ -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
 
        /*