*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.29 2004/03/24 03:06:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.30 2004/04/22 02:39:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int remoteVersion;
int minRemoteVersion;
int maxRemoteVersion;
+
+ /* error handling */
+ bool die_on_errors; /* whether to die on sql errors... */
+ int n_errors; /* number of errors (if no die) */
+
/* The rest is private */
} Archive;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.85 2004/03/24 03:06:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.86 2004/04/22 02:39:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
va_end(ap);
}
+/* on some error, we may decide to go on... */
+void
+warn_or_die_horribly(ArchiveHandle *AH,
+ const char *modulename, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ if (AH->public.die_on_errors)
+ {
+ _die_horribly(AH, modulename, fmt, ap);
+ }
+ else
+ {
+ _write_msg(modulename, fmt, ap);
+ AH->public.n_errors++;
+ }
+ va_end(ap);
+}
static void
_moveAfter(ArchiveHandle *AH, TocEntry *pos, TocEntry *te)
die_horribly(AH, modulename, "unrecognized file format \"%d\"\n", fmt);
}
+ /* sql error handling */
+ AH->public.die_on_errors = true;
+ AH->public.n_errors = 0;
+
return AH;
}
res = PQexec(AH->connection, cmd->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
+ /* NOT warn_or_die_horribly... use -O instead to skip this. */
die_horribly(AH, modulename, "could not set session user to \"%s\": %s",
user, PQerrorMessage(AH->connection));
res = PQexec(AH->connection, cmd->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
- die_horribly(AH, modulename, "could not set default_with_oids: %s",
- PQerrorMessage(AH->connection));
+ warn_or_die_horribly(AH, modulename,
+ "could not set default_with_oids: %s",
+ PQerrorMessage(AH->connection));
PQclear(res);
}
res = PQexec(AH->connection, qry->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
- die_horribly(AH, modulename, "could not set search_path to \"%s\": %s",
- schemaName, PQerrorMessage(AH->connection));
+ warn_or_die_horribly(AH, modulename,
+ "could not set search_path to \"%s\": %s",
+ schemaName, PQerrorMessage(AH->connection));
PQclear(res);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.57 2004/03/24 03:06:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.58 2004/04/22 02:39:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern const char *progname;
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
+extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
extern void write_msg(const char *modulename, const char *fmt,...) __attribute__((format(printf, 2, 3)));
extern void WriteTOC(ArchiveHandle *AH);
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.52 2004/03/03 21:28:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.53 2004/04/22 02:39:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
AH->pgCopyIn = 1;
}
else
- die_horribly(AH, modulename, "%s: %s",
- desc, PQerrorMessage(AH->connection));
+ warn_or_die_horribly(AH, modulename, "%s: %s",
+ desc, PQerrorMessage(AH->connection));
}
PQclear(res);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.55 2003/12/06 03:00:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.56 2004/04/22 02:39:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
RestoreOptions *opts;
int c;
+ int exit_code;
Archive *AH;
char *inputFileSpec;
extern int optind;
/* Let the archiver know how noisy to be */
AH->verbose = opts->verbose;
+ /* restore keeps submitting sql commands as "pg_restore ... | psql ... "
+ * this behavior choice could be turned into an option.
+ */
+ AH->die_on_errors = false;
+
if (opts->tocFile)
SortTocFromFile(AH, opts);
else
RestoreArchive(AH, opts);
+ /* done, print a summary of ignored errors */
+ if (AH->n_errors)
+ fprintf(stderr, _("WARNING, errors ignored on restore: %d\n"),
+ AH->n_errors);
+
+ /* AH may be freed in CloseArchive? */
+ exit_code = AH->n_errors? 1: 0;
+
CloseArchive(AH);
- return 0;
+ return exit_code;
}
static void