Commit 5ce94b28 authored by Bruce Momjian's avatar Bruce Momjian

Add --tablespaces-only and --roles-only options to pg_dumpall.

Dave Page
parent ef65f6f7
<!-- <!--
$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 PostgreSQL documentation
--> -->
...@@ -193,6 +193,16 @@ PostgreSQL documentation ...@@ -193,6 +193,16 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </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> <varlistentry>
<term><option>-s</option></term> <term><option>-s</option></term>
<term><option>--schema-only</option></term> <term><option>--schema-only</option></term>
...@@ -216,6 +226,16 @@ PostgreSQL documentation ...@@ -216,6 +226,16 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </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> <varlistentry>
<term><option>-v</></term> <term><option>-v</></term>
<term><option>--verbose</></term> <term><option>--verbose</></term>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * 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[]) ...@@ -78,6 +78,8 @@ main(int argc, char *argv[])
bool force_password = false; bool force_password = false;
bool data_only = false; bool data_only = false;
bool globals_only = false; bool globals_only = false;
bool roles_only = false;
bool tablespaces_only = false;
bool schema_only = false; bool schema_only = false;
PGconn *conn; PGconn *conn;
int encoding; int encoding;
...@@ -97,11 +99,13 @@ main(int argc, char *argv[]) ...@@ -97,11 +99,13 @@ main(int argc, char *argv[])
{"oids", no_argument, NULL, 'o'}, {"oids", no_argument, NULL, 'o'},
{"no-owner", no_argument, NULL, 'O'}, {"no-owner", no_argument, NULL, 'O'},
{"port", required_argument, NULL, 'p'}, {"port", required_argument, NULL, 'p'},
{"password", no_argument, NULL, 'W'}, {"roles-only", no_argument, NULL, 'r'},
{"schema-only", no_argument, NULL, 's'}, {"schema-only", no_argument, NULL, 's'},
{"superuser", required_argument, NULL, 'S'}, {"superuser", required_argument, NULL, 'S'},
{"tablespaces-only", no_argument, NULL, 't'},
{"username", required_argument, NULL, 'U'}, {"username", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{"password", no_argument, NULL, 'W'},
{"no-privileges", no_argument, NULL, 'x'}, {"no-privileges", no_argument, NULL, 'x'},
{"no-acl", no_argument, NULL, 'x'}, {"no-acl", no_argument, NULL, 'x'},
...@@ -161,7 +165,7 @@ main(int argc, char *argv[]) ...@@ -161,7 +165,7 @@ main(int argc, char *argv[])
pgdumpopts = createPQExpBuffer(); 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) switch (c)
{ {
...@@ -214,6 +218,10 @@ main(int argc, char *argv[]) ...@@ -214,6 +218,10 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " -p \"%s\"", pgport); appendPQExpBuffer(pgdumpopts, " -p \"%s\"", pgport);
#endif #endif
break; break;
case 'r':
roles_only = true;
break;
case 's': case 's':
schema_only = true; schema_only = true;
...@@ -227,6 +235,10 @@ main(int argc, char *argv[]) ...@@ -227,6 +235,10 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " -S \"%s\"", optarg); appendPQExpBuffer(pgdumpopts, " -S \"%s\"", optarg);
#endif #endif
break; break;
case 't':
tablespaces_only = true;
break;
case 'U': case 'U':
pguser = optarg; pguser = optarg;
...@@ -295,6 +307,34 @@ main(int argc, char *argv[]) ...@@ -295,6 +307,34 @@ main(int argc, char *argv[])
progname); progname);
exit(1); 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 * First try to connect to database "postgres", and failing that
...@@ -332,25 +372,31 @@ main(int argc, char *argv[]) ...@@ -332,25 +372,31 @@ main(int argc, char *argv[])
printf("SET escape_string_warning = 'off';\n"); printf("SET escape_string_warning = 'off';\n");
printf("\n"); printf("\n");
/* Dump roles (users) */ if (!tablespaces_only)
dumpRoles(conn); {
/* Dump roles (users) */
/* Dump role memberships --- need different method for pre-8.1 */ dumpRoles(conn);
if (server_version >= 80100)
dumpRoleMembership(conn); /* Dump role memberships --- need different method for pre-8.1 */
else if (server_version >= 80100)
dumpGroups(conn); dumpRoleMembership(conn);
else
dumpGroups(conn);
}
/* Dump tablespaces */ if (!roles_only)
if (server_version >= 80000) {
dumpTablespaces(conn); /* Dump tablespaces */
if (server_version >= 80000)
dumpTablespaces(conn);
}
/* Dump CREATE DATABASE commands */ /* Dump CREATE DATABASE commands */
if (!globals_only) if (!globals_only && !roles_only && !tablespaces_only)
dumpCreateDB(conn); dumpCreateDB(conn);
} }
if (!globals_only) if (!globals_only && !roles_only && !tablespaces_only)
dumpDatabases(conn); dumpDatabases(conn);
PQfinish(conn); PQfinish(conn);
...@@ -384,8 +430,10 @@ help(void) ...@@ -384,8 +430,10 @@ help(void)
printf(_(" -g, --globals-only dump only global objects, no databases\n")); printf(_(" -g, --globals-only dump only global objects, no databases\n"));
printf(_(" -o, --oids include OIDs in dump\n")); printf(_(" -o, --oids include OIDs in dump\n"));
printf(_(" -O, --no-owner skip restoration of object ownership\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, --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(_(" -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(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
printf(_(" --disable-dollar-quoting\n" printf(_(" --disable-dollar-quoting\n"
" disable dollar quoting, use SQL standard quoting\n")); " disable dollar quoting, use SQL standard quoting\n"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment