@@ -61,6 +61,7 @@ extern int optind;
61
61
62
62
63
63
static void usage (const char * progname );
64
+ static void set_section (int * dumpSections , const char * arg );
64
65
65
66
typedef struct option optType ;
66
67
@@ -116,6 +117,7 @@ main(int argc, char **argv)
116
117
{"no-data-for-failed-tables" , no_argument , & no_data_for_failed_tables , 1 },
117
118
{"no-tablespaces" , no_argument , & outputNoTablespaces , 1 },
118
119
{"role" , required_argument , NULL , 2 },
120
+ {"section" , required_argument , NULL , 3 },
119
121
{"use-set-session-authorization" , no_argument , & use_setsessauth , 1 },
120
122
{"no-security-labels" , no_argument , & no_security_labels , 1 },
121
123
@@ -270,6 +272,10 @@ main(int argc, char **argv)
270
272
opts -> use_role = optarg ;
271
273
break ;
272
274
275
+ case 3 : /* section */
276
+ set_section (& (opts -> dumpSections ), optarg );
277
+ break ;
278
+
273
279
default :
274
280
fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
275
281
exit (1 );
@@ -292,6 +298,33 @@ main(int argc, char **argv)
292
298
exit (1 );
293
299
}
294
300
301
+ if (opts -> dataOnly && opts -> schemaOnly )
302
+ {
303
+ fprintf (stderr , _ ("%s: options -s/--schema-only and -a/--data-only cannot be used together\n" ),
304
+ progname );
305
+ exit (1 );
306
+ }
307
+
308
+ if ((opts -> dataOnly || opts -> schemaOnly ) && (opts -> dumpSections != DUMP_UNSECTIONED ))
309
+ {
310
+ fprintf (stderr , _ ("%s: options -s/--schema-only and -a/--data-only cannot be used with --section\n" ),
311
+ progname );
312
+ exit (1 );
313
+ }
314
+
315
+ if (opts -> dataOnly )
316
+ opts -> dumpSections = DUMP_DATA ;
317
+ else if (opts -> schemaOnly )
318
+ opts -> dumpSections = DUMP_PRE_DATA | DUMP_POST_DATA ;
319
+ else if ( opts -> dumpSections != DUMP_UNSECTIONED )
320
+ {
321
+ opts -> dataOnly = opts -> dumpSections == DUMP_DATA ;
322
+ opts -> schemaOnly = !(opts -> dumpSections & DUMP_DATA );
323
+ }
324
+
325
+
326
+ fprintf (stderr ,"dumpsection: %d, dataOnly: %d, schemaOnly: %d\n" , opts -> dumpSections , opts -> dataOnly , opts -> schemaOnly );
327
+
295
328
/* Should get at most one of -d and -f, else user is confused */
296
329
if (opts -> dbname )
297
330
{
@@ -432,6 +465,7 @@ usage(const char *progname)
432
465
" created\n" ));
433
466
printf (_ (" --no-security-labels do not restore security labels\n" ));
434
467
printf (_ (" --no-tablespaces do not restore tablespace assignments\n" ));
468
+ printf (_ (" --section=SECTION restore named section (pre-data, data or post-data)\n" ));
435
469
printf (_ (" --use-set-session-authorization\n"
436
470
" use SET SESSION AUTHORIZATION commands instead of\n"
437
471
" ALTER OWNER commands to set ownership\n" ));
@@ -447,3 +481,26 @@ usage(const char *progname)
447
481
printf (_ ("\nIf no input file name is supplied, then standard input is used.\n\n" ));
448
482
printf (
_ (
"Report bugs to <[email protected] >.\n" ));
449
483
}
484
+
485
+ static void
486
+ set_section (int * dumpSections , const char * arg )
487
+ {
488
+ /* if this is the first, clear all the bits */
489
+ if (* dumpSections == DUMP_UNSECTIONED )
490
+ * dumpSections = 0 ;
491
+
492
+ if (strcmp (arg ,"pre-data" ) == 0 )
493
+ * dumpSections |= DUMP_PRE_DATA ;
494
+ else if (strcmp (arg ,"data" ) == 0 )
495
+ * dumpSections |= DUMP_DATA ;
496
+ else if (strcmp (arg ,"post-data" ) == 0 )
497
+ * dumpSections |= DUMP_POST_DATA ;
498
+ else
499
+ {
500
+ fprintf (stderr , _ ("%s: unknown section name \"%s\")\n" ),
501
+ progname , arg );
502
+ fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ),
503
+ progname );
504
+ exit (1 );
505
+ }
506
+ }
0 commit comments