default: /* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit_nicely(1);
}
}
/* Get file name from command line */ if (optind < argc)
inputFileSpec = argv[optind++]; else
inputFileSpec = NULL;
/* Complain if any arguments remain */ if (optind < argc)
{
pg_log_error("too many command-line arguments (first is \"%s\")",
argv[optind]);
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit_nicely(1);
}
/* Complain if neither -f nor -d was specified (except if dumping TOC) */ if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary)
pg_fatal("one of -d/--dbname and -f/--file must be specified");
/* Should get at most one of -d and -f, else user is confused */ if (opts->cparams.dbname)
{ if (opts->filename)
{
pg_log_error("options %s and %s cannot be used together", "-d/--dbname", "-f/--file");
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit_nicely(1);
}
if (opts->restrict_key)
pg_fatal("options %s and %s cannot be used together", "-d/--dbname", "--restrict-key");
opts->useDB = 1;
} else
{ /* *Ifyoudon'tprovidearestrictkey,onewillbeappointedforyou.
*/ if (!opts->restrict_key)
opts->restrict_key = generate_restrict_key(); if (!opts->restrict_key)
pg_fatal("could not generate restrict key"); if (!valid_restrict_key(opts->restrict_key))
pg_fatal("invalid restrict key");
}
/* reject conflicting "-only" options */ if (data_only && schema_only)
pg_fatal("options %s and %s cannot be used together", "-s/--schema-only", "-a/--data-only"); if (schema_only && statistics_only)
pg_fatal("options %s and %s cannot be used together", "-s/--schema-only", "--statistics-only"); if (data_only && statistics_only)
pg_fatal("options %s and %s cannot be used together", "-a/--data-only", "--statistics-only");
/* reject conflicting "-only" and "no-" options */ if (data_only && no_data)
pg_fatal("options %s and %s cannot be used together", "-a/--data-only", "--no-data"); if (schema_only && no_schema)
pg_fatal("options %s and %s cannot be used together", "-s/--schema-only", "--no-schema"); if (statistics_only && no_statistics)
pg_fatal("options %s and %s cannot be used together", "--statistics-only", "--no-statistics");
/* reject conflicting "no-" options */ if (with_statistics && no_statistics)
pg_fatal("options %s and %s cannot be used together", "--statistics", "--no-statistics");
/* reject conflicting "only-" options */ if (data_only && with_statistics)
pg_fatal("options %s and %s cannot be used together", "-a/--data-only", "--statistics"); if (schema_only && with_statistics)
pg_fatal("options %s and %s cannot be used together", "-s/--schema-only", "--statistics");
if (data_only && opts->dropSchema)
pg_fatal("options %s and %s cannot be used together", "-c/--clean", "-a/--data-only");
if (opts->single_txn && opts->txn_size > 0)
pg_fatal("options %s and %s cannot be used together", "-1/--single-transaction", "--transaction-size");
/* *-Cisnotcompatiblewith-1,becausewecan'tcreateadatabaseinside *atransactionblock.
*/ if (opts->createDB && opts->single_txn)
pg_fatal("options %s and %s cannot be used together", "-C/--create", "-1/--single-transaction");
/* Can't do single-txn mode with multiple connections */ if (opts->single_txn && numWorkers > 1)
pg_fatal("cannot specify both --single-transaction and multiple jobs");
if (opts->tocSummary)
PrintTOCSummary(AH); else
{
ProcessArchiveRestoreOptions(AH);
RestoreArchive(AH);
}
/* done, print a summary of ignored errors */ if (AH->n_errors)
pg_log_warning("errors ignored on restore: %d", AH->n_errors);
/* AH may be freed in CloseArchive? */
exit_code = AH->n_errors ? 1 : 0;
CloseArchive(AH);
return exit_code;
}
staticvoid
usage(constchar *progname)
{
printf(_("%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"), progname);
printf(_("Usage:\n"));
printf(_(" %s [OPTION]... [FILE]\n"), progname);
printf(_("\nGeneral options:\n"));
printf(_(" -d, --dbname=NAME connect to database name\n"));
printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
printf(_(" -l, --list print summarized TOC of the archive\n"));
printf(_(" -v, --verbose verbose mode\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nOptions controlling the restore:\n"));
printf(_(" -a, --data-only restore only the data, no schema\n"));
printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
printf(_(" -C, --create create the target database\n"));
printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
printf(_(" -I, --index=NAME restore named index\n"));
printf(_(" -j, --jobs=NUM use this many parallel jobs to restore\n"));
printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n" " selecting/ordering output\n"));
printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
printf(_(" -P, --function=NAME(args) restore named function\n"));
printf(_(" -s, --schema-only restore only the schema, no data\n"));
printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
printf(_(" -t, --table=NAME restore named relation (table, view, etc.)\n"));
printf(_(" -T, --trigger=NAME restore named trigger\n"));
printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
printf(_(" -1, --single-transaction restore as a single transaction\n"));
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --enable-row-security enable row security\n"));
printf(_(" --filter=FILENAME restore or skip objects based on expressions\n" " in FILENAME\n"));
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
printf(_(" --no-comments do not restore comment commands\n"));
printf(_(" --no-data do not restore data\n"));
printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n" " created\n"));
printf(_(" --no-policies do not restore row security policies\n"));
printf(_(" --no-publications do not restore publications\n"));
printf(_(" --no-schema do not restore schema\n"));
printf(_(" --no-security-labels do not restore security labels\n"));
printf(_(" --no-statistics do not restore statistics\n"));
printf(_(" --no-subscriptions do not restore subscriptions\n"));
printf(_(" --no-table-access-method do not restore table access methods\n"));
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
printf(_(" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
printf(_(" --statistics restore the statistics\n"));
printf(_(" --statistics-only restore only the statistics, not schema or data\n"));
printf(_(" --strict-names require table and/or schema include patterns to\n" " match at least one entity each\n"));
printf(_(" --transaction-size=N commit after every N objects\n"));
printf(_(" --use-set-session-authorization\n" " use SET SESSION AUTHORIZATION commands instead of\n" " ALTER OWNER commands to set ownership\n"));
printf(_("\nConnection options:\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
printf(_(" --role=ROLENAME do SET ROLE before restore\n"));
printf(_("\n" "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n" "multiple times to select multiple objects.\n"));
printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
while (filter_read_item(&fstate, &objname, &comtype, &objtype))
{ if (comtype == FILTER_COMMAND_TYPE_INCLUDE)
{ switch (objtype)
{ case FILTER_OBJECT_TYPE_NONE: break; case FILTER_OBJECT_TYPE_TABLE_DATA: case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN: case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN: case FILTER_OBJECT_TYPE_DATABASE: case FILTER_OBJECT_TYPE_EXTENSION: case FILTER_OBJECT_TYPE_FOREIGN_DATA:
pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"), "include",
filter_object_type_name(objtype));
exit_nicely(1);
case FILTER_OBJECT_TYPE_FUNCTION:
opts->selTypes = 1;
opts->selFunction = 1;
simple_string_list_append(&opts->functionNames, objname); break; case FILTER_OBJECT_TYPE_INDEX:
opts->selTypes = 1;
opts->selIndex = 1;
simple_string_list_append(&opts->indexNames, objname); break; case FILTER_OBJECT_TYPE_SCHEMA:
simple_string_list_append(&opts->schemaNames, objname); break; case FILTER_OBJECT_TYPE_TABLE:
opts->selTypes = 1;
opts->selTable = 1;
simple_string_list_append(&opts->tableNames, objname); break; case FILTER_OBJECT_TYPE_TRIGGER:
opts->selTypes = 1;
opts->selTrigger = 1;
simple_string_list_append(&opts->triggerNames, objname); break;
}
} elseif (comtype == FILTER_COMMAND_TYPE_EXCLUDE)
{ switch (objtype)
{ case FILTER_OBJECT_TYPE_NONE: break; case FILTER_OBJECT_TYPE_TABLE_DATA: case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN: case FILTER_OBJECT_TYPE_DATABASE: case FILTER_OBJECT_TYPE_EXTENSION: case FILTER_OBJECT_TYPE_FOREIGN_DATA: case FILTER_OBJECT_TYPE_FUNCTION: case FILTER_OBJECT_TYPE_INDEX: case FILTER_OBJECT_TYPE_TABLE: case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN: case FILTER_OBJECT_TYPE_TRIGGER:
pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"), "exclude",
filter_object_type_name(objtype));
exit_nicely(1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.