On sön, 2011-05-22 at 16:43 -0400, Magnus Hagander wrote:
> On Fri, May 20, 2011 at 17:45, Peter Eisentraut <pete...@gmx.net> wrote:
> > On fre, 2011-05-20 at 14:19 -0400, Magnus Hagander wrote:
> >> > I suggest we add an argument-less option -z that means "compress",
> >> and
> >> > then -Z can be relegated to choosing the compression level.
> >>
> >> We can't just use -Z without a parameter for that?
> >
> > You can't portably have a command-line option with an optional argument.
> 
> Ugh.
> 
> In that case, I'm fine with your suggestion.

Quick patch for verification.  I chose the naming -z/--gzip to mirror
GNU tar.
diff --git i/doc/src/sgml/ref/pg_basebackup.sgml w/doc/src/sgml/ref/pg_basebackup.sgml
index 8a7b833..ce7eb52 100644
--- i/doc/src/sgml/ref/pg_basebackup.sgml
+++ w/doc/src/sgml/ref/pg_basebackup.sgml
@@ -169,8 +169,8 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
-      <term><option>-Z <replaceable class="parameter">level</replaceable></option></term>
-      <term><option>--compress=<replaceable class="parameter">level</replaceable></option></term>
+      <term><option>-z</option></term>
+      <term><option>--gzip</option></term>
       <listitem>
        <para>
         Enables gzip compression of tar file output. Compression is only
@@ -179,6 +179,18 @@ PostgreSQL documentation
        </para>
       </listitem>
      </varlistentry>
+
+     <varlistentry>
+      <term><option>-Z <replaceable class="parameter">level</replaceable></option></term>
+      <term><option>--compress-level=<replaceable class="parameter">level</replaceable></option></term>
+      <listitem>
+       <para>
+        Sets the compression level when gzip compression is enabled.
+        The default is the default compression level of the zlib
+        library.
+       </para>
+      </listitem>
+     </varlistentry>
     </variablelist>
    </para>
    <para>
@@ -394,11 +406,11 @@ PostgreSQL documentation
   </para>
 
   <para>
-   To create a backup of the local server with one maximum compressed
+   To create a backup of the local server with one compressed
    tar file for each tablespace, and store it in the directory
    <filename>backup</filename>, showing a progress report while running:
 <screen>
-<prompt>$</prompt> <userinput>pg_basebackup -D backup -Ft -Z9 -P</userinput>
+<prompt>$</prompt> <userinput>pg_basebackup -D backup -Ft -z -P</userinput>
 </screen>
   </para>
 
diff --git i/src/bin/pg_basebackup/pg_basebackup.c w/src/bin/pg_basebackup/pg_basebackup.c
index 1f31fe0..7c2cb57 100644
--- i/src/bin/pg_basebackup/pg_basebackup.c
+++ w/src/bin/pg_basebackup/pg_basebackup.c
@@ -32,7 +32,10 @@ char		format = 'p';		/* p(lain)/t(ar) */
 char	   *label = "pg_basebackup base backup";
 bool		showprogress = false;
 int			verbose = 0;
-int			compresslevel = 0;
+bool		gzip = false;
+#ifdef HAVE_LIBZ
+int			compresslevel = Z_DEFAULT_COMPRESSION;
+#endif
 bool		includewal = false;
 bool		fastcheckpoint = false;
 char	   *dbhost = NULL;
@@ -126,7 +129,8 @@ usage(void)
 	printf(_("  -D, --pgdata=DIRECTORY   receive base backup into directory\n"));
 	printf(_("  -F, --format=p|t         output format (plain, tar)\n"));
 	printf(_("  -x, --xlog               include required WAL files in backup\n"));
-	printf(_("  -Z, --compress=0-9       compress tar output\n"));
+	printf(_("  -z, --gzip               compress tar output with gzip\n"));
+	printf(_("  -Z, --compress-level=0-9 compression level\n"));
 	printf(_("\nGeneral options:\n"));
 	printf(_("  -c, --checkpoint=fast|spread\n"
 			 "                           set fast or spread checkpointing\n"));
@@ -265,7 +269,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 		else
 		{
 #ifdef HAVE_LIBZ
-			if (compresslevel > 0)
+			if (gzip)
 			{
 				snprintf(fn, sizeof(fn), "%s/base.tar.gz", basedir);
 				ztarfile = gzopen(fn, "wb");
@@ -289,7 +293,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 		 * Specific tablespace
 		 */
 #ifdef HAVE_LIBZ
-		if (compresslevel > 0)
+		if (gzip)
 		{
 			snprintf(fn, sizeof(fn), "%s/%s.tar.gz", basedir, PQgetvalue(res, rownum, 0));
 			ztarfile = gzopen(fn, "wb");
@@ -309,7 +313,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 	}
 
 #ifdef HAVE_LIBZ
-	if (compresslevel > 0)
+	if (gzip)
 	{
 		if (!ztarfile)
 		{
@@ -919,7 +923,8 @@ main(int argc, char **argv)
 		{"format", required_argument, NULL, 'F'},
 		{"checkpoint", required_argument, NULL, 'c'},
 		{"xlog", no_argument, NULL, 'x'},
-		{"compress", required_argument, NULL, 'Z'},
+		{"gzip", no_argument, NULL, 'z'},
+		{"compress-level", required_argument, NULL, 'Z'},
 		{"label", required_argument, NULL, 'l'},
 		{"host", required_argument, NULL, 'h'},
 		{"port", required_argument, NULL, 'p'},
@@ -952,7 +957,7 @@ main(int argc, char **argv)
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:F:l:Z:c:h:p:U:xwWvP",
+	while ((c = getopt_long(argc, argv, "D:F:l:c:h:p:U:xwWvPzZ:",
 							long_options, &option_index)) != -1)
 	{
 		switch (c)
@@ -978,6 +983,9 @@ main(int argc, char **argv)
 			case 'l':
 				label = xstrdup(optarg);
 				break;
+			case 'z':
+				gzip = true;
+				break;
 			case 'Z':
 				compresslevel = atoi(optarg);
 				if (compresslevel <= 0 || compresslevel > 9)
@@ -1058,7 +1066,7 @@ main(int argc, char **argv)
 	/*
 	 * Mutually exclusive arguments
 	 */
-	if (format == 'p' && compresslevel > 0)
+	if (format == 'p' && gzip)
 	{
 		fprintf(stderr,
 				_("%s: only tar mode backups can be compressed\n"),
@@ -1069,7 +1077,7 @@ main(int argc, char **argv)
 	}
 
 #ifndef HAVE_LIBZ
-	if (compresslevel > 0)
+	if (gzip)
 	{
 		fprintf(stderr,
 				_("%s: this build does not support compression\n"),
@@ -1077,7 +1085,7 @@ main(int argc, char **argv)
 		exit(1);
 	}
 #else
-	if (compresslevel > 0 && strcmp(basedir, "-") == 0)
+	if (gzip && strcmp(basedir, "-") == 0)
 	{
 		fprintf(stderr,
 				_("%s: compression is not supported on standard output\n"),
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to