OSDN Git Service

Add --tablespaces-only and --roles-only options to pg_dumpall.
authorBruce Momjian <bruce@momjian.us>
Thu, 25 Jan 2007 02:30:32 +0000 (02:30 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 25 Jan 2007 02:30:32 +0000 (02:30 +0000)
Dave Page

doc/src/sgml/ref/pg_dumpall.sgml
src/bin/pg_dump/pg_dumpall.c

index b9f3919..3f40be0 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.59 2007/01/15 17:22:46 neilc Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.60 2007/01/25 02:30:32 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -194,6 +194,16 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>-r</option></term>
+      <term><option>--roles-only</option></term>
+      <listitem>
+       <para>
+        Dump only roles, no databases or tablespaces.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-s</option></term>
       <term><option>--schema-only</option></term>
       <listitem>
@@ -217,6 +227,16 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>-t</option></term>
+      <term><option>--tablespaces-only</option></term>
+      <listitem>
+       <para>
+        Dump only tablespaces, no databases or roles.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-v</></term>
       <term><option>--verbose</></term>
       <listitem>
index 716d1ed..697754e 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.86 2007/01/05 22:19:48 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.87 2007/01/25 02:30:32 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -78,6 +78,8 @@ main(int argc, char *argv[])
        bool            force_password = false;
        bool            data_only = false;
        bool            globals_only = false;
+       bool            roles_only = false;
+       bool            tablespaces_only = false;
        bool            schema_only = false;
        PGconn     *conn;
        int                     encoding;
@@ -97,11 +99,13 @@ main(int argc, char *argv[])
                {"oids", no_argument, NULL, 'o'},
                {"no-owner", no_argument, NULL, 'O'},
                {"port", required_argument, NULL, 'p'},
-               {"password", no_argument, NULL, 'W'},
+               {"roles-only", no_argument, NULL, 'r'},
                {"schema-only", no_argument, NULL, 's'},
                {"superuser", required_argument, NULL, 'S'},
+               {"tablespaces-only", no_argument, NULL, 't'},
                {"username", required_argument, NULL, 'U'},
                {"verbose", no_argument, NULL, 'v'},
+               {"password", no_argument, NULL, 'W'},
                {"no-privileges", no_argument, NULL, 'x'},
                {"no-acl", no_argument, NULL, 'x'},
 
@@ -161,7 +165,7 @@ main(int argc, char *argv[])
 
        pgdumpopts = createPQExpBuffer();
 
-       while ((c = getopt_long(argc, argv, "acdDgh:ioOp:sS:U:vWxX:", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "acdDgh:ioOp:rsS:tU:vWxX:", long_options, &optindex)) != -1)
        {
                switch (c)
                {
@@ -214,6 +218,10 @@ main(int argc, char *argv[])
                                appendPQExpBuffer(pgdumpopts, " -p \"%s\"", pgport);
 #endif
                                break;
+                               
+                       case 'r':
+                               roles_only = true;
+                               break;
 
                        case 's':
                                schema_only = true;
@@ -227,6 +235,10 @@ main(int argc, char *argv[])
                                appendPQExpBuffer(pgdumpopts, " -S \"%s\"", optarg);
 #endif
                                break;
+                               
+                       case 't':
+                               tablespaces_only = true;
+                               break;
 
                        case 'U':
                                pguser = optarg;
@@ -295,6 +307,34 @@ main(int argc, char *argv[])
                                progname);
                exit(1);
        }
+       
+       /* Make sure the user hasn't specified a mix of globals-only options */
+       if (globals_only && roles_only)
+       {
+               fprintf(stderr, _("%s: --globals-only and --roles-only cannot be used together\n"),
+                               progname);
+               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+                               progname);
+               exit(1);
+       }
+       
+       if (globals_only && tablespaces_only)
+       {
+               fprintf(stderr, _("%s: --globals-only and --tablespaces-only cannot be used together\n"),
+                               progname);
+               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+                               progname);
+               exit(1);
+       }
+       
+       if (roles_only && tablespaces_only)
+       {
+               fprintf(stderr, _("%s: --roles-only and --tablespaces-only cannot be used together\n"),
+                               progname);
+               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+                               progname);
+               exit(1);
+       }
 
        /*
         * First try to connect to database "postgres", and failing that
@@ -332,25 +372,31 @@ main(int argc, char *argv[])
                        printf("SET escape_string_warning = 'off';\n");
                printf("\n");
 
-               /* Dump roles (users) */
-               dumpRoles(conn);
-
-               /* Dump role memberships --- need different method for pre-8.1 */
-               if (server_version >= 80100)
-                       dumpRoleMembership(conn);
-               else
-                       dumpGroups(conn);
+               if (!tablespaces_only)
+               {
+                       /* Dump roles (users) */
+                       dumpRoles(conn);
+
+                       /* Dump role memberships --- need different method for pre-8.1 */
+                       if (server_version >= 80100)
+                               dumpRoleMembership(conn);
+                       else
+                               dumpGroups(conn);
+               }
 
-               /* Dump tablespaces */
-               if (server_version >= 80000)
-                       dumpTablespaces(conn);
+               if (!roles_only)
+               {
+                       /* Dump tablespaces */
+                       if (server_version >= 80000)
+                               dumpTablespaces(conn);
+               }
 
                /* Dump CREATE DATABASE commands */
-               if (!globals_only)
+               if (!globals_only && !roles_only && !tablespaces_only)
                        dumpCreateDB(conn);
        }
 
-       if (!globals_only)
+       if (!globals_only && !roles_only && !tablespaces_only)
                dumpDatabases(conn);
 
        PQfinish(conn);
@@ -384,8 +430,10 @@ help(void)
        printf(_("  -g, --globals-only       dump only global objects, no databases\n"));
        printf(_("  -o, --oids               include OIDs in dump\n"));
        printf(_("  -O, --no-owner           skip restoration of object ownership\n"));
+       printf(_("  -r, --roles-only         dump only roles, no databases or tablespaces\n"));
        printf(_("  -s, --schema-only        dump only the schema, no data\n"));
        printf(_("  -S, --superuser=NAME     specify the superuser user name to use in the dump\n"));
+       printf(_("  -t, --tablespaces-only   dump only tablespaces, no databases or roles\n"));
        printf(_("  -x, --no-privileges      do not dump privileges (grant/revoke)\n"));
        printf(_("  --disable-dollar-quoting\n"
                         "                           disable dollar quoting, use SQL standard quoting\n"));