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

Commit4f163d8

Browse files
committed
Make pg_control file optional for restore.
1 parent375d915 commit4f163d8

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

‎backup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
107107
* obtained at output of pg_start_backup or pg_stop_backup does
108108
* not contain this information.
109109
*/
110-
current.tli=get_current_timeline();
110+
current.tli=get_current_timeline(false);
111111

112112
/*
113113
* In differential backup mode, check if there is an already-validated
@@ -567,7 +567,7 @@ wait_for_archive(pgBackup *backup, const char *sql)
567567
* Enforce TLI obtention if backup is not present as this code
568568
* path can be taken as a callback at exit.
569569
*/
570-
tli=get_current_timeline();
570+
tli=get_current_timeline(false);
571571

572572
/* Fill in fields if backup exists */
573573
if (backup!=NULL)

‎fetch.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
*/
3535
char*
36-
slurpFile(constchar*datadir,constchar*path,size_t*filesize)
36+
slurpFile(constchar*datadir,constchar*path,size_t*filesize,boolsafe)
3737
{
3838
intfd;
3939
char*buffer;
@@ -43,20 +43,35 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
4343
snprintf(fullpath,sizeof(fullpath),"%s/%s",datadir,path);
4444

4545
if ((fd=open(fullpath,O_RDONLY |PG_BINARY,0))==-1)
46-
elog(ERROR,"could not open file \"%s\" for reading: %s",
47-
fullpath,strerror(errno));
46+
{
47+
if (safe)
48+
returnNULL;
49+
else
50+
elog(ERROR,"could not open file \"%s\" for reading: %s",
51+
fullpath,strerror(errno));
52+
}
4853

4954
if (fstat(fd,&statbuf)<0)
50-
elog(ERROR,"could not open file \"%s\" for reading: %s",
51-
fullpath,strerror(errno));
55+
{
56+
if (safe)
57+
returnNULL;
58+
else
59+
elog(ERROR,"could not open file \"%s\" for reading: %s",
60+
fullpath,strerror(errno));
61+
}
5262

5363
len=statbuf.st_size;
5464

5565
buffer=pg_malloc(len+1);
5666

5767
if (read(fd,buffer,len)!=len)
58-
elog(ERROR,"could not read file \"%s\": %s\n",
59-
fullpath,strerror(errno));
68+
{
69+
if (safe)
70+
returnNULL;
71+
else
72+
elog(ERROR,"could not read file \"%s\": %s\n",
73+
fullpath,strerror(errno));
74+
}
6075

6176
close(fd);
6277

‎pg_arman.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ extern void pgBackupDelete(int keep_generations, int keep_days);
231231
/* in fetch.c */
232232
externchar*slurpFile(constchar*datadir,
233233
constchar*path,
234-
size_t*filesize);
234+
size_t*filesize,
235+
boolsafe);
235236

236237
/* in validate.c */
237238
externintdo_validate(pgBackupRange*range);
@@ -291,7 +292,7 @@ extern void extractPageMap(const char *datadir, XLogRecPtr startpoint,
291292
TimeLineIDtli,XLogRecPtrendpoint);
292293

293294
/* in util.c */
294-
externTimeLineIDget_current_timeline(void);
295+
externTimeLineIDget_current_timeline(boolsafe);
295296
externvoidsanityChecks(void);
296297
externvoidtime2iso(char*buf,size_tlen,time_ttime);
297298
externconstchar*status2str(BackupStatusstatus);

‎restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ do_restore(const char *target_time,
9898
if (!backups)
9999
elog(ERROR,"cannot process any more.");
100100

101-
cur_tli=get_current_timeline();
101+
cur_tli=get_current_timeline(true);
102102
backup_tli=get_fullbackup_timeline(backups,rt);
103103

104104
/* determine target timeline */

‎util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ sanityChecks(void)
6060
size_tsize;
6161

6262
/* First fetch file... */
63-
buffer=slurpFile(pgdata,"global/pg_control",&size);
63+
buffer=slurpFile(pgdata,"global/pg_control",&size, false);
6464
digestControlFile(&ControlFile,buffer,size);
6565
pg_free(buffer);
6666

@@ -80,14 +80,16 @@ sanityChecks(void)
8080
* used by a node.
8181
*/
8282
TimeLineID
83-
get_current_timeline(void)
83+
get_current_timeline(boolsafe)
8484
{
8585
ControlFileDataControlFile;
8686
char*buffer;
8787
size_tsize;
8888

8989
/* First fetch file... */
90-
buffer=slurpFile(pgdata,"global/pg_control",&size);
90+
buffer=slurpFile(pgdata,"global/pg_control",&size,safe);
91+
if (buffer==NULL)
92+
return0;
9193
digestControlFile(&ControlFile,buffer,size);
9294
pg_free(buffer);
9395

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp