Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb08040

Browse files
committed
- no longer put ACLs at end of dump
- connect as appropriate user in pg_restore with db connection- dump owner of rule in pg_dump
1 parentcd9f0ca commitbb08040

File tree

6 files changed

+122
-147
lines changed

6 files changed

+122
-147
lines changed

‎src/bin/pg_dump/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.20 2000/07/21 11:40:08 pjw Exp $
7+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.21 2000/07/24 06:24:26 pjw Exp $
88
#
99
#-------------------------------------------------------------------------
1010

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ static int_tocSortCompareByIDNum(const void *p1, const void *p2);
4343
staticArchiveHandle*_allocAH(constchar*FileSpec,constArchiveFormatfmt,
4444
intcompression,ArchiveModemode);
4545
staticint_printTocEntry(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt);
46+
staticvoid_reconnectAsOwner(ArchiveHandle*AH,TocEntry*te);
47+
4648
staticint_tocEntryRequired(TocEntry*te,RestoreOptions*ropt);
4749
staticvoid_disableTriggers(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt);
4850
staticvoid_enableTriggers(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt);
@@ -153,6 +155,12 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
153155
/* Work out what, if anything, we want from this entry */
154156
reqs=_tocEntryRequired(te,ropt);
155157

158+
/* Reconnect if necessary */
159+
if (reqs!=0)
160+
{
161+
_reconnectAsOwner(AH,te);
162+
}
163+
156164
if ( (reqs&1)!=0)/* We want the schema */
157165
{
158166
ahlog(AH,1,"Creating %s %s\n",te->desc,te->name);
@@ -772,6 +780,14 @@ void ahlog(ArchiveHandle* AH, int level, const char *fmt, ...)
772780
va_end(ap);
773781
}
774782

783+
/*
784+
* Single place for logic which says 'We are restoring to a direct DB connection'.
785+
*/
786+
intRestoringToDB(ArchiveHandle*AH)
787+
{
788+
return (AH->ropt&&AH->ropt->useDB&&AH->connection);
789+
}
790+
775791
/*
776792
* Write buffer to the output file (usually stdout). This is user for
777793
* outputting 'restore' scripts etc. It is even possible for an archive
@@ -798,7 +814,7 @@ int ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle* AH)
798814
* If we're doing a restore, and it's direct to DB, and we're connected
799815
* then send it to the DB.
800816
*/
801-
if (AH->ropt&&AH->ropt->useDB&&AH->connection)
817+
if (RestoringToDB(AH))
802818
returnExecuteSqlCommandBuf(AH, (void*)ptr,size*nmemb);
803819
else
804820
returnfwrite((void*)ptr,size,nmemb,AH->OF);
@@ -1335,22 +1351,32 @@ static int _tocEntryRequired(TocEntry* te, RestoreOptions *ropt)
13351351
returnres;
13361352
}
13371353

1354+
staticvoid_reconnectAsOwner(ArchiveHandle*AH,TocEntry*te)
1355+
{
1356+
if (te->owner&&strlen(te->owner)!=0&&strcmp(AH->currUser,te->owner)!=0) {
1357+
if (RestoringToDB(AH))
1358+
{
1359+
ReconnectDatabase(AH,te->owner);
1360+
//todo pjw - ???? fix for db connection...
1361+
}
1362+
else
1363+
{
1364+
ahprintf(AH,"\\connect - %s\n",te->owner);
1365+
}
1366+
AH->currUser=te->owner;
1367+
}
1368+
}
1369+
13381370
staticint_printTocEntry(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt)
13391371
{
13401372
ahprintf(AH,"--\n-- TOC Entry ID %d (OID %s)\n--\n-- Name: %s Type: %s Owner: %s\n",
13411373
te->id,te->oid,te->name,te->desc,te->owner);
13421374
if (AH->PrintExtraTocPtr!=NULL) {
1343-
(*AH->PrintExtraTocPtr)(AH,te);
1375+
(*AH->PrintExtraTocPtr)(AH,te);
13441376
}
13451377
ahprintf(AH,"--\n\n");
13461378

1347-
if (te->owner&&strlen(te->owner)!=0&&strcmp(AH->currUser,te->owner)!=0) {
1348-
//todo pjw - fix for db connection...
1349-
//ahprintf(AH, "\\connect - %s\n", te->owner);
1350-
AH->currUser=te->owner;
1351-
}
1352-
1353-
ahprintf(AH,"%s\n",te->defn);
1379+
ahprintf(AH,"%s\n",te->defn);
13541380

13551381
return1;
13561382
}

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ extern int isValidTarHeader(char *header);
264264

