mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
> 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:
@ -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">
|
<refentry id="APP-PGRESTORE">
|
||||||
<refmeta>
|
<refmeta>
|
||||||
@ -129,6 +129,18 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</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>
|
<varlistentry>
|
||||||
<term><option>-f <replaceable>filename</replaceable></option></term>
|
<term><option>-f <replaceable>filename</replaceable></option></term>
|
||||||
<term><option>--file=<replaceable>filename</replaceable></option></term>
|
<term><option>--file=<replaceable>filename</replaceable></option></term>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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;
|
int maxRemoteVersion;
|
||||||
|
|
||||||
/* error handling */
|
/* 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) */
|
int n_errors; /* number of errors (if no die) */
|
||||||
|
|
||||||
/* The rest is private */
|
/* The rest is private */
|
||||||
@ -103,6 +103,7 @@ typedef struct _restoreOptions
|
|||||||
char *username;
|
char *username;
|
||||||
int ignoreVersion;
|
int ignoreVersion;
|
||||||
int requirePassword;
|
int requirePassword;
|
||||||
|
int exit_on_error;
|
||||||
|
|
||||||
bool *idWanted;
|
bool *idWanted;
|
||||||
bool limitToList;
|
bool limitToList;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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->format = archUnknown;
|
||||||
opts->suppressDumpWarnings = false;
|
opts->suppressDumpWarnings = false;
|
||||||
|
opts->exit_on_error = false;
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
@ -1227,7 +1228,7 @@ warn_or_die_horribly(ArchiveHandle *AH,
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
if (AH->public.die_on_errors)
|
if (AH->public.exit_on_error)
|
||||||
{
|
{
|
||||||
_die_horribly(AH, modulename, fmt, ap);
|
_die_horribly(AH, modulename, fmt, ap);
|
||||||
}
|
}
|
||||||
@ -1693,7 +1694,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* sql error handling */
|
/* sql error handling */
|
||||||
AH->public.die_on_errors = true;
|
AH->public.exit_on_error = true;
|
||||||
AH->public.n_errors = 0;
|
AH->public.n_errors = 0;
|
||||||
|
|
||||||
return AH;
|
return AH;
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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'},
|
{"create", 0, NULL, 'C'},
|
||||||
{"data-only", 0, NULL, 'a'},
|
{"data-only", 0, NULL, 'a'},
|
||||||
{"dbname", 1, NULL, 'd'},
|
{"dbname", 1, NULL, 'd'},
|
||||||
|
{"exit-on-error", 0, NULL, 'e'},
|
||||||
{"file", 1, NULL, 'f'},
|
{"file", 1, NULL, 'f'},
|
||||||
{"format", 1, NULL, 'F'},
|
{"format", 1, NULL, 'F'},
|
||||||
{"function", 1, NULL, 'P'},
|
{"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)
|
cmdopts, NULL)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -159,6 +160,9 @@ main(int argc, char **argv)
|
|||||||
case 'd':
|
case 'd':
|
||||||
opts->dbname = strdup(optarg);
|
opts->dbname = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
opts->exit_on_error = true;
|
||||||
|
break;
|
||||||
case 'f': /* output file name */
|
case 'f': /* output file name */
|
||||||
opts->filename = strdup(optarg);
|
opts->filename = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
@ -321,10 +325,10 @@ main(int argc, char **argv)
|
|||||||
/* Let the archiver know how noisy to be */
|
/* Let the archiver know how noisy to be */
|
||||||
AH->verbose = opts->verbose;
|
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)
|
if (opts->tocFile)
|
||||||
SortTocFromFile(AH, opts);
|
SortTocFromFile(AH, opts);
|
||||||
@ -391,6 +395,7 @@ usage(const char *progname)
|
|||||||
printf(_(" -p, --port=PORT database server port number\n"));
|
printf(_(" -p, --port=PORT database server port number\n"));
|
||||||
printf(_(" -U, --username=NAME connect as specified database user\n"));
|
printf(_(" -U, --username=NAME connect as specified database user\n"));
|
||||||
printf(_(" -W, --password force password prompt (should happen automatically)\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(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
|
||||||
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
|
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
|
||||||
|
Reference in New Issue
Block a user