Skip to content

Commit 4f163d8

Browse files
committed
Make pg_control file optional for restore.
1 parent 375d915 commit 4f163d8

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(const char *datadir, const char *path, size_t *filesize)
36+
slurpFile(const char *datadir, const char *path, size_t *filesize, bool safe)
3737
{
3838
int fd;
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+
return NULL;
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+
return NULL;
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+
return NULL;
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
extern char *slurpFile(const char *datadir,
233233
const char *path,
234-
size_t *filesize);
234+
size_t *filesize,
235+
bool safe);
235236

236237
/* in validate.c */
237238
extern int do_validate(pgBackupRange *range);
@@ -291,7 +292,7 @@ extern void extractPageMap(const char *datadir, XLogRecPtr startpoint,
291292
TimeLineID tli, XLogRecPtr endpoint);
292293

293294
/* in util.c */
294-
extern TimeLineID get_current_timeline(void);
295+
extern TimeLineID get_current_timeline(bool safe);
295296
extern void sanityChecks(void);
296297
extern void time2iso(char *buf, size_t len, time_t time);
297298
extern const char *status2str(BackupStatus status);

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_t size;
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(bool safe)
8484
{
8585
ControlFileData ControlFile;
8686
char *buffer;
8787
size_t size;
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+
return 0;
9193
digestControlFile(&ControlFile, buffer, size);
9294
pg_free(buffer);
9395

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy