Go to the source code of this file.
|
int | RestoreArchivedFile (const char *path, const char *xlogfname, off_t expectedSize, const char *restoreCommand) |
|
◆ RestoreArchivedFile()
int RestoreArchivedFile |
( |
const char * |
path, |
|
|
const char * |
xlogfname, |
|
|
off_t |
expectedSize, |
|
|
const char * |
restoreCommand |
|
) |
| |
Definition at line 39 of file archive.c.
41{
43 char *xlogRestoreCmd;
44 int rc;
46
48
50 xlogfname, NULL);
51
52
53
54
55
56 fflush(NULL);
57 rc = system(xlogRestoreCmd);
58 pfree(xlogRestoreCmd);
59
60 if (rc == 0)
61 {
62
63
64
65
66 if (
stat(xlogpath, &stat_buf) == 0)
67 {
68 if (expectedSize > 0 && stat_buf.st_size != expectedSize)
69 pg_fatal(
"unexpected file size for \"%s\": %lld instead of %lld",
70 xlogfname, (long long int) stat_buf.st_size,
71 (long long int) expectedSize);
72 else
73 {
74 int xlogfd = open(xlogpath, O_RDONLY |
PG_BINARY, 0);
75
76 if (xlogfd < 0)
77 pg_fatal(
"could not open file \"%s\" restored from archive: %m",
78 xlogpath);
79 else
80 return xlogfd;
81 }
82 }
83 else
84 {
85 if (errno != ENOENT)
86 pg_fatal(
"could not stat file \"%s\": %m",
87 xlogpath);
88 }
89 }
90
91
92
93
94
95
96
98 pg_fatal(
"\"restore_command\" failed: %s",
100
101
102
103
104
105 pg_log_error(
"could not restore file \"%s\" from archive",
106 xlogfname);
107 return -1;
108}
char * BuildRestoreCommand(const char *restoreCommand, const char *xlogpath, const char *xlogfname, const char *lastRestartPointFname)
#define pg_log_error(...)
void pfree(void *pointer)
char * wait_result_to_str(int exitstatus)
bool wait_result_is_any_signal(int exit_status, bool include_command_not_found)
References BuildRestoreCommand(), MAXPGPATH, pfree(), PG_BINARY, pg_fatal, pg_log_error, snprintf, stat::st_size, stat, wait_result_is_any_signal(), wait_result_to_str(), and XLOGDIR.