diff options
Diffstat (limited to 'src/bin/pg_dump/pg_dumpall.c')
-rw-r--r-- | src/bin/pg_dump/pg_dumpall.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index e2a9733d348..1b974cf7e8e 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -26,6 +26,7 @@ #include "common/string.h" #include "dumputils.h" #include "fe_utils/string_utils.h" +#include "filter.h" #include "getopt_long.h" #include "pg_backup.h" @@ -81,6 +82,7 @@ static PGresult *executeQuery(PGconn *conn, const char *query); static void executeCommand(PGconn *conn, const char *query); static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names); +static void read_dumpall_filters(const char *filename, SimpleStringList *patterns); static char pg_dump_bin[MAXPGPATH]; static const char *progname; @@ -177,6 +179,7 @@ main(int argc, char *argv[]) {"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1}, {"on-conflict-do-nothing", no_argument, &on_conflict_do_nothing, 1}, {"rows-per-insert", required_argument, NULL, 7}, + {"filter", required_argument, NULL, 8}, {NULL, 0, NULL, 0} }; @@ -360,6 +363,10 @@ main(int argc, char *argv[]) appendShellString(pgdumpopts, optarg); break; + case 8: + read_dumpall_filters(optarg, &database_exclude_patterns); + break; + default: /* getopt_long already emitted a complaint */ pg_log_error_hint("Try \"%s --help\" for more information.", progname); @@ -653,6 +660,7 @@ help(void) printf(_(" --disable-triggers disable triggers during data-only restore\n")); printf(_(" --exclude-database=PATTERN exclude databases whose name matches PATTERN\n")); printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n")); + printf(_(" --filter=FILENAME exclude databases specified in FILENAME\n")); printf(_(" --if-exists use IF EXISTS when dropping objects\n")); printf(_(" --inserts dump data as INSERT commands, rather than COPY\n")); printf(_(" --load-via-partition-root load partitions via the root table\n")); @@ -1937,3 +1945,62 @@ hash_string_pointer(char *s) return hash_bytes(ss, strlen(s)); } + +/* + * read_dumpall_filters - retrieve database identifier patterns from file + * + * Parse the specified filter file for include and exclude patterns, and add + * them to the relevant lists. If the filename is "-" then filters will be + * read from STDIN rather than a file. + * + * At the moment, the only allowed filter is for database exclusion. + */ +static void +read_dumpall_filters(const char *filename, SimpleStringList *pattern) +{ + FilterStateData fstate; + char *objname; + FilterCommandType comtype; + FilterObjectType objtype; + + filter_init(&fstate, filename, exit); + + while (filter_read_item(&fstate, &objname, &comtype, &objtype)) + { + if (comtype == FILTER_COMMAND_TYPE_INCLUDE) + { + pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed."), + "include", + filter_object_type_name(objtype)); + exit_nicely(1); + } + + switch (objtype) + { + case FILTER_OBJECT_TYPE_NONE: + break; + case FILTER_OBJECT_TYPE_FUNCTION: + case FILTER_OBJECT_TYPE_INDEX: + case FILTER_OBJECT_TYPE_TABLE_DATA: + case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN: + case FILTER_OBJECT_TYPE_TRIGGER: + case FILTER_OBJECT_TYPE_EXTENSION: + case FILTER_OBJECT_TYPE_FOREIGN_DATA: + case FILTER_OBJECT_TYPE_SCHEMA: + case FILTER_OBJECT_TYPE_TABLE: + case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN: + pg_log_filter_error(&fstate, _("unsupported filter object.")); + exit_nicely(1); + break; + + case FILTER_OBJECT_TYPE_DATABASE: + simple_string_list_append(pattern, objname); + break; + } + + if (objname) + free(objname); + } + + filter_free(&fstate); +} |