59{
62 int exit_code;
63 int numWorkers = 1;
65 char *inputFileSpec;
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;
80
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'},
111
112
113
114
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},
131
132 {NULL, 0, NULL, 0}
133 };
134
138
140
142
144
145 if (argc > 1)
146 {
147 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
148 {
151 }
152 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
153 {
154 puts("pg_restore (PostgreSQL) " PG_VERSION);
156 }
157 }
158
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)
161 {
163 {
164 case 'a':
165 data_only = true;
166 break;
167 case 'c':
168 opts->dropSchema = 1;
169 break;
170 case 'C':
172 break;
173 case 'd':
175 break;
176 case 'e':
177 opts->exit_on_error =
true;
178 break;
179 case 'f':
181 break;
182 case 'F':
185 break;
186 case 'h':
189 break;
190
191 case 'j':
194 &numWorkers))
196 break;
197
198 case 'l':
199 opts->tocSummary = 1;
200 break;
201
202 case 'L':
204 break;
205
206 case 'n':
208 break;
209
210 case 'N':
212 break;
213
214 case 'O':
216 break;
217
218 case 'p':
221 break;
222 case 'R':
223
224 break;
225 case 'P':
227 opts->selFunction = 1;
229 break;
230 case 'I':
234 break;
235 case 'T':
237 opts->selTrigger = 1;
239 break;
240 case 's':
241 schema_only = true;
242 break;
243 case 'S':
246 break;
247 case 't':
251 break;
252
253 case 'U':
255 break;
256
257 case 'v':
260 break;
261
262 case 'w':
264 break;
265
266 case 'W':
268 break;
269
270 case 'x':
272 break;
273
274 case '1':
275 opts->single_txn =
true;
276 opts->exit_on_error =
true;
277 break;
278
279 case 0:
280
281
282
283
284 break;
285
286 case 2:
288 break;
289
290 case 3:
292 break;
293
294 case 4:
296 break;
297
298 case 5:
300 1, INT_MAX,
303 opts->exit_on_error =
true;
304 break;
305
306 default:
307
310 }
311 }
312
313
315 inputFileSpec = argv[
optind++];
316 else
317 inputFileSpec = NULL;
318
319
321 {
322 pg_log_error(
"too many command-line arguments (first is \"%s\")",
326 }
327
328
329 if (!
opts->cparams.dbname && !
opts->filename && !
opts->tocSummary)
330 pg_fatal(
"one of -d/--dbname and -f/--file must be specified");
331
332
333 if (
opts->cparams.dbname)
334 {
336 {
337 pg_log_error(
"options -d/--dbname and -f/--file cannot be used together");
340 }
342 }
343
344 if (data_only && schema_only)
345 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
346
347 if (data_only &&
opts->dropSchema)
348 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
349
350 if (
opts->single_txn &&
opts->txn_size > 0)
351 pg_fatal(
"options -1/--single-transaction and --transaction-size cannot be used together");
352
353
354
355
356
357 if (
opts->createDB &&
opts->single_txn)
358 pg_fatal(
"options -C/--create and -1/--single-transaction cannot be used together");
359
360
361 if (
opts->single_txn && numWorkers > 1)
362 pg_fatal(
"cannot specify both --single-transaction and multiple jobs");
363
364
365 opts->dumpSchema = (!data_only);
366 opts->dumpData = (!schema_only);
367
369 opts->enable_row_security = enable_row_security;
370 opts->noDataForFailedTables = no_data_for_failed_tables;
371 opts->noTableAm = outputNoTableAm;
372 opts->noTablespace = outputNoTablespaces;
378
380 pg_fatal(
"option --if-exists requires option -c/--clean");
383
384 if (
opts->formatName)
385 {
386 switch (
opts->formatName[0])
387 {
388 case 'c':
389 case 'C':
391 break;
392
393 case 'd':
394 case 'D':
396 break;
397
398 case 't':
399 case 'T':
401 break;
402
403 default:
404 pg_fatal(
"unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
406 }
407 }
408
410
412
413
414
415
416
417
419
420
422
423
424
425
427
430
432
433 if (
opts->tocSummary)
435 else
436 {
439 }
440
441
444
445
447
449
450 return exit_code;
451}
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 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)
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)