Commit 46b55e7f authored by Peter Eisentraut's avatar Peter Eisentraut

pg_restore: Add -N option to exclude schemas

This is similar to the -N option in pg_dump, except that it doesn't take
a pattern, just like the existing -n option in pg_restore.

From: Michael Banck <michael.banck@credativ.de>
parent 16d1adb3
...@@ -302,7 +302,7 @@ ...@@ -302,7 +302,7 @@
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><option>-n <replaceable class="parameter">namespace</replaceable></option></term> <term><option>-n <replaceable class="parameter">schema</replaceable></option></term>
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term> <term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>
<listitem> <listitem>
<para> <para>
...@@ -314,6 +314,22 @@ ...@@ -314,6 +314,22 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-N <replaceable class="parameter">schema</replaceable></option></term>
<term><option>--exclude-schema=<replaceable class="parameter">schema</replaceable></option></term>
<listitem>
<para>
Do not restore objects that are in the named schema. Multiple schemas
to be excluded may be specified with multiple <option>-N</> switches.
</para>
<para>
When both <option>-n</> and <option>-N</> are given for the same
schema name, the <option>-N</> switch wins and the schema is excluded.
</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>
......
...@@ -99,6 +99,7 @@ typedef struct _restoreOptions ...@@ -99,6 +99,7 @@ typedef struct _restoreOptions
SimpleStringList indexNames; SimpleStringList indexNames;
SimpleStringList functionNames; SimpleStringList functionNames;
SimpleStringList schemaNames; SimpleStringList schemaNames;
SimpleStringList schemaExcludeNames;
SimpleStringList triggerNames; SimpleStringList triggerNames;
SimpleStringList tableNames; SimpleStringList tableNames;
......
...@@ -2751,6 +2751,11 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt) ...@@ -2751,6 +2751,11 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
return 0; return 0;
} }
if (ropt->schemaExcludeNames.head != NULL
&& te->namespace
&& simple_string_list_member(&ropt->schemaExcludeNames, te->namespace))
return 0;
if (ropt->selTypes) if (ropt->selTypes)
{ {
if (strcmp(te->desc, "TABLE") == 0 || if (strcmp(te->desc, "TABLE") == 0 ||
......
...@@ -85,6 +85,7 @@ main(int argc, char **argv) ...@@ -85,6 +85,7 @@ main(int argc, char **argv)
{"data-only", 0, NULL, 'a'}, {"data-only", 0, NULL, 'a'},
{"dbname", 1, NULL, 'd'}, {"dbname", 1, NULL, 'd'},
{"exit-on-error", 0, NULL, 'e'}, {"exit-on-error", 0, NULL, 'e'},
{"exclude-schema", 1, NULL, 'N'},
{"file", 1, NULL, 'f'}, {"file", 1, NULL, 'f'},
{"format", 1, NULL, 'F'}, {"format", 1, NULL, 'F'},
{"function", 1, NULL, 'P'}, {"function", 1, NULL, 'P'},
...@@ -148,7 +149,7 @@ main(int argc, char **argv) ...@@ -148,7 +149,7 @@ main(int argc, char **argv)
} }
} }
while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:Op:P:RsS:t:T:U:vwWx1", while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
cmdopts, NULL)) != -1) cmdopts, NULL)) != -1)
{ {
switch (c) switch (c)
...@@ -196,6 +197,10 @@ main(int argc, char **argv) ...@@ -196,6 +197,10 @@ main(int argc, char **argv)
simple_string_list_append(&opts->schemaNames, optarg); simple_string_list_append(&opts->schemaNames, optarg);
break; break;
case 'N': /* Do not dump data for this schema */
simple_string_list_append(&opts->schemaExcludeNames, optarg);
break;
case 'O': case 'O':
opts->noOwner = 1; opts->noOwner = 1;
break; break;
...@@ -456,6 +461,7 @@ usage(const char *progname) ...@@ -456,6 +461,7 @@ usage(const char *progname)
printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n" printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
" selecting/ordering output\n")); " selecting/ordering output\n"));
printf(_(" -n, --schema=NAME restore only objects in this schema\n")); printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
printf(_(" -N, --exclude-schema=NAME do not restore 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) restore named function\n")); printf(_(" -P, --function=NAME(args) restore named function\n"));
printf(_(" -s, --schema-only restore only the schema, no data\n")); printf(_(" -s, --schema-only restore only the schema, no data\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