57 main(
int argc,
char **argv)
66 static int enable_row_security = 0;
68 static int no_data_for_failed_tables = 0;
69 static int outputNoTableAm = 0;
70 static int outputNoTablespaces = 0;
78 struct option cmdopts[] = {
79 {
"clean", 0, NULL,
'c'},
80 {
"create", 0, NULL,
'C'},
81 {
"data-only", 0, NULL,
'a'},
82 {
"dbname", 1, NULL,
'd'},
83 {
"exit-on-error", 0, NULL,
'e'},
84 {
"exclude-schema", 1, NULL,
'N'},
85 {
"file", 1, NULL,
'f'},
86 {
"format", 1, NULL,
'F'},
87 {
"function", 1, NULL,
'P'},
88 {
"host", 1, NULL,
'h'},
89 {
"index", 1, NULL,
'I'},
90 {
"jobs", 1, NULL,
'j'},
91 {
"list", 0, NULL,
'l'},
92 {
"no-privileges", 0, NULL,
'x'},
93 {
"no-acl", 0, NULL,
'x'},
94 {
"no-owner", 0, NULL,
'O'},
95 {
"no-reconnect", 0, NULL,
'R'},
96 {
"port", 1, NULL,
'p'},
97 {
"no-password", 0, NULL,
'w'},
98 {
"password", 0, NULL,
'W'},
99 {
"schema", 1, NULL,
'n'},
100 {
"schema-only", 0, NULL,
's'},
101 {
"superuser", 1, NULL,
'S'},
102 {
"table", 1, NULL,
't'},
103 {
"trigger", 1, NULL,
'T'},
104 {
"use-list", 1, NULL,
'L'},
105 {
"username", 1, NULL,
'U'},
106 {
"verbose", 0, NULL,
'v'},
107 {
"single-transaction", 0, NULL,
'1'},
113 {
"enable-row-security",
no_argument, &enable_row_security, 1},
115 {
"no-data-for-failed-tables",
no_argument, &no_data_for_failed_tables, 1},
116 {
"no-table-access-method",
no_argument, &outputNoTableAm, 1},
117 {
"no-tablespaces",
no_argument, &outputNoTablespaces, 1},
142 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
147 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
149 puts(
"pg_restore (PostgreSQL) " PG_VERSION);
154 while ((
c =
getopt_long(argc, argv,
"acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
155 cmdopts, NULL)) != -1)
163 opts->dropSchema = 1;
172 opts->exit_on_error =
true;
194 opts->tocSummary = 1;
222 opts->selFunction = 1;
232 opts->selTrigger = 1;
236 opts->schemaOnly = 1;
270 opts->single_txn =
true;
271 opts->exit_on_error =
true;
298 inputFileSpec = argv[
optind++];
300 inputFileSpec = NULL;
305 pg_log_error(
"too many command-line arguments (first is \"%s\")",
312 if (!
opts->cparams.dbname && !
opts->filename && !
opts->tocSummary)
313 pg_fatal(
"one of -d/--dbname and -f/--file must be specified");
316 if (
opts->cparams.dbname)
320 pg_log_error(
"options -d/--dbname and -f/--file cannot be used together");
327 if (
opts->dataOnly &&
opts->schemaOnly)
328 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
330 if (
opts->dataOnly &&
opts->dropSchema)
331 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
337 if (
opts->createDB &&
opts->single_txn)
338 pg_fatal(
"options -C/--create and -1/--single-transaction cannot be used together");
341 if (
opts->single_txn && numWorkers > 1)
342 pg_fatal(
"cannot specify both --single-transaction and multiple jobs");
345 opts->enable_row_security = enable_row_security;
346 opts->noDataForFailedTables = no_data_for_failed_tables;
347 opts->noTableAm = outputNoTableAm;
348 opts->noTablespace = outputNoTablespaces;
356 pg_fatal(
"option --if-exists requires option -c/--clean");
360 if (
opts->formatName)
362 switch (
opts->formatName[0])
380 pg_fatal(
"unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
409 if (
opts->tocSummary)
432 printf(
_(
"%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"),
progname);
436 printf(
_(
"\nGeneral options:\n"));
437 printf(
_(
" -d, --dbname=NAME connect to database name\n"));
438 printf(
_(
" -f, --file=FILENAME output file name (- for stdout)\n"));
439 printf(
_(
" -F, --format=c|d|t backup file format (should be automatic)\n"));
440 printf(
_(
" -l, --list print summarized TOC of the archive\n"));
441 printf(
_(
" -v, --verbose verbose mode\n"));
442 printf(
_(
" -V, --version output version information, then exit\n"));
443 printf(
_(
" -?, --help show this help, then exit\n"));
445 printf(
_(
"\nOptions controlling the restore:\n"));
446 printf(
_(
" -a, --data-only restore only the data, no schema\n"));
447 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
448 printf(
_(
" -C, --create create the target database\n"));
449 printf(
_(
" -e, --exit-on-error exit on error, default is to continue\n"));
450 printf(
_(
" -I, --index=NAME restore named index\n"));
451 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to restore\n"));
452 printf(
_(
" -L, --use-list=FILENAME use table of contents from this file for\n"
453 " selecting/ordering output\n"));
454 printf(
_(
" -n, --schema=NAME restore only objects in this schema\n"));
455 printf(
_(
" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
456 printf(
_(
" -O, --no-owner skip restoration of object ownership\n"));
457 printf(
_(
" -P, --function=NAME(args) restore named function\n"));
458 printf(
_(
" -s, --schema-only restore only the schema, no data\n"));
459 printf(
_(
" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
460 printf(
_(
" -t, --table=NAME restore named relation (table, view, etc.)\n"));
461 printf(
_(
" -T, --trigger=NAME restore named trigger\n"));
462 printf(
_(
" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
463 printf(
_(
" -1, --single-transaction restore as a single transaction\n"));
464 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
465 printf(
_(
" --enable-row-security enable row security\n"));
466 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
467 printf(
_(
" --no-comments do not restore comments\n"));
468 printf(
_(
" --no-data-for-failed-tables do not restore data of tables that could not be\n"
470 printf(
_(
" --no-publications do not restore publications\n"));
471 printf(
_(
" --no-security-labels do not restore security labels\n"));
472 printf(
_(
" --no-subscriptions do not restore subscriptions\n"));
473 printf(
_(
" --no-table-access-method do not restore table access methods\n"));
474 printf(
_(
" --no-tablespaces do not restore tablespace assignments\n"));
475 printf(
_(
" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
476 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
477 " match at least one entity each\n"));
478 printf(
_(
" --use-set-session-authorization\n"
479 " use SET SESSION AUTHORIZATION commands instead of\n"
480 " ALTER OWNER commands to set ownership\n"));
482 printf(
_(
"\nConnection options:\n"));
483 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
484 printf(
_(
" -p, --port=PORT database server port number\n"));
485 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
486 printf(
_(
" -w, --no-password never prompt for password\n"));
487 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
488 printf(
_(
" --role=ROLENAME do SET ROLE before restore\n"));
491 "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
492 "multiple times to select multiple objects.\n"));
493 printf(
_(
"\nIf no input file name is supplied, then standard input is used.\n\n"));
494 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
495 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
void on_exit_close_archive(Archive *AHX)
void init_parallel_dump_utils(void)
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
char * pg_strdup(const char *in)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
void pg_logging_increase_verbosity(void)
void pg_logging_init(const char *argv0)
void pg_logging_set_level(enum pg_log_level new_level)
#define pg_log_error(...)
#define pg_log_error_hint(...)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
static AmcheckOptions opts
void ProcessArchiveRestoreOptions(Archive *AHX)
RestoreOptions * NewRestoreOptions(void)
void CloseArchive(Archive *AHX)
void SortTocFromFile(Archive *AHX)
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
void RestoreArchive(Archive *AHX)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void set_dump_section(const char *arg, int *dumpSections)
static int disable_triggers
#define exit_nicely(code)
static int no_publications
static int no_security_labels
static int use_setsessauth
static int no_subscriptions
PGDLLIMPORT char * optarg
static void usage(const char *progname)
int main(int argc, char **argv)
#define pg_log_warning(...)
const char * get_progname(const char *argv0)
void simple_string_list_append(SimpleStringList *list, const char *val)