265265
externOutputContextSetOutput(ArchiveHandle*AH,char*filename,intcompression);
266266
externvoidResetOutput(ArchiveHandle*AH,OutputContextsavedContext);
267+
externintRestoringToDB(ArchiveHandle*AH);
268+
externintReconnectDatabase(ArchiveHandle*AH,char*newUser);
267269

268270
intahwrite(constvoid*ptr,size_tsize,size_tnmemb,ArchiveHandle*AH);
269271
intahprintf(ArchiveHandle*AH,constchar*fmt, ...);

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,26 @@ _prompt_for_password(char *username, char *password)
4848
t;
4949
#endif
5050

51-
fprintf(stderr,"Username: ");
52-
fflush(stderr);
53-
fgets(username,100,stdin);
54-
length=strlen(username);
55-
/* skip rest of the line */
56-
if (length>0&&username[length-1]!='\n')
51+
/*
52+
* Allow for forcing a specific username
53+
*/
54+
if (strlen(username)==0)
5755
{
58-
do
56+
fprintf(stderr,"Username: ");
57+
fflush(stderr);
58+
fgets(username,100,stdin);
59+
length=strlen(username);
60+
/* skip rest of the line */
61+
if (length>0&&username[length-1]!='\n')
5962
{
60-
fgets(buf,512,stdin);
61-
}while (buf[strlen(buf)-1]!='\n');
63+
do
64+
{
65+
fgets(buf,512,stdin);
66+
}while (buf[strlen(buf)-1]!='\n');
67+
}
68+
if (length>0&&username[length-1]=='\n')
69+
username[length-1]='\0';
6270
}
63-
if (length>0&&username[length-1]=='\n')
64-
username[length-1]='\0';
6571

6672
#ifdefHAVE_TERMIOS_H
6773
tcgetattr(0,&t);
@@ -125,17 +131,69 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
125131
PQclear(res);
126132
}
127133

