59{
62 int exit_code;
63 int numWorkers = 1;
65 char *inputFileSpec;
66 bool data_only = false;
67 bool schema_only = false;
69 static int enable_row_security = 0;
71 static int no_data_for_failed_tables = 0;
72 static int outputNoTableAm = 0;
73 static int outputNoTablespaces = 0;
88
89 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
122
124 {
"enable-row-security",
no_argument, &enable_row_security, 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},
147
148 {NULL, 0, NULL, 0}
149 };
150
154
156
158
160
161 if (argc > 1)
162 {
163 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
164 {
167 }
168 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
169 {
170 puts("pg_restore (PostgreSQL) " PG_VERSION);
172 }
173 }
174
175 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 {
179 {
180 case 'a':
181 data_only = true;
182 break;
183 case 'c':
184 opts->dropSchema = 1;
185 break;
186 case 'C':
188 break;
189 case 'd':
191 break;
192 case 'e':
193 opts->exit_on_error =
true;
194 break;
195 case 'f':
197 break;
198 case 'F':
201 break;
202 case 'h':
205 break;
206
207 case 'j':
210 &numWorkers))
211 exit(1);
212 break;
213
214 case 'l':
215 opts->tocSummary = 1;
216 break;
217
218 case 'L':
220 break;
221
222 case 'n':
224 break;
225
226 case 'N':
228 break;
229
230 case 'O':
232 break;
233
234 case 'p':
237 break;
238 case 'R':
239
240 break;
241 case 'P':
243 opts->selFunction = 1;
245 break;
246 case 'I':
250 break;
251 case 'T':
253 opts->selTrigger = 1;
255 break;
256 case 's':
257 schema_only = true;
258 break;
259 case 'S':
262 break;
263 case 't':
267 break;
268
269 case 'U':
271 break;
272
273 case 'v':
276 break;
277
278 case 'w':
280 break;
281
282 case 'W':
284 break;
285
286 case 'x':
288 break;
289
290 case '1':
291 opts->single_txn =
true;
292 opts->exit_on_error =
true;
293 break;
294
295 case 0:
296
297
298
299
300 break;
301
302 case 2:
304 break;
305
306 case 3:
308 break;
309
310 case 4:
312 break;
313
314 case 5:
316 1, INT_MAX,
318 exit(1);
319 opts->exit_on_error =
true;
320 break;
321
322 default:
323
326 }
327 }
328
329
331 inputFileSpec = argv[
optind++];
332 else
333 inputFileSpec = NULL;
334
335
337 {
338 pg_log_error(
"too many command-line arguments (first is \"%s\")",
342 }
343
344
345 if (!
opts->cparams.dbname && !
opts->filename && !
opts->tocSummary)
346 pg_fatal(
"one of -d/--dbname and -f/--file must be specified");
347
348
349 if (
opts->cparams.dbname)
350 {
352 {
353 pg_log_error(
"options -d/--dbname and -f/--file cannot be used together");
356 }
358 }
359
360
361 if (data_only && schema_only)
362 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
364 pg_fatal(
"options -s/--schema-only and --statistics-only cannot be used together");
366 pg_fatal(
"options -a/--data-only and --statistics-only cannot be used together");
367
368
370 pg_fatal(
"options -a/--data-only and --no-data cannot be used together");
372 pg_fatal(
"options -s/--schema-only and --no-schema cannot be used together");
374 pg_fatal(
"options --statistics-only and --no-statistics cannot be used together");
375
376
378 pg_fatal(
"options --with-data and --no-data cannot be used together");
380 pg_fatal(
"options --with-schema and --no-schema cannot be used together");
382 pg_fatal(
"options --with-statistics and --no-statistics cannot be used together");
383
384 if (data_only &&
opts->dropSchema)
385 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
386
387 if (
opts->single_txn &&
opts->txn_size > 0)
388 pg_fatal(
"options -1/--single-transaction and --transaction-size cannot be used together");
389
390
391
392
393
394 if (
opts->createDB &&
opts->single_txn)
395 pg_fatal(
"options -C/--create and -1/--single-transaction cannot be used together");
396
397
398 if (
opts->single_txn && numWorkers > 1)
399 pg_fatal(
"cannot specify both --single-transaction and multiple jobs");
400
401
402
403
404
405
406
407
412 opts->dumpStatistics = ((
opts->dumpStatistics && !schema_only && !data_only) ||
414
416 opts->enable_row_security = enable_row_security;
417 opts->noDataForFailedTables = no_data_for_failed_tables;
418 opts->noTableAm = outputNoTableAm;
419 opts->noTablespace = outputNoTablespaces;
426
428 pg_fatal(
"option --if-exists requires option -c/--clean");
431
432 if (
opts->formatName)
433 {
445 {
446
447 pg_fatal(
"archive format \"%s\" is not supported; please use psql",
449 }
450 else
451 pg_fatal(
"unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
453 }
454
456
458
459
460
461
462
463
465
466
468
469
470
471
473
476
478
479 if (
opts->tocSummary)
481 else
482 {
485 }
486
487
490
491
493
495
496 return exit_code;
497}
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)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void CloseArchive(Archive *AHX)
void SortTocFromFile(Archive *AHX)
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
void RestoreArchive(Archive *AHX)
void set_dump_section(const char *arg, int *dumpSections)
static int statistics_only
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
static int with_statistics
PGDLLIMPORT char * optarg
static void usage(const char *progname)
static void read_restore_filters(const char *filename, RestoreOptions *opts)
#define pg_log_warning(...)
int pg_strcasecmp(const char *s1, const char *s2)
const char * get_progname(const char *argv0)
void simple_string_list_append(SimpleStringList *list, const char *val)