<listitem>
<para>
Dump only the data, not the schema (data definitions).
+ Table data, large objects, and sequence values are dumped.
</para>
<para>
- This option is equivalent to specifying <option>--section=data</>.
+ This option is similar to, but for historical reasons not identical
+ to, specifying <option>--section=data</>.
</para>
</listitem>
</varlistentry>
Dump only the object definitions (schema), not data.
</para>
<para>
- To exclude table data for only a subset of tables in the database,
- see <option>--exclude-table-data</>.
+ This option is the inverse of <option>--data-only</>.
+ It is similar to, but for historical reasons not identical to,
+ specifying
+ <option>--section=pre-data --section=post-data</>.
</para>
<para>
- This option is equivalent to specifying
- <option>--section=pre-data --section=post-data</>.
+ (Do not confuse this with the <option>--schema</> option, which
+ uses the word <quote>schema</> in a different meaning.)
+ </para>
+ <para>
+ To exclude table data for only a subset of tables in the database,
+ see <option>--exclude-table-data</>.
</para>
</listitem>
</varlistentry>
<term><option>--section=<replaceable class="parameter">sectionname</replaceable></option></term>
<listitem>
<para>
- Only dump the named section. The name can be one of <option>pre-data</>, <option>data</>
- and <option>post-data</>.
- This option can be specified more than once. The default is to dump all sections.
+ Only dump the named section. The section name can be
+ <option>pre-data</>, <option>data</>, or <option>post-data</>.
+ This option can be specified more than once to select multiple
+ sections. The default is to dump all sections.
</para>
<para>
- Post-data items consist of definitions of indexes, triggers, rules
- and constraints other than validated check constraints.
- Pre-data items consist of all other data definition items.
+ The data section contains actual table data as well as large-object
+ definitions.
+ Post-data items consist of definitions of indexes, triggers, rules
+ and constraints other than validated check constraints.
+ Pre-data items consist of all other data definition items.
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Restore only the data, not the schema (data definitions).
+ Table data, large objects, and sequence values are restored,
+ if present in the archive.
</para>
+
<para>
- This option is equivalent to specifying <option>--section=data</>.
+ This option is similar to, but for historical reasons not identical
+ to, specifying <option>--section=data</>.
</para>
</listitem>
</varlistentry>
<term><option>--schema-only</option></term>
<listitem>
<para>
- Restore only the schema (data definitions), not the data (table
- contents). Current sequence values will not be restored, either.
- (Do not confuse this with the <option>--schema</> option, which
- uses the word <quote>schema</> in a different meaning.)
+ Restore only the schema (data definitions), not data,
+ to the extent that schema entries are present in the archive.
</para>
<para>
- This option is equivalent to specifying
+ This option is the inverse of <option>--data-only</>.
+ It is similar to, but for historical reasons not identical to,
+ specifying
<option>--section=pre-data --section=post-data</>.
</para>
+ <para>
+ (Do not confuse this with the <option>--schema</> option, which
+ uses the word <quote>schema</> in a different meaning.)
+ </para>
</listitem>
</varlistentry>
<term><option>--section=<replaceable class="parameter">sectionname</replaceable></option></term>
<listitem>
<para>
- Only restore the named section. The name can be one of <option>pre-data</>, <option>data</>
- and <option>post-data</>.
- This option can be specified more than once. The default is to restore all sections.
+ Only restore the named section. The section name can be
+ <option>pre-data</>, <option>data</>, or <option>post-data</>.
+ This option can be specified more than once to select multiple
+ sections. The default is to restore all sections.
</para>
<para>
- Post-data items consist of definitions of indexes, triggers, rules
- and constraints other than validated check constraints.
- Pre-data items consist of all other data definition items.
+ The data section contains actual table data as well as large-object
+ definitions.
+ Post-data items consist of definitions of indexes, triggers, rules
+ and constraints other than validated check constraints.
+ Pre-data items consist of all other data definition items.
</para>
</listitem>
</varlistentry>
#include <ctype.h>
#include "dumputils.h"
-#include "pg_backup.h"
#include "parser/keywords.h"
}
+/*
+ * Parse a --section=foo command line argument.
+ *
+ * Set or update the bitmask in *dumpSections according to arg.
+ * dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
+ * pg_restore so they can know if this has even been called.
+ */
+void
+set_dump_section(const char *arg, int *dumpSections)
+{
+ /* if this is the first call, clear all the bits */
+ if (*dumpSections == DUMP_UNSECTIONED)
+ *dumpSections = 0;
+
+ if (strcmp(arg,"pre-data") == 0)
+ *dumpSections |= DUMP_PRE_DATA;
+ else if (strcmp(arg,"data") == 0)
+ *dumpSections |= DUMP_DATA;
+ else if (strcmp(arg,"post-data") == 0)
+ *dumpSections |= DUMP_POST_DATA;
+ else
+ {
+ fprintf(stderr, _("%s: unknown section name \"%s\")\n"),
+ progname, arg);
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+ progname);
+ exit_nicely(1);
+ }
+}
+
+
/*
* Write a printf-style message to stderr.
*
exit_nicely(1);
}
-/*
- * Set the bitmask in dumpSections according to the first argument.
- * dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
- * pg_restore so they can know if this has even been called.
- */
-
-void
-set_section (const char *arg, int *dumpSections)
-{
- /* if this is the first, clear all the bits */
- if (*dumpSections == DUMP_UNSECTIONED)
- *dumpSections = 0;
-
- if (strcmp(arg,"pre-data") == 0)
- *dumpSections |= DUMP_PRE_DATA;
- else if (strcmp(arg,"data") == 0)
- *dumpSections |= DUMP_DATA;
- else if (strcmp(arg,"post-data") == 0)
- *dumpSections |= DUMP_POST_DATA;
- else
- {
- fprintf(stderr, _("%s: unknown section name \"%s\")\n"),
- progname, arg);
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
- progname);
- exit_nicely(1);
- }
-}
-
/* Register a callback to be run when exit_nicely is invoked. */
void
on_exit_nicely(on_exit_nicely_callback function, void *arg)
#include "libpq-fe.h"
#include "pqexpbuffer.h"
+typedef enum /* bits returned by set_dump_section */
+{
+ DUMP_PRE_DATA = 0x01,
+ DUMP_DATA = 0x02,
+ DUMP_POST_DATA = 0x04,
+ DUMP_UNSECTIONED = 0xff
+} DumpSections;
+
+typedef void (*on_exit_nicely_callback) (int code, void *arg);
+
extern int quote_all_identifiers;
extern const char *progname;
uint32 objectId, PQExpBuffer sql);
extern void emitShSecLabels(PGconn *conn, PGresult *res,
PQExpBuffer buffer, const char *target, const char *objname);
+extern void set_dump_section(const char *arg, int *dumpSections);
extern void write_msg(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
extern void vwrite_msg(const char *modulename, const char *fmt, va_list ap)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
extern void exit_horribly(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
-extern void set_section (const char *arg, int *dumpSections);
-
-typedef void (*on_exit_nicely_callback) (int code, void *arg);
extern void on_exit_nicely(on_exit_nicely_callback function, void *arg);
extern void exit_nicely(int code) __attribute__((noreturn));
SECTION_POST_DATA /* stuff to be processed after data */
} teSection;
-typedef enum
-{
- DUMP_PRE_DATA = 0x01,
- DUMP_DATA = 0x02,
- DUMP_POST_DATA = 0x04,
- DUMP_UNSECTIONED = 0xff
-} DumpSections;
-
/*
* We may want to have some more user-readable data, but in the mean
* time this gives us some abstraction and type checking.
int no_security_labels; /* Skip security label entries */
char *superuser; /* Username to use as superuser */
char *use_role; /* Issue SET ROLE to this */
- int dataOnly;
int dropSchema;
const char *filename;
+ int dataOnly;
int schemaOnly;
int dumpSections;
int verbose;
extern void CloseArchive(Archive *AH);
-extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
+extern void SetArchiveRestoreOptions(Archive *AH, RestoreOptions *ropt);
+
+extern void RestoreArchive(Archive *AH);
/* Open an existing archive */
extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
/* Rearrange and filter TOC entries */
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
-extern void InitDummyWantedList(Archive *AHX, RestoreOptions *ropt);
/* Convenience functions used only when writing DATA */
extern int archputs(const char *s, Archive *AH);
static void _selectTablespace(ArchiveHandle *AH, const char *tablespace);
static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te);
static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te);
-static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls);
+static teReqs _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt);
static bool _tocEntryIsACL(TocEntry *te);
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
/* Public */
void
-RestoreArchive(Archive *AHX, RestoreOptions *ropt)
+SetArchiveRestoreOptions(Archive *AHX, RestoreOptions *ropt)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
+ TocEntry *te;
+ teSection curSection;
+
+ /* Save options for later access */
+ AH->ropt = ropt;
+
+ /* Decide which TOC entries will be dumped/restored, and mark them */
+ curSection = SECTION_PRE_DATA;
+ for (te = AH->toc->next; te != AH->toc; te = te->next)
+ {
+ if (te->section != SECTION_NONE)
+ curSection = te->section;
+ te->reqs = _tocEntryRequired(te, curSection, ropt);
+ }
+}
+
+/* Public */
+void
+RestoreArchive(Archive *AHX)
+{
+ ArchiveHandle *AH = (ArchiveHandle *) AHX;
+ RestoreOptions *ropt = AH->ropt;
bool parallel_mode;
TocEntry *te;
- teReqs reqs;
OutputContext sav;
- AH->ropt = ropt;
AH->stage = STAGE_INITIALIZING;
/*
{
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
- reqs = _tocEntryRequired(te, ropt, false);
- if (te->hadDumper && (reqs & REQ_DATA) != 0)
+ if (te->hadDumper && (te->reqs & REQ_DATA) != 0)
exit_horribly(modulename, "cannot restore from compressed archive (compression not supported in this installation)\n");
}
}
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
- reqs = _tocEntryRequired(te, ropt, true);
- if ((reqs & REQ_SCHEMA) != 0)
+ if ((te->reqs & REQ_SCHEMA) != 0)
{ /* It's schema, and it's wanted */
impliedDataOnly = 0;
break;
{
AH->currentTE = te;
- reqs = _tocEntryRequired(te, ropt, false /* needn't drop ACLs */ );
/* We want anything that's selected and has a dropStmt */
- if (((reqs & (REQ_SCHEMA | REQ_DATA)) != 0) && te->dropStmt)
+ if (((te->reqs & (REQ_SCHEMA | REQ_DATA)) != 0) && te->dropStmt)
{
ahlog(AH, 1, "dropping %s %s\n", te->desc, te->tag);
/* Select owner and schema as necessary */
{
AH->currentTE = te;
- /* Work out what, if anything, we want from this entry */
- reqs = _tocEntryRequired(te, ropt, true);
-
/* Both schema and data objects might now have ownership/ACLs */
- if ((reqs & (REQ_SCHEMA | REQ_DATA)) != 0)
+ if ((te->reqs & (REQ_SCHEMA | REQ_DATA)) != 0)
{
ahlog(AH, 1, "setting owner and privileges for %s %s\n",
te->desc, te->tag);
AH->currentTE = te;
/* Work out what, if anything, we want from this entry */
- reqs = _tocEntryRequired(te, ropt, false);
+ if (_tocEntryIsACL(te))
+ reqs = 0; /* ACLs are never restored here */
+ else
+ reqs = te->reqs;
+
+ /*
+ * Ignore DATABASE entry unless we should create it. We must check this
+ * here, not in _tocEntryRequired, because the createDB option should
+ * not affect emitting a DATABASE entry to an archive file.
+ */
+ if (!ropt->createDB && strcmp(te->desc, "DATABASE") == 0)
+ reqs = 0;
/* Dump any relevant dump warnings to stderr */
if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0)
/*
* If we can output the data, then restore it.
*/
- if (AH->PrintTocDataPtr !=NULL && (reqs & REQ_DATA) != 0)
+ if (AH->PrintTocDataPtr !=NULL)
{
_printTocEntry(AH, te, ropt, true, false);
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
TocEntry *te;
+ teSection curSection;
OutputContext sav;
- char *fmtName;
+ const char *fmtName;
sav = SaveOutput(AH);
if (ropt->filename)
/* We should print DATABASE entries whether or not -C was specified */
ropt->createDB = 1;
+ curSection = SECTION_PRE_DATA;
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
- if (ropt->verbose || _tocEntryRequired(te, ropt, true) != 0)
+ if (te->section != SECTION_NONE)
+ curSection = te->section;
+ if (ropt->verbose ||
+ (_tocEntryRequired(te, curSection, ropt) & (REQ_SCHEMA | REQ_DATA)) != 0)
ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId,
te->catalogId.tableoid, te->catalogId.oid,
te->desc, te->namespace ? te->namespace : "-",
strerror(errno));
}
-/*
- * Set up a dummy ID filter that selects all dump IDs
- */
-void
-InitDummyWantedList(Archive *AHX, RestoreOptions *ropt)
-{
- ArchiveHandle *AH = (ArchiveHandle *) AHX;
-
- /* Allocate space for the 'wanted' array, and init it to 1's */
- ropt->idWanted = (bool *) pg_malloc(sizeof(bool) * AH->maxDumpId);
- memset(ropt->idWanted, 1, sizeof(bool) * AH->maxDumpId);
-}
-
/**********************
* 'Convenience functions that look like standard IO functions
* for writing data when in dump mode.
}
teReqs
-TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt)
+TocIDRequired(ArchiveHandle *AH, DumpId id)
{
TocEntry *te = getTocEntryByDumpId(AH, id);
if (!te)
return 0;
- return _tocEntryRequired(te, ropt, true);
+ return te->reqs;
}
size_t
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
- if (te->dataDumper != NULL)
+ if (te->dataDumper != NULL && (te->reqs & REQ_DATA) != 0)
{
AH->currToc = te;
/* printf("Writing data for %d (%x)\n", te->id, te); */
{
TocEntry *te;
char workbuf[32];
+ int tocCount;
int i;
- /* printf("%d TOC Entries to save\n", AH->tocCount); */
+ /* count entries that will actually be dumped */
+ tocCount = 0;
+ for (te = AH->toc->next; te != AH->toc; te = te->next)
+ {
+ if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) != 0)
+ tocCount++;
+ }
+
+ /* printf("%d TOC Entries to save\n", tocCount); */
- WriteInt(AH, AH->tocCount);
+ WriteInt(AH, tocCount);
for (te = AH->toc->next; te != AH->toc; te = te->next)
{
+ if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) == 0)
+ continue;
+
WriteInt(AH, te->dumpId);
WriteInt(AH, te->dataDumper ? 1 : 0);
int depIdx;
int depSize;
TocEntry *te;
- bool in_post_data = false;
AH->tocCount = ReadInt(AH);
AH->maxDumpId = 0;
te->section = SECTION_PRE_DATA;
}
- /* will stay true even for SECTION_NONE items */
- if (te->section == SECTION_POST_DATA)
- in_post_data = true;
-
- te->inPostData = in_post_data;
-
te->defn = ReadStr(AH);
te->dropStmt = ReadStr(AH);
}
static teReqs
-_tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
+_tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
{
- teReqs res = REQ_ALL;
+ teReqs res = REQ_SCHEMA | REQ_DATA;
- /* ENCODING and STDSTRINGS items are dumped specially, so always reject */
+ /* ENCODING and STDSTRINGS items are treated specially */
if (strcmp(te->desc, "ENCODING") == 0 ||
strcmp(te->desc, "STDSTRINGS") == 0)
- return 0;
+ return REQ_SPECIAL;
/* If it's an ACL, maybe ignore it */
- if ((!include_acls || ropt->aclsSkip) && _tocEntryIsACL(te))
+ if (ropt->aclsSkip && _tocEntryIsACL(te))
return 0;
/* If it's security labels, maybe ignore it */
if (ropt->no_security_labels && strcmp(te->desc, "SECURITY LABEL") == 0)
return 0;
- /* Ignore DATABASE entry unless we should create it */
- if (!ropt->createDB && strcmp(te->desc, "DATABASE") == 0)
- return 0;
-
- /* skip (all but) post data section as required */
- /* table data is filtered if necessary lower down */
- if (ropt->dumpSections != DUMP_UNSECTIONED)
+ /* Ignore it if section is not to be dumped/restored */
+ switch (curSection)
{
- if (!(ropt->dumpSections & DUMP_POST_DATA) && te->inPostData)
- return 0;
- if (!(ropt->dumpSections & DUMP_PRE_DATA) && ! te->inPostData && strcmp(te->desc, "TABLE DATA") != 0)
+ case SECTION_PRE_DATA:
+ if (!(ropt->dumpSections & DUMP_PRE_DATA))
+ return 0;
+ break;
+ case SECTION_DATA:
+ if (!(ropt->dumpSections & DUMP_DATA))
+ return 0;
+ break;
+ case SECTION_POST_DATA:
+ if (!(ropt->dumpSections & DUMP_POST_DATA))
+ return 0;
+ break;
+ default:
+ /* shouldn't get here, really, but ignore it */
return 0;
}
-
/* Check options for selective dump/restore */
if (ropt->schemaNames)
{
if (ropt->schemaOnly)
res = res & REQ_SCHEMA;
- /* Mask it we only want data */
+ /* Mask it if we only want data */
if (ropt->dataOnly)
res = res & REQ_DATA;
{
if (next_work_item != NULL)
{
- teReqs reqs;
-
- /* If not to be dumped, don't waste time launching a worker */
- reqs = _tocEntryRequired(next_work_item, AH->ropt, false);
- if ((reqs & (REQ_SCHEMA | REQ_DATA)) == 0)
+ /* If not to be restored, don't waste time launching a worker */
+ if ((next_work_item->reqs & (REQ_SCHEMA | REQ_DATA)) == 0 ||
+ _tocEntryIsACL(next_work_item))
{
ahlog(AH, 1, "skipping item %d %s %s\n",
next_work_item->dumpId,
static void
inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te)
{
- RestoreOptions *ropt = AH->ropt;
-
ahlog(AH, 1, "table \"%s\" could not be created, will not restore its data\n",
te->tag);
if (AH->tableDataId[te->dumpId] != 0)
{
- /* mark it unwanted; we assume idWanted array already exists */
- ropt->idWanted[AH->tableDataId[te->dumpId] - 1] = false;
+ TocEntry *ted = AH->tocsByDumpId[AH->tableDataId[te->dumpId]];
+
+ ted->reqs = 0;
}
}
typedef enum
{
- REQ_SCHEMA = 1,
- REQ_DATA = 2,
- REQ_ALL = REQ_SCHEMA + REQ_DATA
+ REQ_SCHEMA = 0x01, /* want schema */
+ REQ_DATA = 0x02, /* want data */
+ REQ_SPECIAL = 0x04 /* for special TOC entries */
} teReqs;
typedef struct _archiveHandle
void *dataDumperArg; /* Arg for above routine */
void *formatData; /* TOC Entry data specific to file format */
- /* in post data? not quite the same as section, might be SECTION_NONE */
- bool inPostData;
+ /* working state while dumping/restoring */
+ teReqs reqs; /* do we need schema and/or data of object */
+ bool created; /* set for DATA member if TABLE was created */
/* working state (needed only for parallel restore) */
struct _tocEntry *par_prev; /* list links for pending/ready items; */
struct _tocEntry *par_next; /* these are NULL if not in either list */
- bool created; /* set for DATA member if TABLE was created */
int depCount; /* number of dependencies not yet restored */
DumpId *revDeps; /* dumpIds of objects depending on this one */
int nRevDeps; /* number of such dependencies */
extern void ReadToc(ArchiveHandle *AH);
extern void WriteDataChunks(ArchiveHandle *AH);
-extern teReqs TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt);
+extern teReqs TocIDRequired(ArchiveHandle *AH, DumpId id);
extern bool checkSeek(FILE *fp);
#define appendStringLiteralAHX(buf,str,AH) \
lclContext *ctx = (lclContext *) AH->formatData;
TAR_MEMBER *th;
RestoreOptions *ropt;
+ RestoreOptions *savRopt;
int savVerbose,
i;
ctx->scriptTH = th;
ropt = NewRestoreOptions();
+ memcpy(ropt, AH->ropt, sizeof(RestoreOptions));
ropt->dropSchema = 1;
ropt->compression = 0;
ropt->superuser = NULL;
ropt->suppressDumpWarnings = true;
+ savRopt = AH->ropt;
+ AH->ropt = ropt;
+
savVerbose = AH->public.verbose;
AH->public.verbose = 0;
- RestoreArchive((Archive *) AH, ropt);
+ RestoreArchive((Archive *) AH);
+ AH->ropt = savRopt;
AH->public.verbose = savVerbose;
tarClose(AH, th);
ahlog(AH, 4, "skipping tar member %s\n", th->targetFile);
id = atoi(th->targetFile);
- if ((TocIDRequired(AH, id, AH->ropt) & REQ_DATA) != 0)
+ if ((TocIDRequired(AH, id) & REQ_DATA) != 0)
exit_horribly(modulename, "restoring data out of order is not supported in this archive format: "
"\"%s\" is required, but comes before \"%s\" in the archive file.\n",
th->targetFile, filename);
/* various user-settable parameters */
bool schemaOnly;
bool dataOnly;
-int dumpSections; /* bitmask of chosen sections */
+int dumpSections; /* bitmask of chosen sections */
bool aclsSkip;
const char *lockWaitTimeout;
static const char *fmtCopyColumnList(const TableInfo *ti);
static PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query);
+
int
main(int argc, char **argv)
{
break;
case 5: /* section */
- set_section(optarg, &dumpSections);
+ set_dump_section(optarg, &dumpSections);
break;
default:
if (dataOnly && schemaOnly)
exit_horribly(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
- if ((dataOnly || schemaOnly) && dumpSections != DUMP_UNSECTIONED)
- exit_horribly(NULL, "options -s/--schema-only and -a/--data-only cannot be used with --section\n");
-
- if (dataOnly)
- dumpSections = DUMP_DATA;
- else if (schemaOnly)
- dumpSections = DUMP_PRE_DATA | DUMP_POST_DATA;
- else if ( dumpSections != DUMP_UNSECTIONED)
- {
- dataOnly = dumpSections == DUMP_DATA;
- schemaOnly = !(dumpSections & DUMP_DATA);
- }
-
if (dataOnly && outputClean)
exit_horribly(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
dumpDumpableObject(fout, dobjs[i]);
/*
- * And finally we can do the actual output.
+ * Set up options info to ensure we dump what we want.
*/
- if (plainText)
- {
- ropt = NewRestoreOptions();
- ropt->filename = filename;
- ropt->dropSchema = outputClean;
- ropt->aclsSkip = aclsSkip;
- ropt->superuser = outputSuperuser;
- ropt->createDB = outputCreateDB;
- ropt->noOwner = outputNoOwner;
- ropt->noTablespace = outputNoTablespaces;
- ropt->disable_triggers = disable_triggers;
- ropt->use_setsessauth = use_setsessauth;
- ropt->dataOnly = dataOnly;
-
- if (compressLevel == -1)
- ropt->compression = 0;
- else
- ropt->compression = compressLevel;
+ ropt = NewRestoreOptions();
+ ropt->filename = filename;
+ ropt->dropSchema = outputClean;
+ ropt->dataOnly = dataOnly;
+ ropt->schemaOnly = schemaOnly;
+ ropt->dumpSections = dumpSections;
+ ropt->aclsSkip = aclsSkip;
+ ropt->superuser = outputSuperuser;
+ ropt->createDB = outputCreateDB;
+ ropt->noOwner = outputNoOwner;
+ ropt->noTablespace = outputNoTablespaces;
+ ropt->disable_triggers = disable_triggers;
+ ropt->use_setsessauth = use_setsessauth;
- ropt->suppressDumpWarnings = true; /* We've already shown them */
+ if (compressLevel == -1)
+ ropt->compression = 0;
+ else
+ ropt->compression = compressLevel;
- RestoreArchive(fout, ropt);
- }
+ ropt->suppressDumpWarnings = true; /* We've already shown them */
+
+ SetArchiveRestoreOptions(fout, ropt);
+
+ /*
+ * And finally we can do the actual output.
+ *
+ * Note: for non-plain-text output formats, the output file is written
+ * inside CloseArchive(). This is, um, bizarre; but not worth changing
+ * right now.
+ */
+ if (plainText)
+ RestoreArchive(fout);
CloseArchive(fout);
static void
dumpDumpableObject(Archive *fout, DumpableObject *dobj)
{
-
- bool skip = false;
-
- switch (dobj->objType)
- {
- case DO_INDEX:
- case DO_TRIGGER:
- case DO_CONSTRAINT:
- case DO_FK_CONSTRAINT:
- case DO_RULE:
- skip = !(dumpSections & DUMP_POST_DATA);
- break;
- case DO_TABLE_DATA:
- skip = !(dumpSections & DUMP_DATA);
- break;
- default:
- skip = !(dumpSections & DUMP_PRE_DATA);
- }
-
- if (skip)
- return;
-
switch (dobj->objType)
{
case DO_NAMESPACE:
break;
case 3: /* section */
- set_section(optarg, &(opts->dumpSections));
+ set_dump_section(optarg, &(opts->dumpSections));
break;
default:
exit_nicely(1);
}
- if (opts->dataOnly && opts->schemaOnly)
- {
- fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used together\n"),
- progname);
- exit_nicely(1);
- }
-
- if ((opts->dataOnly || opts->schemaOnly) && (opts->dumpSections != DUMP_UNSECTIONED))
- {
- fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used with --section\n"),
- progname);
- exit_nicely(1);
- }
-
- if (opts->dataOnly)
- opts->dumpSections = DUMP_DATA;
- else if (opts->schemaOnly)
- opts->dumpSections = DUMP_PRE_DATA | DUMP_POST_DATA;
- else if ( opts->dumpSections != DUMP_UNSECTIONED)
- {
- opts->dataOnly = opts->dumpSections == DUMP_DATA;
- opts->schemaOnly = !(opts->dumpSections & DUMP_DATA);
- }
-
/* Should get at most one of -d and -f, else user is confused */
if (opts->dbname)
{
if (opts->tocFile)
SortTocFromFile(AH, opts);
- else if (opts->noDataForFailedTables)
- {
- /*
- * we implement this option by clearing idWanted entries, so must
- * create a dummy idWanted array if there wasn't a tocFile
- */
- InitDummyWantedList(AH, opts);
- }
if (opts->tocSummary)
PrintTOCSummary(AH, opts);
else
- RestoreArchive(AH, opts);
+ {
+ SetArchiveRestoreOptions(AH, opts);
+ RestoreArchive(AH);
+ }
/* done, print a summary of ignored errors */
if (AH->n_errors)