66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
88 *
9- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.19 2003/05/3022 :55:16 tgl Exp $
9+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.20 2003/05/3023 :55:10 tgl Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -60,6 +60,7 @@ static char *findPgDump(const char *argv0);
6060char * pgdumploc ;
6161PQExpBuffer pgdumpopts ;
6262bool output_clean = false;
63+ bool skip_acls = false;
6364bool verbose = false;
6465int server_version ;
6566
@@ -72,11 +73,14 @@ main(int argc, char *argv[])
7273char * pgport = NULL ;
7374char * pguser = NULL ;
7475bool force_password = false;
76+ bool data_only = false;
7577bool globals_only = false;
78+ bool schema_only = false;
7679PGconn * conn ;
7780int c ;
7881
7982static struct option long_options []= {
83+ {"data-only" ,no_argument ,NULL ,'a' },
8084{"clean" ,no_argument ,NULL ,'c' },
8185{"inserts" ,no_argument ,NULL ,'d' },
8286{"attribute-inserts" ,no_argument ,NULL ,'D' },
@@ -87,8 +91,11 @@ main(int argc, char *argv[])
8791{"oids" ,no_argument ,NULL ,'o' },
8892{"port" ,required_argument ,NULL ,'p' },
8993{"password" ,no_argument ,NULL ,'W' },
94+ {"schema-only" ,no_argument ,NULL ,'s' },
9095{"username" ,required_argument ,NULL ,'U' },
9196{"verbose" ,no_argument ,NULL ,'v' },
97+ {"no-privileges" ,no_argument ,NULL ,'x' },
98+ {"no-acl" ,no_argument ,NULL ,'x' },
9299{NULL ,0 ,NULL ,0 }
93100};
94101
@@ -119,10 +126,15 @@ main(int argc, char *argv[])
119126pgdumploc = findPgDump (argv [0 ]);
120127pgdumpopts = createPQExpBuffer ();
121128
122- while ((c = getopt_long (argc ,argv ,"cdDgh :iop:U:vW " ,long_options ,& optindex ))!= -1 )
129+ while ((c = getopt_long (argc ,argv ,"acdDgh :iop:sU:vWx " ,long_options ,& optindex ))!= -1 )
123130{
124131switch (c )
125132{
133+ case 'a' :
134+ data_only = true;
135+ appendPQExpBuffer (pgdumpopts ," -a" );
136+ break ;
137+
126138case 'c' :
127139output_clean = true;
128140break ;
@@ -151,6 +163,11 @@ main(int argc, char *argv[])
151163appendPQExpBuffer (pgdumpopts ," -p '%s'" ,pgport );
152164break ;
153165
166+ case 's' :
167+ schema_only = true;
168+ appendPQExpBuffer (pgdumpopts ," -s" );
169+ break ;
170+
154171case 'U' :
155172pguser = optarg ;
156173appendPQExpBuffer (pgdumpopts ," -U '%s'" ,pguser );
@@ -166,6 +183,11 @@ main(int argc, char *argv[])
166183appendPQExpBuffer (pgdumpopts ," -W" );
167184break ;
168185
186+ case 'x' :
187+ skip_acls = true;
188+ appendPQExpBuffer (pgdumpopts ," -x" );
189+ break ;
190+
169191default :
170192fprintf (stderr ,_ ("Try '%s --help' for more information.\n" ),progname );
171193exit (1 );
@@ -189,16 +211,19 @@ main(int argc, char *argv[])
189211printf ("--\n\n" );
190212printf ("\\connect \"template1\"\n\n" );
191213
192- dumpUsers ( conn );
193- dumpGroups ( conn );
194-
195- if ( globals_only )
196- goto end ;
214+ if (! data_only )
215+ {
216+ dumpUsers ( conn );
217+ dumpGroups ( conn );
218+ }
197219
198- dumpCreateDB (conn );
199- dumpDatabases (conn );
220+ if (!globals_only )
221+ {
222+ if (!data_only )
223+ dumpCreateDB (conn );
224+ dumpDatabases (conn );
225+ }
200226
201- end :
202227PQfinish (conn );
203228exit (0 );
204229}
@@ -213,14 +238,17 @@ help(void)
213238printf (_ (" %s [OPTION]...\n" ),progname );
214239
215240printf (_ ("\nOptions:\n" ));
241+ printf (_ (" -a, --data-only dump only the data, not the schema\n" ));
216242printf (_ (" -c, --clean clean (drop) databases prior to create\n" ));
217243printf (_ (" -d, --inserts dump data as INSERT, rather than COPY, commands\n" ));
218244printf (_ (" -D, --column-inserts dump data as INSERT commands with column names\n" ));
219245printf (_ (" -g, --globals-only dump only global objects, no databases\n" ));
220246printf (_ (" -i, --ignore-version proceed even when server version mismatches\n"
221247" pg_dumpall version\n" ));
248+ printf (_ (" -s, --schema-only dump only the schema, no data\n" ));
222249printf (_ (" -o, --oids include OIDs in dump\n" ));
223250printf (_ (" -v, --verbose verbose mode\n" ));
251+ printf (_ (" -x, --no-privileges do not dump privileges (grant/revoke)\n" ));
224252printf (_ (" --help show this help, then exit\n" ));
225253printf (_ (" --version output version information, then exit\n" ));
226254
@@ -462,7 +490,8 @@ dumpCreateDB(PGconn *conn)
462490appendPQExpBuffer (buf ,";\n" );
463491}
464492
465- if (!buildACLCommands (fdbname ,"DATABASE" ,dbacl ,dbowner ,
493+ if (!skip_acls &&
494+ !buildACLCommands (fdbname ,"DATABASE" ,dbacl ,dbowner ,
466495server_version ,buf ))
467496{
468497fprintf (stderr ,_ ("%s: could not parse ACL list (%s) for database %s\n" ),