58 main(
int argc,
char **argv)
67 static int enable_row_security = 0;
69 static int no_data_for_failed_tables = 0;
70 static int outputNoTableAm = 0;
71 static int outputNoTablespaces = 0;
78 bool data_only =
false;
79 bool schema_only =
false;
81 struct option cmdopts[] = {
82 {
"clean", 0, NULL,
'c'},
83 {
"create", 0, NULL,
'C'},
84 {
"data-only", 0, NULL,
'a'},
85 {
"dbname", 1, NULL,
'd'},
86 {
"exit-on-error", 0, NULL,
'e'},
87 {
"exclude-schema", 1, NULL,
'N'},
88 {
"file", 1, NULL,
'f'},
89 {
"format", 1, NULL,
'F'},
90 {
"function", 1, NULL,
'P'},
91 {
"host", 1, NULL,
'h'},
92 {
"index", 1, NULL,
'I'},
93 {
"jobs", 1, NULL,
'j'},
94 {
"list", 0, NULL,
'l'},
95 {
"no-privileges", 0, NULL,
'x'},
96 {
"no-acl", 0, NULL,
'x'},
97 {
"no-owner", 0, NULL,
'O'},
98 {
"no-reconnect", 0, NULL,
'R'},
99 {
"port", 1, NULL,
'p'},
100 {
"no-password", 0, NULL,
'w'},
101 {
"password", 0, NULL,
'W'},
102 {
"schema", 1, NULL,
'n'},
103 {
"schema-only", 0, NULL,
's'},
104 {
"superuser", 1, NULL,
'S'},
105 {
"table", 1, NULL,
't'},
106 {
"trigger", 1, NULL,
'T'},
107 {
"use-list", 1, NULL,
'L'},
108 {
"username", 1, NULL,
'U'},
109 {
"verbose", 0, NULL,
'v'},
110 {
"single-transaction", 0, NULL,
'1'},
116 {
"enable-row-security",
no_argument, &enable_row_security, 1},
118 {
"no-data-for-failed-tables",
no_argument, &no_data_for_failed_tables, 1},
119 {
"no-table-access-method",
no_argument, &outputNoTableAm, 1},
120 {
"no-tablespaces",
no_argument, &outputNoTablespaces, 1},
147 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
152 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
154 puts(
"pg_restore (PostgreSQL) " PG_VERSION);
159 while ((
c =
getopt_long(argc, argv,
"acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
160 cmdopts, NULL)) != -1)
168 opts->dropSchema = 1;
177 opts->exit_on_error =
true;
199 opts->tocSummary = 1;
227 opts->selFunction = 1;
237 opts->selTrigger = 1;
275 opts->single_txn =
true;
276 opts->exit_on_error =
true;
303 opts->exit_on_error =
true;
315 inputFileSpec = argv[
optind++];
317 inputFileSpec = NULL;
322 pg_log_error(
"too many command-line arguments (first is \"%s\")",
329 if (!
opts->cparams.dbname && !
opts->filename && !
opts->tocSummary)
330 pg_fatal(
"one of -d/--dbname and -f/--file must be specified");
333 if (
opts->cparams.dbname)
337 pg_log_error(
"options -d/--dbname and -f/--file cannot be used together");
344 if (data_only && schema_only)
345 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
347 if (data_only &&
opts->dropSchema)
348 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
350 if (
opts->single_txn &&
opts->txn_size > 0)
351 pg_fatal(
"options -1/--single-transaction and --transaction-size cannot be used together");
357 if (
opts->createDB &&
opts->single_txn)
358 pg_fatal(
"options -C/--create and -1/--single-transaction cannot be used together");
361 if (
opts->single_txn && numWorkers > 1)
362 pg_fatal(
"cannot specify both --single-transaction and multiple jobs");
365 opts->dumpSchema = (!data_only);
366 opts->dumpData = (!schema_only);
369 opts->enable_row_security = enable_row_security;
370 opts->noDataForFailedTables = no_data_for_failed_tables;
371 opts->noTableAm = outputNoTableAm;
372 opts->noTablespace = outputNoTablespaces;
380 pg_fatal(
"option --if-exists requires option -c/--clean");
384 if (
opts->formatName)
386 switch (
opts->formatName[0])
404 pg_fatal(
"unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
433 if (
opts->tocSummary)
456 printf(
_(
"%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"),
progname);
460 printf(
_(
"\nGeneral options:\n"));
461 printf(
_(
" -d, --dbname=NAME connect to database name\n"));
462 printf(
_(
" -f, --file=FILENAME output file name (- for stdout)\n"));
463 printf(
_(
" -F, --format=c|d|t backup file format (should be automatic)\n"));
464 printf(
_(
" -l, --list print summarized TOC of the archive\n"));
465 printf(
_(
" -v, --verbose verbose mode\n"));
466 printf(
_(
" -V, --version output version information, then exit\n"));
467 printf(
_(
" -?, --help show this help, then exit\n"));
469 printf(
_(
"\nOptions controlling the restore:\n"));
470 printf(
_(
" -a, --data-only restore only the data, no schema\n"));
471 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
472 printf(
_(
" -C, --create create the target database\n"));
473 printf(
_(
" -e, --exit-on-error exit on error, default is to continue\n"));
474 printf(
_(
" -I, --index=NAME restore named index\n"));
475 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to restore\n"));
476 printf(
_(
" -L, --use-list=FILENAME use table of contents from this file for\n"
477 " selecting/ordering output\n"));
478 printf(
_(
" -n, --schema=NAME restore only objects in this schema\n"));
479 printf(
_(
" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
480 printf(
_(
" -O, --no-owner skip restoration of object ownership\n"));
481 printf(
_(
" -P, --function=NAME(args) restore named function\n"));
482 printf(
_(
" -s, --schema-only restore only the schema, no data\n"));
483 printf(
_(
" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
484 printf(
_(
" -t, --table=NAME restore named relation (table, view, etc.)\n"));
485 printf(
_(
" -T, --trigger=NAME restore named trigger\n"));
486 printf(
_(
" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
487 printf(
_(
" -1, --single-transaction restore as a single transaction\n"));
488 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
489 printf(
_(
" --enable-row-security enable row security\n"));
490 printf(
_(
" --filter=FILENAME restore or skip objects based on expressions\n"
492 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
493 printf(
_(
" --no-comments do not restore comment commands\n"));
494 printf(
_(
" --no-data-for-failed-tables do not restore data of tables that could not be\n"
496 printf(
_(
" --no-publications do not restore publications\n"));
497 printf(
_(
" --no-security-labels do not restore security labels\n"));
498 printf(
_(
" --no-subscriptions do not restore subscriptions\n"));
499 printf(
_(
" --no-table-access-method do not restore table access methods\n"));
500 printf(
_(
" --no-tablespaces do not restore tablespace assignments\n"));
501 printf(
_(
" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
502 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
503 " match at least one entity each\n"));
504 printf(
_(
" --transaction-size=N commit after every N objects\n"));
505 printf(
_(
" --use-set-session-authorization\n"
506 " use SET SESSION AUTHORIZATION commands instead of\n"
507 " ALTER OWNER commands to set ownership\n"));
509 printf(
_(
"\nConnection options:\n"));
510 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
511 printf(
_(
" -p, --port=PORT database server port number\n"));
512 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
513 printf(
_(
" -w, --no-password never prompt for password\n"));
514 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
515 printf(
_(
" --role=ROLENAME do SET ROLE before restore\n"));
518 "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
519 "multiple times to select multiple objects.\n"));
520 printf(
_(
"\nIf no input file name is supplied, then standard input is used.\n\n"));
521 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
522 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
563 opts->selFunction = 1;
581 opts->selTrigger = 1;
void on_exit_close_archive(Archive *AHX)
void init_parallel_dump_utils(void)
#define Assert(condition)
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
char * pg_strdup(const char *in)
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
void filter_free(FilterStateData *fstate)
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
const char * filter_object_type_name(FilterObjectType fot)
@ FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN
@ FILTER_OBJECT_TYPE_SCHEMA
@ FILTER_OBJECT_TYPE_INDEX
@ FILTER_OBJECT_TYPE_TRIGGER
@ FILTER_OBJECT_TYPE_FOREIGN_DATA
@ FILTER_OBJECT_TYPE_DATABASE
@ FILTER_OBJECT_TYPE_FUNCTION
@ FILTER_OBJECT_TYPE_TABLE_DATA
@ FILTER_OBJECT_TYPE_NONE
@ FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN
@ FILTER_OBJECT_TYPE_EXTENSION
@ FILTER_OBJECT_TYPE_TABLE
@ FILTER_COMMAND_TYPE_NONE
@ FILTER_COMMAND_TYPE_EXCLUDE
@ FILTER_COMMAND_TYPE_INCLUDE
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)
static void read_restore_filters(const char *filename, RestoreOptions *opts)
#define pg_log_warning(...)
const char * get_progname(const char *argv0)
void simple_string_list_append(SimpleStringList *list, const char *val)