Since I needed this feature badly, I added the -n / --schema switch to
pg_restore. It restores the given schemaname only. It can be used in conjunction with the -t and other switches to make the selection very fine grained. Richard van den Bergg, CISSP
This commit is contained in:
parent
4d0e7b4aac
commit
ebc8649892
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.51 2005/05/29 03:32:18 momjian Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.52 2005/06/09 17:56:51 momjian Exp $ -->
|
||||||
|
|
||||||
<refentry id="APP-PGRESTORE">
|
<refentry id="APP-PGRESTORE">
|
||||||
<refmeta>
|
<refmeta>
|
||||||
@ -239,6 +239,18 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>-n <replaceable class="parameter">namespace</replaceable></option></term>
|
||||||
|
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Restore only definitions and/or data in the named schema. Not to be
|
||||||
|
confused with the <option>-s</option> option. This can be combined with
|
||||||
|
<option>-t</option> option.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-O</option></term>
|
<term><option>-O</option></term>
|
||||||
<term><option>--no-owner</option></term>
|
<term><option>--no-owner</option></term>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.34 2004/11/06 19:36:01 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.35 2005/06/09 17:56:51 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -98,6 +98,7 @@ typedef struct _restoreOptions
|
|||||||
char *indexNames;
|
char *indexNames;
|
||||||
char *functionNames;
|
char *functionNames;
|
||||||
char *tableNames;
|
char *tableNames;
|
||||||
|
char *schemaNames;
|
||||||
char *triggerNames;
|
char *triggerNames;
|
||||||
|
|
||||||
int useDB;
|
int useDB;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.109 2005/05/17 17:30:29 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.110 2005/06/09 17:56:51 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1997,6 +1997,14 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
|
|||||||
/* Check if tablename only is wanted */
|
/* Check if tablename only is wanted */
|
||||||
if (ropt->selTypes)
|
if (ropt->selTypes)
|
||||||
{
|
{
|
||||||
|
if (ropt->schemaNames)
|
||||||
|
{
|
||||||
|
/* If no namespace is specified, it means all. */
|
||||||
|
if (!te->namespace)
|
||||||
|
return 0;
|
||||||
|
if(strcmp(ropt->schemaNames, te->namespace) != 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if ((strcmp(te->desc, "TABLE") == 0) || (strcmp(te->desc, "TABLE DATA") == 0))
|
if ((strcmp(te->desc, "TABLE") == 0) || (strcmp(te->desc, "TABLE DATA") == 0))
|
||||||
{
|
{
|
||||||
if (!ropt->selTable)
|
if (!ropt->selTable)
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.70 2005/04/29 07:08:06 neilc Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.71 2005/06/09 17:56:51 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -103,6 +103,7 @@ main(int argc, char **argv)
|
|||||||
{"no-reconnect", 0, NULL, 'R'},
|
{"no-reconnect", 0, NULL, 'R'},
|
||||||
{"port", 1, NULL, 'p'},
|
{"port", 1, NULL, 'p'},
|
||||||
{"password", 0, NULL, 'W'},
|
{"password", 0, NULL, 'W'},
|
||||||
|
{"schema", 1, NULL, 'n'},
|
||||||
{"schema-only", 0, NULL, 's'},
|
{"schema-only", 0, NULL, 's'},
|
||||||
{"superuser", 1, NULL, 'S'},
|
{"superuser", 1, NULL, 'S'},
|
||||||
{"table", 1, NULL, 't'},
|
{"table", 1, NULL, 't'},
|
||||||
@ -141,7 +142,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
|
while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:",
|
||||||
cmdopts, NULL)) != -1)
|
cmdopts, NULL)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -223,6 +224,11 @@ main(int argc, char **argv)
|
|||||||
opts->tableNames = strdup(optarg);
|
opts->tableNames = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'n': /* Dump data for this schema only */
|
||||||
|
opts->selTypes = 1;
|
||||||
|
opts->schemaNames = strdup(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
opts->requirePassword = true;
|
opts->requirePassword = true;
|
||||||
opts->username = simple_prompt("User name: ", 100, true);
|
opts->username = simple_prompt("User name: ", 100, true);
|
||||||
@ -375,6 +381,7 @@ usage(const char *progname)
|
|||||||
printf(_(" -I, --index=NAME restore named index\n"));
|
printf(_(" -I, --index=NAME restore named index\n"));
|
||||||
printf(_(" -L, --use-list=FILENAME use specified table of contents for ordering\n"
|
printf(_(" -L, --use-list=FILENAME use specified table of contents for ordering\n"
|
||||||
" output from this file\n"));
|
" output from this file\n"));
|
||||||
|
printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
|
||||||
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
|
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
|
||||||
printf(_(" -P, --function=NAME(args)\n"
|
printf(_(" -P, --function=NAME(args)\n"
|
||||||
" restore named function\n"));
|
" restore named function\n"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user