PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_restore.c
Go to the documentation of this file.
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/pg_dumpall 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#include <sys/stat.h>
45#ifdef HAVE_TERMIOS_H
46#include <termios.h>
47#endif
48
49#include "common/string.h"
50#include "connectdb.h"
51#include "dumputils.h"
54#include "filter.h"
55#include "getopt_long.h"
56#include "parallel.h"
57#include "pg_backup_utils.h"
58
59static void usage(const char *progname);
60static void read_restore_filters(const char *filename, RestoreOptions *opts);
61static bool file_exists_in_directory(const char *dir, const char *filename);
63 int numWorkers, bool append_data);
65
66static int restore_all_databases(const char *inputFileSpec,
73
74/*
75 * Stores a database OID and the corresponding name.
76 */
77typedef struct DbOidName
78{
80 char str[FLEXIBLE_ARRAY_MEMBER]; /* null-terminated string here */
82
83
84int
85main(int argc, char **argv)
86{
88 int c;
89 int numWorkers = 1;
90 char *inputFileSpec;
91 bool data_only = false;
92 bool schema_only = false;
93 int n_errors = 0;
94 bool globals_only = false;
96 static int disable_triggers = 0;
97 static int enable_row_security = 0;
98 static int if_exists = 0;
99 static int no_data_for_failed_tables = 0;
100 static int outputNoTableAm = 0;
101 static int outputNoTablespaces = 0;
102 static int use_setsessauth = 0;
103 static int no_comments = 0;
104 static int no_data = 0;
105 static int no_policies = 0;
106 static int no_publications = 0;
107 static int no_schema = 0;
108 static int no_security_labels = 0;
109 static int no_statistics = 0;
110 static int no_subscriptions = 0;
111 static int strict_names = 0;
112 static int statistics_only = 0;
113 static int with_statistics = 0;
114
115 struct option cmdopts[] = {
116 {"clean", 0, NULL, 'c'},
117 {"create", 0, NULL, 'C'},
118 {"data-only", 0, NULL, 'a'},
119 {"globals-only", 0, NULL, 'g'},
120 {"dbname", 1, NULL, 'd'},
121 {"exit-on-error", 0, NULL, 'e'},
122 {"exclude-schema", 1, NULL, 'N'},
123 {"file", 1, NULL, 'f'},
124 {"format", 1, NULL, 'F'},
125 {"function", 1, NULL, 'P'},
126 {"host", 1, NULL, 'h'},
127 {"index", 1, NULL, 'I'},
128 {"jobs", 1, NULL, 'j'},
129 {"list", 0, NULL, 'l'},
130 {"no-privileges", 0, NULL, 'x'},
131 {"no-acl", 0, NULL, 'x'},
132 {"no-owner", 0, NULL, 'O'},
133 {"no-reconnect", 0, NULL, 'R'},
134 {"port", 1, NULL, 'p'},
135 {"no-password", 0, NULL, 'w'},
136 {"password", 0, NULL, 'W'},
137 {"schema", 1, NULL, 'n'},
138 {"schema-only", 0, NULL, 's'},
139 {"superuser", 1, NULL, 'S'},
140 {"table", 1, NULL, 't'},
141 {"trigger", 1, NULL, 'T'},
142 {"use-list", 1, NULL, 'L'},
143 {"username", 1, NULL, 'U'},
144 {"verbose", 0, NULL, 'v'},
145 {"single-transaction", 0, NULL, '1'},
146
147 /*
148 * the following options don't have an equivalent short option letter
149 */
150 {"disable-triggers", no_argument, &disable_triggers, 1},
151 {"enable-row-security", no_argument, &enable_row_security, 1},
152 {"if-exists", no_argument, &if_exists, 1},
153 {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
154 {"no-table-access-method", no_argument, &outputNoTableAm, 1},
155 {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
156 {"role", required_argument, NULL, 2},
157 {"section", required_argument, NULL, 3},
158 {"strict-names", no_argument, &strict_names, 1},
159 {"transaction-size", required_argument, NULL, 5},
160 {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
161 {"no-comments", no_argument, &no_comments, 1},
162 {"no-data", no_argument, &no_data, 1},
163 {"no-policies", no_argument, &no_policies, 1},
164 {"no-publications", no_argument, &no_publications, 1},
165 {"no-schema", no_argument, &no_schema, 1},
166 {"no-security-labels", no_argument, &no_security_labels, 1},
167 {"no-subscriptions", no_argument, &no_subscriptions, 1},
168 {"no-statistics", no_argument, &no_statistics, 1},
169 {"statistics", no_argument, &with_statistics, 1},
170 {"statistics-only", no_argument, &statistics_only, 1},
171 {"filter", required_argument, NULL, 4},
172 {"restrict-key", required_argument, NULL, 6},
173 {"exclude-database", required_argument, NULL, 7},
174
175 {NULL, 0, NULL, 0}
176 };
177
178 pg_logging_init(argv[0]);
180 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
181
183
185
186 progname = get_progname(argv[0]);
187
188 if (argc > 1)
189 {
190 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
191 {
193 exit_nicely(0);
194 }
195 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
196 {
197 puts("pg_restore (PostgreSQL) " PG_VERSION);
198 exit_nicely(0);
199 }
200 }
201
202 while ((c = getopt_long(argc, argv, "acCd:ef:F:gh:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
203 cmdopts, NULL)) != -1)
204 {
205 switch (c)
206 {
207 case 'a': /* Dump data only */
208 data_only = true;
209 break;
210 case 'c': /* clean (i.e., drop) schema prior to create */
211 opts->dropSchema = 1;
212 break;
213 case 'C':
214 opts->createDB = 1;
215 break;
216 case 'd':
217 opts->cparams.dbname = pg_strdup(optarg);
218 break;
219 case 'e':
220 opts->exit_on_error = true;
221 break;
222 case 'f': /* output file name */
223 opts->filename = pg_strdup(optarg);
224 break;
225 case 'F':
226 if (strlen(optarg) != 0)
227 opts->formatName = pg_strdup(optarg);
228 break;
229 case 'g':
230 /* restore only global sql commands. */
231 globals_only = true;
232 break;
233 case 'h':
234 if (strlen(optarg) != 0)
235 opts->cparams.pghost = pg_strdup(optarg);
236 break;
237 case 'j': /* number of restore jobs */
238 if (!option_parse_int(optarg, "-j/--jobs", 1,
240 &numWorkers))
241 exit(1);
242 break;
243
244 case 'l': /* Dump the TOC summary */
245 opts->tocSummary = 1;
246 break;
247
248 case 'L': /* input TOC summary file name */
249 opts->tocFile = pg_strdup(optarg);
250 break;
251
252 case 'n': /* Dump data for this schema only */
253 simple_string_list_append(&opts->schemaNames, optarg);
254 break;
255
256 case 'N': /* Do not dump data for this schema */
257 simple_string_list_append(&opts->schemaExcludeNames, optarg);
258 break;
259
260 case 'O':
261 opts->noOwner = 1;
262 break;
263
264 case 'p':
265 if (strlen(optarg) != 0)
266 opts->cparams.pgport = pg_strdup(optarg);
267 break;
268 case 'R':
269 /* no-op, still accepted for backwards compatibility */
270 break;
271 case 'P': /* Function */
272 opts->selTypes = 1;
273 opts->selFunction = 1;
274 simple_string_list_append(&opts->functionNames, optarg);
275 break;
276 case 'I': /* Index */
277 opts->selTypes = 1;
278 opts->selIndex = 1;
280 break;
281 case 'T': /* Trigger */
282 opts->selTypes = 1;
283 opts->selTrigger = 1;
284 simple_string_list_append(&opts->triggerNames, optarg);
285 break;
286 case 's': /* dump schema only */
287 schema_only = true;
288 break;
289 case 'S': /* Superuser username */
290 if (strlen(optarg) != 0)
291 opts->superuser = pg_strdup(optarg);
292 break;
293 case 't': /* Dump specified table(s) only */
294 opts->selTypes = 1;
295 opts->selTable = 1;
297 break;
298
299 case 'U':
300 opts->cparams.username = pg_strdup(optarg);
301 break;
302
303 case 'v': /* verbose */
304 opts->verbose = 1;
306 break;
307
308 case 'w':
309 opts->cparams.promptPassword = TRI_NO;
310 break;
311
312 case 'W':
313 opts->cparams.promptPassword = TRI_YES;
314 break;
315
316 case 'x': /* skip ACL dump */
317 opts->aclsSkip = 1;
318 break;
319
320 case '1': /* Restore data in a single transaction */
321 opts->single_txn = true;
322 opts->exit_on_error = true;
323 break;
324
325 case 0:
326
327 /*
328 * This covers the long options without a short equivalent.
329 */
330 break;
331
332 case 2: /* SET ROLE */
333 opts->use_role = pg_strdup(optarg);
334 break;
335
336 case 3: /* section */
337 set_dump_section(optarg, &(opts->dumpSections));
338 break;
339
340 case 4: /* filter */
342 break;
343
344 case 5: /* transaction-size */
345 if (!option_parse_int(optarg, "--transaction-size",
346 1, INT_MAX,
347 &opts->txn_size))
348 exit(1);
349 opts->exit_on_error = true;
350 break;
351
352 case 6:
353 opts->restrict_key = pg_strdup(optarg);
354 break;
355
356 case 7: /* database patterns to skip */
358 break;
359
360 default:
361 /* getopt_long already emitted a complaint */
362 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
363 exit_nicely(1);
364 }
365 }
366
367 /* Get file name from command line */
368 if (optind < argc)
369 inputFileSpec = argv[optind++];
370 else
372
373 /* Complain if any arguments remain */
374 if (optind < argc)
375 {
376 pg_log_error("too many command-line arguments (first is \"%s\")",
377 argv[optind]);
378 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
379 exit_nicely(1);
380 }
381
382 /* Complain if neither -f nor -d was specified (except if dumping TOC) */
383 if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary)
384 pg_fatal("one of -d/--dbname and -f/--file must be specified");
385
387 {
388 pg_log_error("option %s cannot be used together with %s",
389 "--exclude-database", "-g/--globals-only");
390 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
391 exit_nicely(1);
392 }
393
394 /* Should get at most one of -d and -f, else user is confused */
395 if (opts->cparams.dbname)
396 {
397 if (opts->filename)
398 {
399 pg_log_error("options %s and %s cannot be used together",
400 "-d/--dbname", "-f/--file");
401 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
402 exit_nicely(1);
403 }
404
405 if (opts->restrict_key)
406 pg_fatal("options %s and %s cannot be used together",
407 "-d/--dbname", "--restrict-key");
408
409 opts->useDB = 1;
410 }
411 else
412 {
413 /*
414 * If you don't provide a restrict key, one will be appointed for you.
415 */
416 if (!opts->restrict_key)
417 opts->restrict_key = generate_restrict_key();
418 if (!opts->restrict_key)
419 pg_fatal("could not generate restrict key");
420 if (!valid_restrict_key(opts->restrict_key))
421 pg_fatal("invalid restrict key");
422 }
423
424 /* reject conflicting "-only" options */
425 if (data_only && schema_only)
426 pg_fatal("options %s and %s cannot be used together",
427 "-s/--schema-only", "-a/--data-only");
429 pg_fatal("options %s and %s cannot be used together",
430 "-s/--schema-only", "--statistics-only");
432 pg_fatal("options %s and %s cannot be used together",
433 "-a/--data-only", "--statistics-only");
434
435 /* reject conflicting "-only" and "no-" options */
436 if (data_only && no_data)
437 pg_fatal("options %s and %s cannot be used together",
438 "-a/--data-only", "--no-data");
439 if (schema_only && no_schema)
440 pg_fatal("options %s and %s cannot be used together",
441 "-s/--schema-only", "--no-schema");
443 pg_fatal("options %s and %s cannot be used together",
444 "--statistics-only", "--no-statistics");
445
446 /* reject conflicting "no-" options */
448 pg_fatal("options %s and %s cannot be used together",
449 "--statistics", "--no-statistics");
450
451 /* reject conflicting "only-" options */
453 pg_fatal("options %s and %s cannot be used together",
454 "-a/--data-only", "--statistics");
456 pg_fatal("options %s and %s cannot be used together",
457 "-s/--schema-only", "--statistics");
458
459 if (data_only && opts->dropSchema)
460 pg_fatal("options %s and %s cannot be used together",
461 "-c/--clean", "-a/--data-only");
462
463 if (opts->single_txn && opts->txn_size > 0)
464 pg_fatal("options %s and %s cannot be used together",
465 "-1/--single-transaction", "--transaction-size");
466
467 if (opts->single_txn && globals_only)
468 pg_fatal("options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
469 "--single-transaction", "-g/--globals-only");
470
471 if (opts->txn_size && globals_only)
472 pg_fatal("options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
473 "--transaction-size", "-g/--globals-only");
474
475 if (opts->exit_on_error && globals_only)
476 pg_fatal("options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
477 "--exit-on-error", "-g/--globals-only");
478
479 if (data_only && globals_only)
480 pg_fatal("options %s and %s cannot be used together",
481 "-a/--data-only", "-g/--globals-only");
483 pg_fatal("options %s and %s cannot be used together",
484 "-s/--schema-only", "-g/--globals-only");
486 pg_fatal("options %s and %s cannot be used together",
487 "--statistics-only", "-g/--globals-only");
489 pg_fatal("options %s and %s cannot be used together",
490 "--statistics", "-g/--globals-only");
491
492 /*
493 * -C is not compatible with -1, because we can't create a database inside
494 * a transaction block.
495 */
496 if (opts->createDB && opts->single_txn)
497 pg_fatal("options %s and %s cannot be used together",
498 "-C/--create", "-1/--single-transaction");
499
500 /* Can't do single-txn mode with multiple connections */
501 if (opts->single_txn && numWorkers > 1)
502 pg_fatal("cannot specify both --single-transaction and multiple jobs");
503
504 /*
505 * Set derivative flags. Ambiguous or nonsensical combinations, e.g.
506 * "--schema-only --no-schema", will have already caused an error in one
507 * of the checks above.
508 */
509 opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) ||
510 data_only) && !no_data;
511 opts->dumpSchema = ((opts->dumpSchema && !data_only && !statistics_only) ||
513 opts->dumpStatistics = ((opts->dumpStatistics && !schema_only && !data_only) ||
515
516 opts->disable_triggers = disable_triggers;
517 opts->enable_row_security = enable_row_security;
518 opts->noDataForFailedTables = no_data_for_failed_tables;
519 opts->noTableAm = outputNoTableAm;
520 opts->noTablespace = outputNoTablespaces;
521 opts->use_setsessauth = use_setsessauth;
522 opts->no_comments = no_comments;
523 opts->no_policies = no_policies;
524 opts->no_publications = no_publications;
525 opts->no_security_labels = no_security_labels;
526 opts->no_subscriptions = no_subscriptions;
527
528 if (if_exists && !opts->dropSchema)
529 pg_fatal("option %s requires option %s",
530 "--if-exists", "-c/--clean");
531 opts->if_exists = if_exists;
533
534 if (opts->formatName)
535 {
536 if (pg_strcasecmp(opts->formatName, "c") == 0 ||
537 pg_strcasecmp(opts->formatName, "custom") == 0)
538 opts->format = archCustom;
539 else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
540 pg_strcasecmp(opts->formatName, "directory") == 0)
541 opts->format = archDirectory;
542 else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
543 pg_strcasecmp(opts->formatName, "tar") == 0)
544 opts->format = archTar;
545 else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
546 pg_strcasecmp(opts->formatName, "plain") == 0)
547 {
548 /* recognize this for consistency with pg_dump */
549 pg_fatal("archive format \"%s\" is not supported; please use psql",
550 opts->formatName);
551 }
552 else
553 pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
554 opts->formatName);
555 }
556
557 /*
558 * If toc.glo file is present, then restore all the databases from
559 * map.dat, but skip restoring those matching --exclude-database patterns.
560 */
561 if (inputFileSpec != NULL &&
563 {
566
567 opts->format = archUnknown;
568
570
571 /*
572 * Can only use --list or --use-list options with a single database
573 * dump.
574 */
575 if (opts->tocSummary)
576 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
577 "-l/--list");
578 if (opts->tocFile)
579 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
580 "-L/--use-list");
581
582 if (opts->strict_names)
583 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
584 "--strict-names");
585 if (globals_only && opts->dropSchema)
586 pg_fatal("options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
587 "--clean", "-g/--globals-only");
588
589 /*
590 * For pg_dumpall archives, --clean implies --if-exists since global
591 * objects may not exist in the target cluster.
592 */
593 if (opts->dropSchema && !opts->if_exists)
594 {
595 opts->if_exists = 1;
596 pg_log_info("--if-exists is implied by --clean for pg_dumpall archives");
597 }
598
599 if (no_schema)
600 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
601 "--no-schema");
602
603 if (data_only)
604 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
605 "-a/--data-only");
606
607 if (statistics_only)
608 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
609 "--statistics-only");
610
611 if (!(opts->dumpSections & DUMP_PRE_DATA))
612 pg_fatal("option %s cannot exclude %s when restoring a pg_dumpall archive",
613 "--section", "--pre-data");
614
615 /*
616 * To restore from a pg_dumpall archive, -C (create database) option
617 * must be specified unless we are only restoring globals.
618 */
619 if (!globals_only && opts->createDB != 1)
620 {
621 pg_log_error("option %s must be specified when restoring an archive created by pg_dumpall",
622 "-C/--create");
623 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
624 pg_log_error_hint("Individual databases can be restored using their specific archives.");
625 exit_nicely(1);
626 }
627
628 /*
629 * Always restore global objects, even if --exclude-database results
630 * in zero databases to process. If 'globals-only' is set, exit
631 * immediately.
632 */
634
636
637 if (globals_only)
638 pg_log_info("database restoring skipped because option %s was specified",
639 "-g/--globals-only");
640 else
641 {
642 /* Now restore all the databases from map.dat */
644 opts, numWorkers);
645 }
646
647 /* Free db pattern list. */
649 }
650 else
651 {
652 if (db_exclude_patterns.head != NULL)
653 {
655 pg_fatal("option %s can be used only when restoring an archive created by pg_dumpall",
656 "--exclude-database");
657 }
658
659 if (globals_only)
660 pg_fatal("option %s can be used only when restoring an archive created by pg_dumpall",
661 "-g/--globals-only");
662
663 /* Process if toc.glo file does not exist. */
664 n_errors = restore_one_database(inputFileSpec, opts, numWorkers, false);
665 }
666
667 /* Done, print a summary of ignored errors during restore. */
668 if (n_errors)
669 {
670 pg_log_warning("errors ignored on restore: %d", n_errors);
671 return 1;
672 }
673
674 return 0;
675}
676
677/*
678 * restore_global_objects
679 *
680 * This restore all global objects.
681 */
682static int
684{
685 Archive *AH;
686 int nerror = 0;
687
688 /* Set format as custom so that toc.glo file can be read. */
689 opts->format = archCustom;
690 opts->txn_size = 0;
691
692 AH = OpenArchive(inputFileSpec, opts->format);
693
695
697
698 /* Let the archiver know how noisy to be */
699 AH->verbose = opts->verbose;
700
701 /* Don't output TOC entry comments when restoring globals */
702 ((ArchiveHandle *) AH)->noTocComments = 1;
703
704 AH->exit_on_error = false;
705
706 /* Parallel execution is not supported for global object restoration. */
707 AH->numWorkers = 1;
708
710 RestoreArchive(AH, false);
711
712 nerror = AH->n_errors;
713
714 /* AH may be freed in CloseArchive? */
715 CloseArchive(AH);
716
717 return nerror;
718}
719
720/*
721 * restore_one_database
722 *
723 * This will restore one database using toc.dat file.
724 *
725 * returns the number of errors while doing restore.
726 */
727static int
729 int numWorkers, bool append_data)
730{
731 Archive *AH;
732 int n_errors;
733
734 AH = OpenArchive(inputFileSpec, opts->format);
735
737
738 /*
739 * We don't have a connection yet but that doesn't matter. The connection
740 * is initialized to NULL and if we terminate through exit_nicely() while
741 * it's still NULL, the cleanup function will just be a no-op. If we are
742 * restoring multiple databases, then only update AX handle for cleanup as
743 * the previous entry was already in the array and we had closed previous
744 * connection, so we can use the same array slot.
745 */
746 if (!append_data)
748 else
750
751 /* Let the archiver know how noisy to be */
752 AH->verbose = opts->verbose;
753
754 /*
755 * Whether to keep submitting sql commands as "pg_restore ... | psql ... "
756 */
757 AH->exit_on_error = opts->exit_on_error;
758
759 if (opts->tocFile)
760 SortTocFromFile(AH);
761
762 AH->numWorkers = numWorkers;
763
764 if (opts->tocSummary)
765 PrintTOCSummary(AH);
766 else
767 {
770 }
771
772 n_errors = AH->n_errors;
773
774 /* AH may be freed in CloseArchive? */
775 CloseArchive(AH);
776
777 return n_errors;
778}
779
780static void
781usage(const char *progname)
782{
783 printf(_("%s restores PostgreSQL databases from archives created by pg_dump or pg_dumpall.\n\n"), progname);
784 printf(_("Usage:\n"));
785 printf(_(" %s [OPTION]... [FILE]\n"), progname);
786
787 printf(_("\nGeneral options:\n"));
788 printf(_(" -d, --dbname=NAME connect to database name\n"));
789 printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
790 printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
791 printf(_(" -l, --list print summarized TOC of the archive\n"));
792 printf(_(" -v, --verbose verbose mode\n"));
793 printf(_(" -V, --version output version information, then exit\n"));
794 printf(_(" -?, --help show this help, then exit\n"));
795
796 printf(_("\nOptions controlling the restore:\n"));
797 printf(_(" -a, --data-only restore only the data, no schema\n"));
798 printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
799 printf(_(" -C, --create create the target database\n"));
800 printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
801 printf(_(" -g, --globals-only restore only global objects, no databases\n"));
802 printf(_(" -I, --index=NAME restore named index\n"));
803 printf(_(" -j, --jobs=NUM use this many parallel jobs to restore\n"));
804 printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
805 " selecting/ordering output\n"));
806 printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
807 printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
808 printf(_(" -O, --no-owner skip restoration of object ownership\n"));
809 printf(_(" -P, --function=NAME(args) restore named function\n"));
810 printf(_(" -s, --schema-only restore only the schema, no data\n"));
811 printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
812 printf(_(" -t, --table=NAME restore named relation (table, view, etc.)\n"));
813 printf(_(" -T, --trigger=NAME restore named trigger\n"));
814 printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
815 printf(_(" -1, --single-transaction restore as a single transaction\n"));
816 printf(_(" --disable-triggers disable triggers during data-only restore\n"));
817 printf(_(" --enable-row-security enable row security\n"));
818 printf(_(" --exclude-database=PATTERN do not restore the specified database(s)\n"));
819 printf(_(" --filter=FILENAME restore or skip objects based on expressions\n"
820 " in FILENAME\n"));
821 printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
822 printf(_(" --no-comments do not restore comment commands\n"));
823 printf(_(" --no-data do not restore data\n"));
824 printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
825 " created\n"));
826 printf(_(" --no-policies do not restore row security policies\n"));
827 printf(_(" --no-publications do not restore publications\n"));
828 printf(_(" --no-schema do not restore schema\n"));
829 printf(_(" --no-security-labels do not restore security labels\n"));
830 printf(_(" --no-statistics do not restore statistics\n"));
831 printf(_(" --no-subscriptions do not restore subscriptions\n"));
832 printf(_(" --no-table-access-method do not restore table access methods\n"));
833 printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
834 printf(_(" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
835 printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
836 printf(_(" --statistics restore the statistics\n"));
837 printf(_(" --statistics-only restore only the statistics, not schema or data\n"));
838 printf(_(" --strict-names require table and/or schema include patterns to\n"
839 " match at least one entity each\n"));
840 printf(_(" --transaction-size=N commit after every N objects\n"));
841 printf(_(" --use-set-session-authorization\n"
842 " use SET SESSION AUTHORIZATION commands instead of\n"
843 " ALTER OWNER commands to set ownership\n"));
844
845 printf(_("\nConnection options:\n"));
846 printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
847 printf(_(" -p, --port=PORT database server port number\n"));
848 printf(_(" -U, --username=NAME connect as specified database user\n"));
849 printf(_(" -w, --no-password never prompt for password\n"));
850 printf(_(" -W, --password force password prompt (should happen automatically)\n"));
851 printf(_(" --role=ROLENAME do SET ROLE before restore\n"));
852
853 printf(_("\n"
854 "The options -I, -n, -N, -P, -t, -T, --section, and --exclude-database can be\n"
855 "combined and specified multiple times to select multiple objects.\n"));
856 printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
857 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
858 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
859}
860
861/*
862 * read_restore_filters - retrieve object identifier patterns from file
863 *
864 * Parse the specified filter file for include and exclude patterns, and add
865 * them to the relevant lists. If the filename is "-" then filters will be
866 * read from STDIN rather than a file.
867 */
868static void
870{
872 char *objname;
874 FilterObjectType objtype;
875
877
878 while (filter_read_item(&fstate, &objname, &comtype, &objtype))
879 {
881 {
882 switch (objtype)
883 {
885 break;
892 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
893 "include",
894 filter_object_type_name(objtype));
895 exit_nicely(1);
896
898 opts->selTypes = 1;
899 opts->selFunction = 1;
900 simple_string_list_append(&opts->functionNames, objname);
901 break;
903 opts->selTypes = 1;
904 opts->selIndex = 1;
905 simple_string_list_append(&opts->indexNames, objname);
906 break;
908 simple_string_list_append(&opts->schemaNames, objname);
909 break;
911 opts->selTypes = 1;
912 opts->selTable = 1;
913 simple_string_list_append(&opts->tableNames, objname);
914 break;
916 opts->selTypes = 1;
917 opts->selTrigger = 1;
918 simple_string_list_append(&opts->triggerNames, objname);
919 break;
920 }
921 }
923 {
924 switch (objtype)
925 {
927 break;
938 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
939 "exclude",
940 filter_object_type_name(objtype));
941 exit_nicely(1);
942
944 simple_string_list_append(&opts->schemaExcludeNames, objname);
945 break;
946 }
947 }
948 else
949 {
952 }
953
954 if (objname)
955 free(objname);
956 }
957
959}
960
961/*
962 * file_exists_in_directory
963 *
964 * Returns true if the file exists in the given directory.
965 */
966static bool
967file_exists_in_directory(const char *dir, const char *filename)
968{
969 struct stat st;
970 char buf[MAXPGPATH];
971
972 if (snprintf(buf, MAXPGPATH, "%s/%s", dir, filename) >= MAXPGPATH)
973 pg_fatal("directory name too long: \"%s\"", dir);
974
975 return (stat(buf, &st) == 0 && S_ISREG(st.st_mode));
976}
977
978/*
979 * get_dbnames_list_to_restore
980 *
981 * This will mark for skipping any entries from dbname_oid_list that pattern match an
982 * entry in the db_exclude_patterns list.
983 *
984 * Returns the number of database to be restored.
985 *
986 */
987static int
991{
992 int count_db = 0;
993 PQExpBuffer query;
995 PGresult *res;
996
997 query = createPQExpBuffer();
999
1000 /*
1001 * Process one by one all dbnames and if specified to skip restoring, then
1002 * remove dbname from list.
1003 */
1005 db_cell; db_cell = db_cell->next)
1006 {
1007 DbOidName *dbidname = (DbOidName *) db_cell->ptr;
1008 bool skip_db_restore = false;
1009
1010 resetPQExpBuffer(query);
1012
1014
1016 {
1017 /*
1018 * If there is an exact match then we don't need to try a pattern
1019 * match
1020 */
1021 if (pg_strcasecmp(dbidname->str, pat_cell->val) == 0)
1022 skip_db_restore = true;
1023 /* Otherwise, try a pattern match if there is a connection */
1024 else
1025 {
1026 int dotcnt;
1027
1028 appendPQExpBufferStr(query, "SELECT 1 ");
1029 processSQLNamePattern(conn, query, pat_cell->val, false,
1030 false, NULL, db_lit->data,
1031 NULL, NULL, NULL, &dotcnt);
1032
1033 if (dotcnt > 0)
1034 {
1035 pg_log_error("improper qualified name (too many dotted names): %s",
1036 dbidname->str);
1037 PQfinish(conn);
1038 exit_nicely(1);
1039 }
1040
1041 res = executeQuery(conn, query->data);
1042
1043 if (PQntuples(res))
1044 {
1045 skip_db_restore = true;
1046 pg_log_info("database name \"%s\" matches --exclude-database pattern \"%s\"", dbidname->str, pat_cell->val);
1047 }
1048
1049 PQclear(res);
1050 resetPQExpBuffer(query);
1051 }
1052
1053 if (skip_db_restore)
1054 break;
1055 }
1056
1057 /*
1058 * Mark db to be skipped or increment the counter of dbs to be
1059 * restored
1060 */
1061 if (skip_db_restore)
1062 {
1063 pg_log_info("excluding database \"%s\"", dbidname->str);
1064 dbidname->oid = InvalidOid;
1065 }
1066 else
1067 count_db++;
1068 }
1069
1070 destroyPQExpBuffer(query);
1072
1073 return count_db;
1074}
1075
1076/*
1077 * get_dbname_oid_list_from_mfile
1078 *
1079 * Open map.dat file and read line by line and then prepare a list of database
1080 * names and corresponding db_oid.
1081 *
1082 * Returns, total number of database names in map.dat file.
1083 */
1084static int
1086{
1088 FILE *pfile;
1090 int count = 0;
1091 int len;
1092
1093
1094 /*
1095 * If there is no map.dat file in dump, then return from here as there is
1096 * no database to restore.
1097 */
1098 if (!file_exists_in_directory(dumpdirpath, "map.dat"))
1099 {
1100 pg_log_info("database restoring is skipped because file \"%s\" does not exist in directory \"%s\"", "map.dat", dumpdirpath);
1101 return 0;
1102 }
1103
1105
1106 /* Trim slash from directory name. */
1107 while (len > 1 && dumpdirpath[len - 1] == '/')
1108 {
1109 dumpdirpath[len - 1] = '\0';
1110 len--;
1111 }
1112
1114
1115 /* Open map.dat file. */
1117
1118 if (pfile == NULL)
1119 pg_fatal("could not open file \"%s\": %m", map_file_path);
1120
1122
1123 /* Append all the dbname/db_oid combinations to the list. */
1124 while (pg_get_line_buf(pfile, &linebuf))
1125 {
1126 Oid db_oid = InvalidOid;
1127 char *dbname;
1129 int namelen;
1130 char *p = linebuf.data;
1131
1132 /* look for the dboid. */
1133 while (isdigit((unsigned char) *p))
1134 p++;
1135
1136 /* ignore lines that don't begin with a digit */
1137 if (p == linebuf.data)
1138 continue;
1139
1140 if (*p == ' ')
1141 {
1142 sscanf(linebuf.data, "%u", &db_oid);
1143 p++;
1144 }
1145
1146 /* dbname is the rest of the line */
1147 dbname = p;
1148 namelen = strlen(dbname);
1149
1150 /* Strip trailing newline */
1151 if (namelen > 0 && dbname[namelen - 1] == '\n')
1152 dbname[--namelen] = '\0';
1153
1154 /* Report error and exit if the file has any corrupted data. */
1155 if (!OidIsValid(db_oid) || namelen < 1)
1156 pg_fatal("invalid entry in file \"%s\" on line %d", map_file_path,
1157 count + 1);
1158
1159 dbidname = pg_malloc(offsetof(DbOidName, str) + namelen + 1);
1160 dbidname->oid = db_oid;
1161 strlcpy(dbidname->str, dbname, namelen + 1);
1162
1163 pg_log_info("found database \"%s\" (OID: %u) in file \"%s\"",
1164 dbidname->str, db_oid, map_file_path);
1165
1167 count++;
1168 }
1169
1170 /* Close map.dat file. */
1171 fclose(pfile);
1172
1173 pfree(linebuf.data);
1174
1175 return count;
1176}
1177
1178/*
1179 * restore_all_databases
1180 *
1181 * This will restore databases those dumps are present in
1182 * directory based on map.dat file mapping.
1183 *
1184 * This will skip restoring for databases that are specified with
1185 * exclude-database option.
1186 *
1187 * returns, number of errors while doing restore.
1188 */
1189static int
1192 int numWorkers)
1193{
1195 int num_db_restore = 0;
1196 int num_total_db;
1197 int n_errors_total = 0;
1198 char *connected_db = NULL;
1199 PGconn *conn = NULL;
1202
1204
1205 /* Save db name to reuse it for all the database. */
1206 if (opts->cparams.dbname)
1207 connected_db = opts->cparams.dbname;
1208
1210
1211 pg_log_info(ngettext("found %d database name in \"%s\"",
1212 "found %d database names in \"%s\"",
1213 num_total_db),
1214 num_total_db, "map.dat");
1215
1216 /*
1217 * If exclude-patterns is given, connect to the database to process them.
1218 */
1219 if (db_exclude_patterns.head != NULL)
1220 {
1221 if (opts->cparams.dbname)
1222 {
1223 conn = ConnectDatabase(opts->cparams.dbname, NULL, opts->cparams.pghost,
1224 opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT,
1225 false, progname, NULL, NULL, NULL, NULL);
1226
1227 if (!conn)
1228 pg_fatal("could not connect to database \"%s\"", opts->cparams.dbname);
1229 }
1230
1231 if (!conn)
1232 {
1233 pg_log_info("trying to connect to database \"%s\"", "postgres");
1234
1235 conn = ConnectDatabase("postgres", NULL, opts->cparams.pghost,
1236 opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT,
1237 false, progname, NULL, NULL, NULL, NULL);
1238
1239 /* Try with template1. */
1240 if (!conn)
1241 {
1242 pg_log_info("trying to connect to database \"%s\"", "template1");
1243
1244 conn = ConnectDatabase("template1", NULL, opts->cparams.pghost,
1245 opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT,
1246 false, progname, NULL, NULL, NULL, NULL);
1247 if (!conn)
1248 {
1249 pg_log_error("could not connect to databases \"postgres\" or \"template1\"\n"
1250 "Please specify an alternative database.");
1251 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
1252 exit_nicely(1);
1253 }
1254 }
1255 }
1256
1257 /* Filter the db list according to the exclude patterns. */
1260 PQfinish(conn);
1261 }
1262 else
1264
1265 /* Exit if no db needs to be restored. */
1266 if (num_db_restore == 0)
1267 {
1268 pg_log_info(ngettext("no database needs restoring out of %d database",
1269 "no database needs restoring out of %d databases", num_total_db),
1270 num_total_db);
1273 return 0;
1274 }
1275
1276 pg_log_info("need to restore %d databases out of %d databases", num_db_restore, num_total_db);
1277
1278 /*
1279 * We have a list of databases to restore after processing the
1280 * exclude-database switch(es). Now we can restore them one by one.
1281 */
1283 db_cell; db_cell = db_cell->next)
1284 {
1285 DbOidName *dbidname = (DbOidName *) db_cell->ptr;
1286 char subdirpath[MAXPGPATH];
1287 char subdirdbpath[MAXPGPATH];
1288 char dbfilename[MAXPGPATH];
1289 int n_errors;
1290
1291 /* ignore dbs marked for skipping */
1292 if (dbidname->oid == InvalidOid)
1293 continue;
1294
1295 /*
1296 * Since pg_backup_archiver.c may modify RestoreOptions during the
1297 * previous restore, we must provide a fresh copy of the original
1298 * "opts" for each call to restore_one_database.
1299 */
1301
1302 /*
1303 * We need to reset override_dbname so that objects can be restored
1304 * into an already created database. (used with -d/--dbname option)
1305 */
1306 if (tmpopts->cparams.override_dbname)
1307 {
1308 pfree(tmpopts->cparams.override_dbname);
1309 tmpopts->cparams.override_dbname = NULL;
1310 }
1311
1312 snprintf(subdirdbpath, MAXPGPATH, "%s/databases", inputFileSpec);
1313
1314 /*
1315 * Look for the database dump file/dir. If there is an {oid}.tar or
1316 * {oid}.dmp file, use it. Otherwise try to use a directory called
1317 * {oid}
1318 */
1319 snprintf(dbfilename, MAXPGPATH, "%u.tar", dbidname->oid);
1321 snprintf(subdirpath, MAXPGPATH, "%s/databases/%u.tar", inputFileSpec, dbidname->oid);
1322 else
1323 {
1324 snprintf(dbfilename, MAXPGPATH, "%u.dmp", dbidname->oid);
1325
1327 snprintf(subdirpath, MAXPGPATH, "%s/databases/%u.dmp", inputFileSpec, dbidname->oid);
1328 else
1329 snprintf(subdirpath, MAXPGPATH, "%s/databases/%u", inputFileSpec, dbidname->oid);
1330 }
1331
1332 pg_log_info("restoring database \"%s\"", dbidname->str);
1333
1334 /* If database is already created, then don't set createDB flag. */
1335 if (tmpopts->cparams.dbname)
1336 {
1338
1339 test_conn = ConnectDatabase(dbidname->str, NULL, tmpopts->cparams.pghost,
1340 tmpopts->cparams.pgport, tmpopts->cparams.username, TRI_DEFAULT,
1341 false, progname, NULL, NULL, NULL, NULL);
1342 if (test_conn)
1343 {
1345
1346 /* Use already created database for connection. */
1347 tmpopts->createDB = 0;
1348 tmpopts->cparams.dbname = dbidname->str;
1349 }
1350 else
1351 {
1352 /* We'll have to create it */
1353 tmpopts->createDB = 1;
1354 tmpopts->cparams.dbname = connected_db;
1355 }
1356 }
1357
1358 /* Restore the single database. */
1359 n_errors = restore_one_database(subdirpath, tmpopts, numWorkers, true);
1360
1361 n_errors_total += n_errors;
1362
1363 /* Print a summary of ignored errors during single database restore. */
1364 if (n_errors)
1365 pg_log_warning("errors ignored on database \"%s\" restore: %d", dbidname->str, n_errors);
1366 }
1367
1368 /* Log number of processed databases. */
1369 pg_log_info("number of restored databases is %d", num_db_restore);
1370
1371 /* Free dbname and dboid list. */
1373
1376
1377 return n_errors_total;
1378}
void replace_on_exit_close_archive(Archive *AHX)
Definition parallel.c:345
void on_exit_close_archive(Archive *AHX)
Definition parallel.c:330
void init_parallel_dump_utils(void)
Definition parallel.c:238
#define PG_MAX_JOBS
Definition parallel.h:48
#define PG_BINARY_R
Definition c.h:1332
#define ngettext(s, p, n)
Definition c.h:1219
#define Assert(condition)
Definition c.h:906
#define PG_TEXTDOMAIN(domain)
Definition c.h:1252
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:513
#define OidIsValid(objectId)
Definition c.h:821
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition exec.c:430
int main(void)
PGresult * executeQuery(PGconn *conn, const char *query)
Definition connectdb.c:278
PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)
Definition connectdb.c:40
char * generate_restrict_key(void)
Definition dumputils.c:973
bool valid_restrict_key(const char *restrict_key)
Definition dumputils.c:997
#define _(x)
Definition elog.c:95
void PQfinish(PGconn *conn)
void * pg_malloc(size_t size)
Definition fe_memutils.c:47
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
void pg_free(void *ptr)
#define pg_malloc0_object(type)
Definition fe_memutils.h:51
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
Definition filter.c:36
void filter_free(FilterStateData *fstate)
Definition filter.c:60
const char * filter_object_type_name(FilterObjectType fot)
Definition filter.c:82
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
Definition filter.c:392
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
Definition filter.c:154
FilterObjectType
Definition filter.h:48
@ FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN
Definition filter.h:51
@ FILTER_OBJECT_TYPE_SCHEMA
Definition filter.h:57
@ FILTER_OBJECT_TYPE_INDEX
Definition filter.h:56
@ FILTER_OBJECT_TYPE_TRIGGER
Definition filter.h:60
@ FILTER_OBJECT_TYPE_FOREIGN_DATA
Definition filter.h:54
@ FILTER_OBJECT_TYPE_DATABASE
Definition filter.h:52
@ FILTER_OBJECT_TYPE_FUNCTION
Definition filter.h:55
@ FILTER_OBJECT_TYPE_TABLE_DATA
Definition filter.h:50
@ FILTER_OBJECT_TYPE_NONE
Definition filter.h:49
@ FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN
Definition filter.h:59
@ FILTER_OBJECT_TYPE_EXTENSION
Definition filter.h:53
@ FILTER_OBJECT_TYPE_TABLE
Definition filter.h:58
FilterCommandType
Definition filter.h:38
@ FILTER_COMMAND_TYPE_NONE
Definition filter.h:39
@ FILTER_COMMAND_TYPE_EXCLUDE
Definition filter.h:41
@ FILTER_COMMAND_TYPE_INCLUDE
Definition filter.h:40
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition getopt_long.c:60
#define no_argument
Definition getopt_long.h:25
#define required_argument
Definition getopt_long.h:26
const char * str
#define PQclear
#define PQntuples
void pg_logging_increase_verbosity(void)
Definition logging.c:185
void pg_logging_init(const char *argv0)
Definition logging.c:83
void pg_logging_set_level(enum pg_log_level new_level)
Definition logging.c:176
#define pg_log_error(...)
Definition logging.h:106
#define pg_log_error_hint(...)
Definition logging.h:112
#define pg_log_info(...)
Definition logging.h:124
@ PG_LOG_WARNING
Definition logging.h:38
const char * progname
Definition main.c:44
void pfree(void *pointer)
Definition mcxt.c:1616
static size_t append_data(char *buf, size_t size, size_t nmemb, void *userdata)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
static AmcheckOptions opts
Definition pg_amcheck.c:112
static void usage(void)
void ProcessArchiveRestoreOptions(Archive *AHX)
RestoreOptions * NewRestoreOptions(void)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void RestoreArchive(Archive *AHX, bool append_data)
void CloseArchive(Archive *AHX)
void SortTocFromFile(Archive *AHX)
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
@ archUnknown
Definition pg_backup.h:41
@ archTar
Definition pg_backup.h:43
@ archCustom
Definition pg_backup.h:42
@ archDirectory
Definition pg_backup.h:45
void exit_nicely(int code)
void set_dump_section(const char *arg, int *dumpSections)
#define DUMP_PRE_DATA
#define pg_fatal(...)
#define MAXPGPATH
const void size_t len
static int strict_names
Definition pg_dump.c:157
static int if_exists
Definition pg_dumpall.c:104
static int statistics_only
Definition pg_dumpall.c:124
static int no_policies
Definition pg_dumpall.c:110
static int disable_triggers
Definition pg_dumpall.c:103
static int no_comments
Definition pg_dumpall.c:109
static int no_publications
Definition pg_dumpall.c:111
static int no_security_labels
Definition pg_dumpall.c:112
static int no_statistics
Definition pg_dumpall.c:115
static int use_setsessauth
Definition pg_dumpall.c:108
static int no_data
Definition pg_dumpall.c:113
static int no_schema
Definition pg_dumpall.c:114
static int no_subscriptions
Definition pg_dumpall.c:116
static char * filename
Definition pg_dumpall.c:132
static int with_statistics
Definition pg_dumpall.c:120
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition pg_get_line.c:95
PGDLLIMPORT int optind
Definition getopt.c:51
PGDLLIMPORT char * optarg
Definition getopt.c:53
static bool file_exists_in_directory(const char *dir, const char *filename)
Definition pg_restore.c:967
static int restore_one_database(const char *inputFileSpec, RestoreOptions *opts, int numWorkers, bool append_data)
Definition pg_restore.c:728
static int get_dbnames_list_to_restore(PGconn *conn, SimplePtrList *dbname_oid_list, SimpleStringList db_exclude_patterns)
Definition pg_restore.c:988
static int restore_global_objects(const char *inputFileSpec, RestoreOptions *opts)
Definition pg_restore.c:683
static void read_restore_filters(const char *filename, RestoreOptions *opts)
Definition pg_restore.c:869
static int get_dbname_oid_list_from_mfile(char *dumpdirpath, SimplePtrList *dbname_oid_list)
static int restore_all_databases(const char *inputFileSpec, SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pg_log_warning(...)
Definition pgfnames.c:24
int pg_strcasecmp(const char *s1, const char *s2)
#define snprintf
Definition port.h:260
const char * get_progname(const char *argv0)
Definition path.c:652
#define printf(...)
Definition port.h:266
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
#define InvalidOid
unsigned int Oid
PQExpBuffer createPQExpBuffer(void)
Definition pqexpbuffer.c:72
void resetPQExpBuffer(PQExpBuffer str)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
char * c
static int fb(int x)
void simple_ptr_list_destroy(SimplePtrList *list)
void simple_string_list_append(SimpleStringList *list, const char *val)
Definition simple_list.c:63
void simple_string_list_destroy(SimpleStringList *list)
void simple_ptr_list_append(SimplePtrList *list, void *ptr)
#define free(a)
char * dbname
Definition streamutil.c:49
PGconn * conn
Definition streamutil.c:52
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, PQExpBuffer dbnamebuf, int *dotcnt)
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
bool exit_on_error
Definition pg_backup.h:252
int n_errors
Definition pg_backup.h:253
int numWorkers
Definition pg_backup.h:240
int verbose
Definition pg_backup.h:232
char str[FLEXIBLE_ARRAY_MEMBER]
Definition pg_restore.c:80
unsigned short st_mode
Definition win32_port.h:258
@ TRI_YES
Definition vacuumlo.c:38
@ TRI_DEFAULT
Definition vacuumlo.c:36
@ TRI_NO
Definition vacuumlo.c:37
#define stat
Definition win32_port.h:74
#define S_ISREG(m)
Definition win32_port.h:318