diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 2f0807e912..5e39268d51 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -725,6 +725,16 @@ PostgreSQL documentation + + + + + This option allows to specify file with schemas that will not be + dumped. Any row of is one schema's name. + + + + @@ -743,6 +753,24 @@ PostgreSQL documentation + + + + + Do not dump data of tables spefified in file. + + + + + + + + + Do not dump tables spefified in file. + + + + @@ -795,6 +823,33 @@ PostgreSQL documentation + + + + + Include data of foreign servers specified in file. + + + + + + + + + Dump schema(s) specified in file. + + + + + + + + + Dump table(s) specified in file. + + + + diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index dfe43968b8..db9fb10f68 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -290,6 +290,7 @@ static void appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions, static char *get_synchronized_snapshot(Archive *fout); static void setupDumpWorker(Archive *AHX); static TableInfo *getRootTableInfo(TableInfo *tbinfo); +static bool read_options_from_file(SimpleStringList *slist, char *filename); int @@ -362,8 +363,13 @@ main(int argc, char **argv) {"disable-dollar-quoting", no_argument, &dopt.disable_dollar_quoting, 1}, {"disable-triggers", no_argument, &dopt.disable_triggers, 1}, {"enable-row-security", no_argument, &dopt.enable_row_security, 1}, + {"exclude-schemas-file", required_argument, NULL, 12}, {"exclude-table-data", required_argument, NULL, 4}, + {"exclude-tables-data-file", required_argument, NULL, 14}, + {"exclude-tables-file", required_argument, NULL, 13}, {"extra-float-digits", required_argument, NULL, 8}, + {"include-schemas-file", required_argument, NULL, 15}, + {"include-tables-file", required_argument, NULL, 16}, {"if-exists", no_argument, &dopt.if_exists, 1}, {"inserts", no_argument, NULL, 9}, {"lock-wait-timeout", required_argument, NULL, 2}, @@ -386,6 +392,7 @@ main(int argc, char **argv) {"on-conflict-do-nothing", no_argument, &dopt.do_nothing, 1}, {"rows-per-insert", required_argument, NULL, 10}, {"include-foreign-data", required_argument, NULL, 11}, + {"include-foreign-data-file", required_argument, NULL, 17}, {NULL, 0, NULL, 0} }; @@ -603,6 +610,32 @@ main(int argc, char **argv) optarg); break; + case 12: /* read exclude schama names from file */ + (void) read_options_from_file(&schema_exclude_patterns, optarg); + break; + + case 13: /* read exclude table names from file */ + (void) read_options_from_file(&table_exclude_patterns, optarg); + break; + + case 14: /* read exclude table data names from file */ + (void) read_options_from_file(&tabledata_exclude_patterns, optarg); + break; + + case 15: /* read table names from file */ + if (read_options_from_file(&schema_include_patterns, optarg)) + dopt.include_everything = false; + break; + + case 16: /* read table names from file */ + if (read_options_from_file(&table_include_patterns, optarg)) + dopt.include_everything = false; + break; + + case 17: /* read exclude table data names from file */ + (void) read_options_from_file(&foreign_servers_include_patterns, optarg); + break; + default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit_nicely(1); @@ -1020,12 +1053,24 @@ help(const char *progname) printf(_(" --disable-triggers disable triggers during data-only restore\n")); printf(_(" --enable-row-security enable row security (dump only content user has\n" " access to)\n")); + printf(_(" --exclude-schemas-file=FILENAME\n" + " do NOT dump schema specified in file\n")); printf(_(" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n")); + printf(_(" --exclude-tables-data-file=FILENAME\n" + " do NOT dump data for tables specified in file\n")); + printf(_(" --exclude-tables-file=FILENAME\n" + " do NOT dump tables specified in file\n")); printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n")); printf(_(" --if-exists use IF EXISTS when dropping objects\n")); printf(_(" --include-foreign-data=PATTERN\n" " include data of foreign tables on foreign\n" " servers matching PATTERN\n")); + printf(_(" --include-foreign-data-file=FILENAME\n" + " include data of foreign servers specified by file\n")); + printf(_(" --include-schemas-file=FILENAME\n" + " dump schema(s) specified in file\n")); + printf(_(" --include-tables-file=FILENAME\n" + " dump table(s) specified in file\n")); printf(_(" --inserts dump data as INSERT commands, rather than COPY\n")); printf(_(" --load-via-partition-root load partitions via the root table\n")); printf(_(" --no-comments do not dump comments\n")); @@ -18647,3 +18692,70 @@ appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions, if (!res) pg_log_warning("could not parse reloptions array"); } + +/* + * Read list of values from file specified by name. Returns true when + * at least one value was read. + */ +static bool +read_options_from_file(SimpleStringList *slist, char *filename) +{ + FILE *f; + char *line; + ssize_t chars; + size_t line_size = 1024; + bool use_stdin = false; + bool result = false; + + /* use "-" as symbol for stdin */ + if (strcmp(filename, "-") != 0) + { + f = fopen(optarg, "r"); + if (!f) + { + fprintf(stderr, + _("%s: could not open the input file \"%s\": %s\n"), + progname, + optarg, + strerror(errno)); + exit_nicely(1); + } + } + else + { + f = stdin; + use_stdin = true; + } + + line = malloc(line_size); + + while ((chars = getline(&line, &line_size, f)) != -1) + { + if (line[chars - 1] == '\n') + line[chars - 1] = '\0'; + + /* ignore empty rows */ + if (*line != '\0') + { + simple_string_list_append(slist, line); + result = true; + } + } + + if (ferror(f)) + { + fprintf(stderr, + _("%s: could not read from file \"%s\": %s\n"), + progname, + use_stdin ? "stdin" : optarg, + strerror(errno)); + exit_nicely(1); + } + + if (!use_stdin) + fclose(f); + + free(line); + + return result; +}