134+
intReconnectDatabase(ArchiveHandle*AH,char*newUser)
135+
{
136+
intneed_pass;
137+
PGconn*newConn;
138+
charpassword[100];
139+
char*pwparam=NULL;
140+
intbadPwd=0;
141+
intnoPwd=0;
142+
143+
ahlog(AH,1,"Connecting as %s\n",newUser);
144+
145+
do
146+
{
147+
need_pass= false;
148+
newConn=PQsetdbLogin(PQhost(AH->connection),PQport(AH->connection),
149+
NULL,NULL,PQdb(AH->connection),
150+
newUser,pwparam);
151+
if (!newConn)
152+
die_horribly(AH,"%s: Failed to reconnect (PQsetdbLogin failed).\n",progname);
153+
154+
if (PQstatus(newConn)==CONNECTION_BAD)
155+
{
156+
noPwd= (strcmp(PQerrorMessage(newConn),"fe_sendauth: no password supplied\n")==0);
157+
badPwd= (strncmp(PQerrorMessage(newConn),"Password authentication failed for user",39)
158+
==0);
159+
160+
if (noPwd||badPwd)
161+
{
162+
163+
if (badPwd)
164+
fprintf(stderr,"Password incorrect\n");
165+
166+
fprintf(stderr,"Connecting to %s as %s\n",PQdb(AH->connection),newUser);
167+
168+
need_pass= true;
169+
_prompt_for_password(newUser,password);
170+
pwparam=password;
171+
}
172+
else
173+
die_horribly(AH,"%s: Could not reconnect. %s\n",progname,PQerrorMessage(newConn));
174+
}
175+
176+
}while (need_pass);
177+
178+
PQfinish(AH->connection);
179+
AH->connection=newConn;
180+
strcpy(AH->username,newUser);
181+
182+
return1;
183+
}
184+
185+
128186
PGconn*ConnectDatabase(Archive*AHX,
129187
constchar*dbname,
130188
constchar*pghost,
131189
constchar*pgport,
132-
constintreqPwd,
133-
constintignoreVersion)
190+
constintreqPwd,
191+
constintignoreVersion)
134192
{
135193
ArchiveHandle*AH= (ArchiveHandle*)AHX;
136-
charconnect_string[512]="";
137-
chartmp_string[128];
138-
charpassword[100];
194+
charconnect_string[512]="";
195+
chartmp_string[128];
196+
charpassword[100];
139197

140198
if (AH->connection)
141199
die_horribly(AH,"%s: already connected to database\n",progname);
@@ -168,6 +226,7 @@ PGconn* ConnectDatabase(Archive *AHX,
168226

169227
if (reqPwd)
170228
{
229+
AH->username[0]='\0';
171230
_prompt_for_password(AH->username,password);
172231
strcat(connect_string,"authtype=password ");
173232
sprintf(tmp_string,"user=%s ",AH->username);
@@ -188,6 +247,8 @@ PGconn* ConnectDatabase(Archive *AHX,
188247
/* check for version mismatch */
189248
_check_database_version(AH,ignoreVersion);
190249

250+
AH->currUser=PQuser(AH->connection);
251+
191252
returnAH->connection;
192253
}
193254

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +0,0 @@
1-
/*-------------------------------------------------------------------------
2-
*
3-
* pg_backup_plain_text.c
4-
*
5-
*This file is copied from the 'custom' format file, but dumps data into
6-
*directly to a text file, and the TOC into the 'main' file.
7-
*
8-
*See the headers to pg_restore for more details.
9-
*
10-
* Copyright (c) 2000, Philip Warner
11-
* Rights are granted to use this software in any way so long
12-
* as this notice is not removed.
13-
*
14-
*The author is not responsible for loss or damages that may
15-
*result from it's use.
16-
*
17-
*
18-
* IDENTIFICATION
19-
*
20-
* Modifications - 01-Jul-2000 - pjw@rhyme.com.au
21-
*
22-
*Initial version.
23-
*
24-
*-------------------------------------------------------------------------
25-
*/
26-
27-
#include<stdlib.h>
28-
#include<string.h>
29-
#include<unistd.h>/* for dup */
30-
#include"pg_backup.h"
31-
#include"pg_backup_archiver.h"
32-
33-
staticvoid_ArchiveEntry(ArchiveHandle*AH,TocEntry*te);
34-
staticvoid_StartData(ArchiveHandle*AH,TocEntry*te);
35-
staticint_WriteData(ArchiveHandle*AH,constvoid*data,intdLen);
36-
staticvoid_EndData(ArchiveHandle*AH,TocEntry*te);
37-
staticint_WriteByte(ArchiveHandle*AH,constinti);
38-
staticint_WriteBuf(ArchiveHandle*AH,constvoid*buf,intlen);
39-
staticvoid_CloseArchive(ArchiveHandle*AH);
40-
staticvoid_PrintTocData(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt);
41-
42-
/*
43-
* Initializer
44-
*/
45-
voidInitArchiveFmt_PlainText(ArchiveHandle*AH)
46-
{
47-
/* Assuming static functions, this can be copied for each format. */
48-
AH->ArchiveEntryPtr=_ArchiveEntry;
49-
AH->StartDataPtr=_StartData;
50-
AH->WriteDataPtr=_WriteData;
51-
AH->EndDataPtr=_EndData;
52-
AH->WriteBytePtr=_WriteByte;
53-
AH->WriteBufPtr=_WriteBuf;
54-
AH->ClosePtr=_CloseArchive;
55-
AH->PrintTocDataPtr=_PrintTocData;
56-
57-
/*
58-
* Now prevent reading...
59-
*/
60-
if (AH->mode==archModeRead)
61-
die_horribly("%s: This format can not be read\n");
62-
63-
}
64-
65-
/*
66-
* - Start a new TOC entry
67-
*/
68-
staticvoid_ArchiveEntry(ArchiveHandle*AH,TocEntry*te)
69-
{
70-
/* Don't need to do anything */
71-
}
72-
73-
staticvoid_StartData(ArchiveHandle*AH,TocEntry*te)
74-
{
75-
ahprintf(AH,"--\n-- Data for TOC Entry ID %d (OID %s) %s %s\n--\n\n",
76-
te->id,te->oid,te->desc,te->name);
77-
}
78-
79-
staticint_WriteData(ArchiveHandle*AH,constvoid*data,intdLen)
80-
{
81-
ahwrite(data,1,dLen,AH);
82-
returndLen;
83-
}
84-
85-
staticvoid_EndData(ArchiveHandle*AH,TocEntry*te)
86-
{
87-
ahprintf(AH,"\n\n");
88-
}
89-
90-
/*
91-
* Print data for a given TOC entry
92-
*/
93-
staticvoid_PrintTocData(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt)
94-
{
95-
if (*te->dataDumper)
96-
(*te->dataDumper)((Archive*)AH,te->oid,te->dataDumperArg);
97-
}
98-
99-
staticint_WriteByte(ArchiveHandle*AH,constinti)
100-
{
101-
/* Don't do anything */
102-
return0;
103-
}
104-
105-
staticint_WriteBuf(ArchiveHandle*AH,constvoid*buf,intlen)
106-
{
107-
/* Don't do anything */
108-
returnlen;
109-
}
110-
111-
staticvoid_CloseArchive(ArchiveHandle*AH)
112-
{
113-
/* Nothing to do */
114-
}
115-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp