Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * pg_restore.c
4 : * pg_restore is an utility extracting postgres database definitions
5 : * from a backup archive created by pg_dump using the archiver
6 : * interface.
7 : *
8 : * pg_restore will read the backup archive and
9 : * dump out a script that reproduces
10 : * the schema of the database in terms of
11 : * user-defined types
12 : * user-defined functions
13 : * tables
14 : * indexes
15 : * aggregates
16 : * operators
17 : * ACL - grant/revoke
18 : *
19 : * the output script is SQL that is understood by PostgreSQL
20 : *
21 : * Basic process in a restore operation is:
22 : *
23 : * Open the Archive and read the TOC.
24 : * Set flags in TOC entries, and *maybe* reorder them.
25 : * Generate script to stdout
26 : * Exit
27 : *
28 : * Copyright (c) 2000, Philip Warner
29 : * Rights are granted to use this software in any way so long
30 : * as this notice is not removed.
31 : *
32 : * The author is not responsible for loss or damages that may
33 : * result from its use.
34 : *
35 : *
36 : * IDENTIFICATION
37 : * src/bin/pg_dump/pg_restore.c
38 : *
39 : *-------------------------------------------------------------------------
40 : */
41 : #include "postgres_fe.h"
42 :
43 : #include <ctype.h>
44 : #ifdef HAVE_TERMIOS_H
45 : #include <termios.h>
46 : #endif
47 :
48 : #include "fe_utils/option_utils.h"
49 : #include "filter.h"
50 : #include "getopt_long.h"
51 : #include "parallel.h"
52 : #include "pg_backup_utils.h"
53 :
54 : static void usage(const char *progname);
55 : static void read_restore_filters(const char *filename, RestoreOptions *opts);
56 :
57 : int
58 170 : main(int argc, char **argv)
59 : {
60 : RestoreOptions *opts;
61 : int c;
62 : int exit_code;
63 170 : int numWorkers = 1;
64 : Archive *AH;
65 : char *inputFileSpec;
66 170 : bool data_only = false;
67 170 : bool schema_only = false;
68 : static int disable_triggers = 0;
69 : static int enable_row_security = 0;
70 : static int if_exists = 0;
71 : static int no_data_for_failed_tables = 0;
72 : static int outputNoTableAm = 0;
73 : static int outputNoTablespaces = 0;
74 : static int use_setsessauth = 0;
75 : static int no_comments = 0;
76 : static int no_data = 0;
77 : static int no_policies = 0;
78 : static int no_publications = 0;
79 : static int no_schema = 0;
80 : static int no_security_labels = 0;
81 : static int no_statistics = 0;
82 : static int no_subscriptions = 0;
83 : static int strict_names = 0;
84 : static int statistics_only = 0;
85 : static int with_data = 0;
86 : static int with_schema = 0;
87 : static int with_statistics = 0;
88 :
89 170 : struct option cmdopts[] = {
90 : {"clean", 0, NULL, 'c'},
91 : {"create", 0, NULL, 'C'},
92 : {"data-only", 0, NULL, 'a'},
93 : {"dbname", 1, NULL, 'd'},
94 : {"exit-on-error", 0, NULL, 'e'},
95 : {"exclude-schema", 1, NULL, 'N'},
96 : {"file", 1, NULL, 'f'},
97 : {"format", 1, NULL, 'F'},
98 : {"function", 1, NULL, 'P'},
99 : {"host", 1, NULL, 'h'},
100 : {"index", 1, NULL, 'I'},
101 : {"jobs", 1, NULL, 'j'},
102 : {"list", 0, NULL, 'l'},
103 : {"no-privileges", 0, NULL, 'x'},
104 : {"no-acl", 0, NULL, 'x'},
105 : {"no-owner", 0, NULL, 'O'},
106 : {"no-reconnect", 0, NULL, 'R'},
107 : {"port", 1, NULL, 'p'},
108 : {"no-password", 0, NULL, 'w'},
109 : {"password", 0, NULL, 'W'},
110 : {"schema", 1, NULL, 'n'},
111 : {"schema-only", 0, NULL, 's'},
112 : {"superuser", 1, NULL, 'S'},
113 : {"table", 1, NULL, 't'},
114 : {"trigger", 1, NULL, 'T'},
115 : {"use-list", 1, NULL, 'L'},
116 : {"username", 1, NULL, 'U'},
117 : {"verbose", 0, NULL, 'v'},
118 : {"single-transaction", 0, NULL, '1'},
119 :
120 : /*
121 : * the following options don't have an equivalent short option letter
122 : */
123 : {"disable-triggers", no_argument, &disable_triggers, 1},
124 : {"enable-row-security", no_argument, &enable_row_security, 1},
125 : {"if-exists", no_argument, &if_exists, 1},
126 : {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
127 : {"no-table-access-method", no_argument, &outputNoTableAm, 1},
128 : {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
129 : {"role", required_argument, NULL, 2},
130 : {"section", required_argument, NULL, 3},
131 : {"strict-names", no_argument, &strict_names, 1},
132 : {"transaction-size", required_argument, NULL, 5},
133 : {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
134 : {"no-comments", no_argument, &no_comments, 1},
135 : {"no-data", no_argument, &no_data, 1},
136 : {"no-policies", no_argument, &no_policies, 1},
137 : {"no-publications", no_argument, &no_publications, 1},
138 : {"no-schema", no_argument, &no_schema, 1},
139 : {"no-security-labels", no_argument, &no_security_labels, 1},
140 : {"no-subscriptions", no_argument, &no_subscriptions, 1},
141 : {"no-statistics", no_argument, &no_statistics, 1},
142 : {"with-data", no_argument, &with_data, 1},
143 : {"with-schema", no_argument, &with_schema, 1},
144 : {"with-statistics", no_argument, &with_statistics, 1},
145 : {"statistics-only", no_argument, &statistics_only, 1},
146 : {"filter", required_argument, NULL, 4},
147 :
148 : {NULL, 0, NULL, 0}
149 : };
150 :
151 170 : pg_logging_init(argv[0]);
152 170 : pg_logging_set_level(PG_LOG_WARNING);
153 170 : set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
154 :
155 170 : init_parallel_dump_utils();
156 :
157 170 : opts = NewRestoreOptions();
158 :
159 170 : progname = get_progname(argv[0]);
160 :
161 170 : if (argc > 1)
162 : {
163 168 : if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
164 : {
165 2 : usage(progname);
166 2 : exit_nicely(0);
167 : }
168 166 : if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
169 : {
170 34 : puts("pg_restore (PostgreSQL) " PG_VERSION);
171 34 : exit_nicely(0);
172 : }
173 : }
174 :
175 730 : while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
176 : cmdopts, NULL)) != -1)
177 : {
178 608 : switch (c)
179 : {
180 4 : case 'a': /* Dump data only */
181 4 : data_only = true;
182 4 : break;
183 34 : case 'c': /* clean (i.e., drop) schema prior to create */
184 34 : opts->dropSchema = 1;
185 34 : break;
186 52 : case 'C':
187 52 : opts->createDB = 1;
188 52 : break;
189 58 : case 'd':
190 58 : opts->cparams.dbname = pg_strdup(optarg);
191 58 : break;
192 48 : case 'e':
193 48 : opts->exit_on_error = true;
194 48 : break;
195 62 : case 'f': /* output file name */
196 62 : opts->filename = pg_strdup(optarg);
197 62 : break;
198 22 : case 'F':
199 22 : if (strlen(optarg) != 0)
200 22 : opts->formatName = pg_strdup(optarg);
201 22 : break;
202 48 : case 'h':
203 48 : if (strlen(optarg) != 0)
204 48 : opts->cparams.pghost = pg_strdup(optarg);
205 48 : break;
206 :
207 16 : case 'j': /* number of restore jobs */
208 16 : if (!option_parse_int(optarg, "-j/--jobs", 1,
209 : PG_MAX_JOBS,
210 : &numWorkers))
211 2 : exit(1);
212 14 : break;
213 :
214 8 : case 'l': /* Dump the TOC summary */
215 8 : opts->tocSummary = 1;
216 8 : break;
217 :
218 0 : case 'L': /* input TOC summary file name */
219 0 : opts->tocFile = pg_strdup(optarg);
220 0 : break;
221 :
222 0 : case 'n': /* Dump data for this schema only */
223 0 : simple_string_list_append(&opts->schemaNames, optarg);
224 0 : break;
225 :
226 0 : case 'N': /* Do not dump data for this schema */
227 0 : simple_string_list_append(&opts->schemaExcludeNames, optarg);
228 0 : break;
229 :
230 0 : case 'O':
231 0 : opts->noOwner = 1;
232 0 : break;
233 :
234 68 : case 'p':
235 68 : if (strlen(optarg) != 0)
236 68 : opts->cparams.pgport = pg_strdup(optarg);
237 68 : break;
238 0 : case 'R':
239 : /* no-op, still accepted for backwards compatibility */
240 0 : break;
241 0 : case 'P': /* Function */
242 0 : opts->selTypes = 1;
243 0 : opts->selFunction = 1;
244 0 : simple_string_list_append(&opts->functionNames, optarg);
245 0 : break;
246 0 : case 'I': /* Index */
247 0 : opts->selTypes = 1;
248 0 : opts->selIndex = 1;
249 0 : simple_string_list_append(&opts->indexNames, optarg);
250 0 : break;
251 0 : case 'T': /* Trigger */
252 0 : opts->selTypes = 1;
253 0 : opts->selTrigger = 1;
254 0 : simple_string_list_append(&opts->triggerNames, optarg);
255 0 : break;
256 2 : case 's': /* dump schema only */
257 2 : schema_only = true;
258 2 : break;
259 0 : case 'S': /* Superuser username */
260 0 : if (strlen(optarg) != 0)
261 0 : opts->superuser = pg_strdup(optarg);
262 0 : break;
263 0 : case 't': /* Dump specified table(s) only */
264 0 : opts->selTypes = 1;
265 0 : opts->selTable = 1;
266 0 : simple_string_list_append(&opts->tableNames, optarg);
267 0 : break;
268 :
269 52 : case 'U':
270 52 : opts->cparams.username = pg_strdup(optarg);
271 52 : break;
272 :
273 58 : case 'v': /* verbose */
274 58 : opts->verbose = 1;
275 58 : pg_logging_increase_verbosity();
276 58 : break;
277 :
278 0 : case 'w':
279 0 : opts->cparams.promptPassword = TRI_NO;
280 0 : break;
281 :
282 0 : case 'W':
283 0 : opts->cparams.promptPassword = TRI_YES;
284 0 : break;
285 :
286 0 : case 'x': /* skip ACL dump */
287 0 : opts->aclsSkip = 1;
288 0 : break;
289 :
290 4 : case '1': /* Restore data in a single transaction */
291 4 : opts->single_txn = true;
292 4 : opts->exit_on_error = true;
293 4 : break;
294 :
295 2 : case 0:
296 :
297 : /*
298 : * This covers the long options without a short equivalent.
299 : */
300 2 : break;
301 :
302 0 : case 2: /* SET ROLE */
303 0 : opts->use_role = pg_strdup(optarg);
304 0 : break;
305 :
306 0 : case 3: /* section */
307 0 : set_dump_section(optarg, &(opts->dumpSections));
308 0 : break;
309 :
310 20 : case 4: /* filter */
311 20 : read_restore_filters(optarg, opts);
312 12 : break;
313 :
314 48 : case 5: /* transaction-size */
315 48 : if (!option_parse_int(optarg, "--transaction-size",
316 : 1, INT_MAX,
317 : &opts->txn_size))
318 0 : exit(1);
319 48 : opts->exit_on_error = true;
320 48 : break;
321 :
322 2 : default:
323 : /* getopt_long already emitted a complaint */
324 2 : pg_log_error_hint("Try \"%s --help\" for more information.", progname);
325 2 : exit_nicely(1);
326 : }
327 : }
328 :
329 : /* Get file name from command line */
330 122 : if (optind < argc)
331 106 : inputFileSpec = argv[optind++];
332 : else
333 16 : inputFileSpec = NULL;
334 :
335 : /* Complain if any arguments remain */
336 122 : if (optind < argc)
337 : {
338 2 : pg_log_error("too many command-line arguments (first is \"%s\")",
339 : argv[optind]);
340 2 : pg_log_error_hint("Try \"%s --help\" for more information.", progname);
341 2 : exit_nicely(1);
342 : }
343 :
344 : /* Complain if neither -f nor -d was specified (except if dumping TOC) */
345 120 : if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary)
346 2 : pg_fatal("one of -d/--dbname and -f/--file must be specified");
347 :
348 : /* Should get at most one of -d and -f, else user is confused */
349 118 : if (opts->cparams.dbname)
350 : {
351 58 : if (opts->filename)
352 : {
353 2 : pg_log_error("options -d/--dbname and -f/--file cannot be used together");
354 2 : pg_log_error_hint("Try \"%s --help\" for more information.", progname);
355 2 : exit_nicely(1);
356 : }
357 56 : opts->useDB = 1;
358 : }
359 :
360 : /* reject conflicting "-only" options */
361 116 : if (data_only && schema_only)
362 2 : pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together");
363 114 : if (schema_only && statistics_only)
364 0 : pg_fatal("options -s/--schema-only and --statistics-only cannot be used together");
365 114 : if (data_only && statistics_only)
366 0 : pg_fatal("options -a/--data-only and --statistics-only cannot be used together");
367 :
368 : /* reject conflicting "-only" and "no-" options */
369 114 : if (data_only && no_data)
370 0 : pg_fatal("options -a/--data-only and --no-data cannot be used together");
371 114 : if (schema_only && no_schema)
372 0 : pg_fatal("options -s/--schema-only and --no-schema cannot be used together");
373 114 : if (statistics_only && no_statistics)
374 0 : pg_fatal("options --statistics-only and --no-statistics cannot be used together");
375 :
376 : /* reject conflicting "with-" and "no-" options */
377 114 : if (with_data && no_data)
378 0 : pg_fatal("options --with-data and --no-data cannot be used together");
379 114 : if (with_schema && no_schema)
380 0 : pg_fatal("options --with-schema and --no-schema cannot be used together");
381 114 : if (with_statistics && no_statistics)
382 0 : pg_fatal("options --with-statistics and --no-statistics cannot be used together");
383 :
384 114 : if (data_only && opts->dropSchema)
385 2 : pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
386 :
387 112 : if (opts->single_txn && opts->txn_size > 0)
388 0 : pg_fatal("options -1/--single-transaction and --transaction-size cannot be used together");
389 :
390 : /*
391 : * -C is not compatible with -1, because we can't create a database inside
392 : * a transaction block.
393 : */
394 112 : if (opts->createDB && opts->single_txn)
395 2 : pg_fatal("options -C/--create and -1/--single-transaction cannot be used together");
396 :
397 : /* Can't do single-txn mode with multiple connections */
398 110 : if (opts->single_txn && numWorkers > 1)
399 2 : pg_fatal("cannot specify both --single-transaction and multiple jobs");
400 :
401 : /*
402 : * Set derivative flags. An "-only" option may be overridden by an
403 : * explicit "with-" option; e.g. "--schema-only --with-statistics" will
404 : * include schema and statistics. Other ambiguous or nonsensical
405 : * combinations, e.g. "--schema-only --no-schema", will have already
406 : * caused an error in one of the checks above.
407 : */
408 108 : opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) ||
409 216 : (data_only || with_data)) && !no_data;
410 108 : opts->dumpSchema = ((opts->dumpSchema && !data_only && !statistics_only) ||
411 216 : (schema_only || with_schema)) && !no_schema;
412 108 : opts->dumpStatistics = ((opts->dumpStatistics && !schema_only && !data_only) ||
413 216 : (statistics_only || with_statistics)) && !no_statistics;
414 :
415 108 : opts->disable_triggers = disable_triggers;
416 108 : opts->enable_row_security = enable_row_security;
417 108 : opts->noDataForFailedTables = no_data_for_failed_tables;
418 108 : opts->noTableAm = outputNoTableAm;
419 108 : opts->noTablespace = outputNoTablespaces;
420 108 : opts->use_setsessauth = use_setsessauth;
421 108 : opts->no_comments = no_comments;
422 108 : opts->no_policies = no_policies;
423 108 : opts->no_publications = no_publications;
424 108 : opts->no_security_labels = no_security_labels;
425 108 : opts->no_subscriptions = no_subscriptions;
426 :
427 108 : if (if_exists && !opts->dropSchema)
428 2 : pg_fatal("option --if-exists requires option -c/--clean");
429 106 : opts->if_exists = if_exists;
430 106 : opts->strict_names = strict_names;
431 :
432 106 : if (opts->formatName)
433 : {
434 44 : if (pg_strcasecmp(opts->formatName, "c") == 0 ||
435 22 : pg_strcasecmp(opts->formatName, "custom") == 0)
436 16 : opts->format = archCustom;
437 12 : else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
438 6 : pg_strcasecmp(opts->formatName, "directory") == 0)
439 2 : opts->format = archDirectory;
440 8 : else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
441 4 : pg_strcasecmp(opts->formatName, "tar") == 0)
442 2 : opts->format = archTar;
443 4 : else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
444 2 : pg_strcasecmp(opts->formatName, "plain") == 0)
445 : {
446 : /* recognize this for consistency with pg_dump */
447 0 : pg_fatal("archive format \"%s\" is not supported; please use psql",
448 : opts->formatName);
449 : }
450 : else
451 2 : pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
452 : opts->formatName);
453 : }
454 :
455 104 : AH = OpenArchive(inputFileSpec, opts->format);
456 :
457 104 : SetArchiveOptions(AH, NULL, opts);
458 :
459 : /*
460 : * We don't have a connection yet but that doesn't matter. The connection
461 : * is initialized to NULL and if we terminate through exit_nicely() while
462 : * it's still NULL, the cleanup function will just be a no-op.
463 : */
464 104 : on_exit_close_archive(AH);
465 :
466 : /* Let the archiver know how noisy to be */
467 104 : AH->verbose = opts->verbose;
468 :
469 : /*
470 : * Whether to keep submitting sql commands as "pg_restore ... | psql ... "
471 : */
472 104 : AH->exit_on_error = opts->exit_on_error;
473 :
474 104 : if (opts->tocFile)
475 0 : SortTocFromFile(AH);
476 :
477 104 : AH->numWorkers = numWorkers;
478 :
479 104 : if (opts->tocSummary)
480 8 : PrintTOCSummary(AH);
481 : else
482 : {
483 96 : ProcessArchiveRestoreOptions(AH);
484 96 : RestoreArchive(AH);
485 : }
486 :
487 : /* done, print a summary of ignored errors */
488 104 : if (AH->n_errors)
489 0 : pg_log_warning("errors ignored on restore: %d", AH->n_errors);
490 :
491 : /* AH may be freed in CloseArchive? */
492 104 : exit_code = AH->n_errors ? 1 : 0;
493 :
494 104 : CloseArchive(AH);
495 :
496 104 : return exit_code;
497 : }
498 :
499 : static void
500 2 : usage(const char *progname)
501 : {
502 2 : printf(_("%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"), progname);
503 2 : printf(_("Usage:\n"));
504 2 : printf(_(" %s [OPTION]... [FILE]\n"), progname);
505 :
506 2 : printf(_("\nGeneral options:\n"));
507 2 : printf(_(" -d, --dbname=NAME connect to database name\n"));
508 2 : printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
509 2 : printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
510 2 : printf(_(" -l, --list print summarized TOC of the archive\n"));
511 2 : printf(_(" -v, --verbose verbose mode\n"));
512 2 : printf(_(" -V, --version output version information, then exit\n"));
513 2 : printf(_(" -?, --help show this help, then exit\n"));
514 :
515 2 : printf(_("\nOptions controlling the restore:\n"));
516 2 : printf(_(" -a, --data-only restore only the data, no schema\n"));
517 2 : printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
518 2 : printf(_(" -C, --create create the target database\n"));
519 2 : printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
520 2 : printf(_(" -I, --index=NAME restore named index\n"));
521 2 : printf(_(" -j, --jobs=NUM use this many parallel jobs to restore\n"));
522 2 : printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
523 : " selecting/ordering output\n"));
524 2 : printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
525 2 : printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
526 2 : printf(_(" -O, --no-owner skip restoration of object ownership\n"));
527 2 : printf(_(" -P, --function=NAME(args) restore named function\n"));
528 2 : printf(_(" -s, --schema-only restore only the schema, no data\n"));
529 2 : printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
530 2 : printf(_(" -t, --table=NAME restore named relation (table, view, etc.)\n"));
531 2 : printf(_(" -T, --trigger=NAME restore named trigger\n"));
532 2 : printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
533 2 : printf(_(" -1, --single-transaction restore as a single transaction\n"));
534 2 : printf(_(" --disable-triggers disable triggers during data-only restore\n"));
535 2 : printf(_(" --enable-row-security enable row security\n"));
536 2 : printf(_(" --filter=FILENAME restore or skip objects based on expressions\n"
537 : " in FILENAME\n"));
538 2 : printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
539 2 : printf(_(" --no-comments do not restore comment commands\n"));
540 2 : printf(_(" --no-data do not restore data\n"));
541 2 : printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
542 : " created\n"));
543 2 : printf(_(" --no-policies do not restore row security policies\n"));
544 2 : printf(_(" --no-publications do not restore publications\n"));
545 2 : printf(_(" --no-schema do not restore schema\n"));
546 2 : printf(_(" --no-security-labels do not restore security labels\n"));
547 2 : printf(_(" --no-statistics do not restore statistics\n"));
548 2 : printf(_(" --no-subscriptions do not restore subscriptions\n"));
549 2 : printf(_(" --no-table-access-method do not restore table access methods\n"));
550 2 : printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
551 2 : printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
552 2 : printf(_(" --statistics-only restore only the statistics, not schema or data\n"));
553 2 : printf(_(" --strict-names require table and/or schema include patterns to\n"
554 : " match at least one entity each\n"));
555 2 : printf(_(" --transaction-size=N commit after every N objects\n"));
556 2 : printf(_(" --use-set-session-authorization\n"
557 : " use SET SESSION AUTHORIZATION commands instead of\n"
558 : " ALTER OWNER commands to set ownership\n"));
559 2 : printf(_(" --with-data dump the data\n"));
560 2 : printf(_(" --with-schema dump the schema\n"));
561 2 : printf(_(" --with-statistics dump the statistics\n"));
562 :
563 2 : printf(_("\nConnection options:\n"));
564 2 : printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
565 2 : printf(_(" -p, --port=PORT database server port number\n"));
566 2 : printf(_(" -U, --username=NAME connect as specified database user\n"));
567 2 : printf(_(" -w, --no-password never prompt for password\n"));
568 2 : printf(_(" -W, --password force password prompt (should happen automatically)\n"));
569 2 : printf(_(" --role=ROLENAME do SET ROLE before restore\n"));
570 :
571 2 : printf(_("\n"
572 : "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
573 : "multiple times to select multiple objects.\n"));
574 2 : printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
575 2 : printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
576 2 : printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
577 2 : }
578 :
579 : /*
580 : * read_restore_filters - retrieve object identifier patterns from file
581 : *
582 : * Parse the specified filter file for include and exclude patterns, and add
583 : * them to the relevant lists. If the filename is "-" then filters will be
584 : * read from STDIN rather than a file.
585 : */
586 : static void
587 20 : read_restore_filters(const char *filename, RestoreOptions *opts)
588 : {
589 : FilterStateData fstate;
590 : char *objname;
591 : FilterCommandType comtype;
592 : FilterObjectType objtype;
593 :
594 20 : filter_init(&fstate, filename, exit_nicely);
595 :
596 34 : while (filter_read_item(&fstate, &objname, &comtype, &objtype))
597 : {
598 22 : if (comtype == FILTER_COMMAND_TYPE_INCLUDE)
599 : {
600 16 : switch (objtype)
601 : {
602 0 : case FILTER_OBJECT_TYPE_NONE:
603 0 : break;
604 4 : case FILTER_OBJECT_TYPE_TABLE_DATA:
605 : case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN:
606 : case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN:
607 : case FILTER_OBJECT_TYPE_DATABASE:
608 : case FILTER_OBJECT_TYPE_EXTENSION:
609 : case FILTER_OBJECT_TYPE_FOREIGN_DATA:
610 4 : pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
611 : "include",
612 : filter_object_type_name(objtype));
613 4 : exit_nicely(1);
614 :
615 4 : case FILTER_OBJECT_TYPE_FUNCTION:
616 4 : opts->selTypes = 1;
617 4 : opts->selFunction = 1;
618 4 : simple_string_list_append(&opts->functionNames, objname);
619 4 : break;
620 2 : case FILTER_OBJECT_TYPE_INDEX:
621 2 : opts->selTypes = 1;
622 2 : opts->selIndex = 1;
623 2 : simple_string_list_append(&opts->indexNames, objname);
624 2 : break;
625 2 : case FILTER_OBJECT_TYPE_SCHEMA:
626 2 : simple_string_list_append(&opts->schemaNames, objname);
627 2 : break;
628 2 : case FILTER_OBJECT_TYPE_TABLE:
629 2 : opts->selTypes = 1;
630 2 : opts->selTable = 1;
631 2 : simple_string_list_append(&opts->tableNames, objname);
632 2 : break;
633 2 : case FILTER_OBJECT_TYPE_TRIGGER:
634 2 : opts->selTypes = 1;
635 2 : opts->selTrigger = 1;
636 2 : simple_string_list_append(&opts->triggerNames, objname);
637 2 : break;
638 : }
639 12 : }
640 6 : else if (comtype == FILTER_COMMAND_TYPE_EXCLUDE)
641 : {
642 6 : switch (objtype)
643 : {
644 0 : case FILTER_OBJECT_TYPE_NONE:
645 0 : break;
646 4 : case FILTER_OBJECT_TYPE_TABLE_DATA:
647 : case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN:
648 : case FILTER_OBJECT_TYPE_DATABASE:
649 : case FILTER_OBJECT_TYPE_EXTENSION:
650 : case FILTER_OBJECT_TYPE_FOREIGN_DATA:
651 : case FILTER_OBJECT_TYPE_FUNCTION:
652 : case FILTER_OBJECT_TYPE_INDEX:
653 : case FILTER_OBJECT_TYPE_TABLE:
654 : case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN:
655 : case FILTER_OBJECT_TYPE_TRIGGER:
656 4 : pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
657 : "exclude",
658 : filter_object_type_name(objtype));
659 4 : exit_nicely(1);
660 :
661 2 : case FILTER_OBJECT_TYPE_SCHEMA:
662 2 : simple_string_list_append(&opts->schemaExcludeNames, objname);
663 2 : break;
664 : }
665 2 : }
666 : else
667 : {
668 : Assert(comtype == FILTER_COMMAND_TYPE_NONE);
669 : Assert(objtype == FILTER_OBJECT_TYPE_NONE);
670 : }
671 :
672 14 : if (objname)
673 14 : free(objname);
674 : }
675 :
676 12 : filter_free(&fstate);
677 12 : }
|