66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
88 *
9- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.86 2007/01/05 22:19:48 momjian Exp $
9+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.87 2007/01/25 02:30:32 momjian Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -78,6 +78,8 @@ main(int argc, char *argv[])
7878bool force_password = false;
7979bool data_only = false;
8080bool globals_only = false;
81+ bool roles_only = false;
82+ bool tablespaces_only = false;
8183bool schema_only = false;
8284PGconn * conn ;
8385int encoding ;
@@ -97,11 +99,13 @@ main(int argc, char *argv[])
9799{"oids" ,no_argument ,NULL ,'o' },
98100{"no-owner" ,no_argument ,NULL ,'O' },
99101{"port" ,required_argument ,NULL ,'p' },
100- {"password " ,no_argument ,NULL ,'W ' },
102+ {"roles-only " ,no_argument ,NULL ,'r ' },
101103{"schema-only" ,no_argument ,NULL ,'s' },
102104{"superuser" ,required_argument ,NULL ,'S' },
105+ {"tablespaces-only" ,no_argument ,NULL ,'t' },
103106{"username" ,required_argument ,NULL ,'U' },
104107{"verbose" ,no_argument ,NULL ,'v' },
108+ {"password" ,no_argument ,NULL ,'W' },
105109{"no-privileges" ,no_argument ,NULL ,'x' },
106110{"no-acl" ,no_argument ,NULL ,'x' },
107111
@@ -161,7 +165,7 @@ main(int argc, char *argv[])
161165
162166pgdumpopts = createPQExpBuffer ();
163167
164- while ((c = getopt_long (argc ,argv ,"acdDgh:ioOp:sS:U :vWxX:" ,long_options ,& optindex ))!= -1 )
168+ while ((c = getopt_long (argc ,argv ,"acdDgh:ioOp:rsS:tU :vWxX:" ,long_options ,& optindex ))!= -1 )
165169{
166170switch (c )
167171{
@@ -214,6 +218,10 @@ main(int argc, char *argv[])
214218appendPQExpBuffer (pgdumpopts ," -p \"%s\"" ,pgport );
215219#endif
216220break ;
221+
222+ case 'r' :
223+ roles_only = true;
224+ break ;
217225
218226case 's' :
219227schema_only = true;
@@ -227,6 +235,10 @@ main(int argc, char *argv[])
227235appendPQExpBuffer (pgdumpopts ," -S \"%s\"" ,optarg );
228236#endif
229237break ;
238+
239+ case 't' :
240+ tablespaces_only = true;
241+ break ;
230242
231243case 'U' :
232244pguser = optarg ;
@@ -295,6 +307,34 @@ main(int argc, char *argv[])
295307progname );
296308exit (1 );
297309}
310+
311+ /* Make sure the user hasn't specified a mix of globals-only options */
312+ if (globals_only && roles_only )
313+ {
314+ fprintf (stderr ,_ ("%s: --globals-only and --roles-only cannot be used together\n" ),
315+ progname );
316+ fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),
317+ progname );
318+ exit (1 );
319+ }
320+
321+ if (globals_only && tablespaces_only )
322+ {
323+ fprintf (stderr ,_ ("%s: --globals-only and --tablespaces-only cannot be used together\n" ),
324+ progname );
325+ fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),
326+ progname );
327+ exit (1 );
328+ }
329+
330+ if (roles_only && tablespaces_only )
331+ {
332+ fprintf (stderr ,_ ("%s: --roles-only and --tablespaces-only cannot be used together\n" ),
333+ progname );
334+ fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),
335+ progname );
336+ exit (1 );
337+ }
298338
299339/*
300340 * First try to connect to database "postgres", and failing that
@@ -332,25 +372,31 @@ main(int argc, char *argv[])
332372printf ("SET escape_string_warning = 'off';\n" );
333373printf ("\n" );
334374
335- /* Dump roles (users) */
336- dumpRoles (conn );
337-
338- /* Dump role memberships --- need different method for pre-8.1 */
339- if (server_version >=80100 )
340- dumpRoleMembership (conn );
341- else
342- dumpGroups (conn );
375+ if (!tablespaces_only )
376+ {
377+ /* Dump roles (users) */
378+ dumpRoles (conn );
379+
380+ /* Dump role memberships --- need different method for pre-8.1 */
381+ if (server_version >=80100 )
382+ dumpRoleMembership (conn );
383+ else
384+ dumpGroups (conn );
385+ }
343386
344- /* Dump tablespaces */
345- if (server_version >=80000 )
346- dumpTablespaces (conn );
387+ if (!roles_only )
388+ {
389+ /* Dump tablespaces */
390+ if (server_version >=80000 )
391+ dumpTablespaces (conn );
392+ }
347393
348394/* Dump CREATE DATABASE commands */
349- if (!globals_only )
395+ if (!globals_only && ! roles_only && ! tablespaces_only )
350396dumpCreateDB (conn );
351397}
352398
353- if (!globals_only )
399+ if (!globals_only && ! roles_only && ! tablespaces_only )
354400dumpDatabases (conn );
355401
356402PQfinish (conn );
@@ -384,8 +430,10 @@ help(void)
384430printf (_ (" -g, --globals-only dump only global objects, no databases\n" ));
385431printf (_ (" -o, --oids include OIDs in dump\n" ));
386432printf (_ (" -O, --no-owner skip restoration of object ownership\n" ));
433+ printf (_ (" -r, --roles-only dump only roles, no databases or tablespaces\n" ));
387434printf (_ (" -s, --schema-only dump only the schema, no data\n" ));
388435printf (_ (" -S, --superuser=NAME specify the superuser user name to use in the dump\n" ));
436+ printf (_ (" -t, --tablespaces-only dump only tablespaces, no databases or roles\n" ));
389437printf (_ (" -x, --no-privileges do not dump privileges (grant/revoke)\n" ));
390438printf (_ (" --disable-dollar-quoting\n"
391439" disable dollar quoting, use SQL standard quoting\n" ));