> Please find attached a submission to add a "exit on error" option to
> pg_restore, as it seems that some people have scripts that rely on the > previous "abort on error" default behavior when restoring data with a > direct connection. > > Fabien Coelho
This commit is contained in:
parent
46be0c18f1
commit
daa076c4fd
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.47 2004/07/13 02:59:49 momjian Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.48 2004/08/20 04:20:22 momjian Exp $ -->
|
||||
|
||||
<refentry id="APP-PGRESTORE">
|
||||
<refmeta>
|
||||
@ -129,6 +129,18 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-e</option></term>
|
||||
<term><option>--exit-on-error</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Exit if an error is encountered while sending SQL commands to
|
||||
the database. The default is to continue and to display a count of
|
||||
errors at the end of the restoration.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-f <replaceable>filename</replaceable></option></term>
|
||||
<term><option>--file=<replaceable>filename</replaceable></option></term>
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.31 2004/07/13 03:00:17 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.32 2004/08/20 04:20:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -59,7 +59,7 @@ typedef struct _Archive
|
||||
int maxRemoteVersion;
|
||||
|
||||
/* error handling */
|
||||
bool die_on_errors; /* whether to die on sql errors... */
|
||||
bool exit_on_error; /* whether to exit on SQL errors... */
|
||||
int n_errors; /* number of errors (if no die) */
|
||||
|
||||
/* The rest is private */
|
||||
@ -103,6 +103,7 @@ typedef struct _restoreOptions
|
||||
char *username;
|
||||
int ignoreVersion;
|
||||
int requirePassword;
|
||||
int exit_on_error;
|
||||
|
||||
bool *idWanted;
|
||||
bool limitToList;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.92 2004/08/13 21:37:28 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.93 2004/08/20 04:20:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -457,6 +457,7 @@ NewRestoreOptions(void)
|
||||
|
||||
opts->format = archUnknown;
|
||||
opts->suppressDumpWarnings = false;
|
||||
opts->exit_on_error = false;
|
||||
|
||||
return opts;
|
||||
}
|
||||
@ -1227,7 +1228,7 @@ warn_or_die_horribly(ArchiveHandle *AH,
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if (AH->public.die_on_errors)
|
||||
if (AH->public.exit_on_error)
|
||||
{
|
||||
_die_horribly(AH, modulename, fmt, ap);
|
||||
}
|
||||
@ -1693,7 +1694,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
|
||||
}
|
||||
|
||||
/* sql error handling */
|
||||
AH->public.die_on_errors = true;
|
||||
AH->public.exit_on_error = true;
|
||||
AH->public.n_errors = 0;
|
||||
|
||||
return AH;
|
||||
|
@ -34,7 +34,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.59 2004/07/13 03:00:17 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.60 2004/08/20 04:20:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -90,6 +90,7 @@ main(int argc, char **argv)
|
||||
{"create", 0, NULL, 'C'},
|
||||
{"data-only", 0, NULL, 'a'},
|
||||
{"dbname", 1, NULL, 'd'},
|
||||
{"exit-on-error", 0, NULL, 'e'},
|
||||
{"file", 1, NULL, 'f'},
|
||||
{"format", 1, NULL, 'F'},
|
||||
{"function", 1, NULL, 'P'},
|
||||
@ -141,7 +142,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
while ((c = getopt_long(argc, argv, "acCd:f:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
|
||||
while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
|
||||
cmdopts, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
@ -159,6 +160,9 @@ main(int argc, char **argv)
|
||||
case 'd':
|
||||
opts->dbname = strdup(optarg);
|
||||
break;
|
||||
case 'e':
|
||||
opts->exit_on_error = true;
|
||||
break;
|
||||
case 'f': /* output file name */
|
||||
opts->filename = strdup(optarg);
|
||||
break;
|
||||
@ -321,10 +325,10 @@ main(int argc, char **argv)
|
||||
/* 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.
|
||||
/*
|
||||
* Whether to keep submitting sql commands as "pg_restore ... | psql ... "
|
||||
*/
|
||||
AH->die_on_errors = false;
|
||||
AH->exit_on_error = opts->exit_on_error;
|
||||
|
||||
if (opts->tocFile)
|
||||
SortTocFromFile(AH, opts);
|
||||
@ -391,6 +395,7 @@ usage(const char *progname)
|
||||
printf(_(" -p, --port=PORT database server port number\n"));
|
||||
printf(_(" -U, --username=NAME connect as specified database user\n"));
|
||||
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
|
||||
printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
|
||||
|
||||
printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
|
||||
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user