1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-12 11:45:24 +02:00

Fix remote archive-get and restore

This commit is contained in:
Arthur Zakirov 2019-03-27 14:07:49 +03:00
parent adee1efc71
commit 3ff6a37d74
4 changed files with 50 additions and 45 deletions

View File

@ -1617,13 +1617,13 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_segment)
{
if (!file_exists)
{
file_exists = fileExists(wal_segment_path, is_start_lsn ? FIO_DB_HOST : FIO_BACKUP_HOST);
file_exists = fileExists(wal_segment_path, FIO_BACKUP_HOST);
/* Try to find compressed WAL file */
if (!file_exists)
{
#ifdef HAVE_LIBZ
file_exists = fileExists(gz_wal_segment_path, is_start_lsn ? FIO_DB_HOST : FIO_BACKUP_HOST);
file_exists = fileExists(gz_wal_segment_path, FIO_BACKUP_HOST);
if (file_exists)
elog(LOG, "Found compressed WAL segment: %s", wal_segment_path);
#endif

View File

@ -1263,9 +1263,8 @@ get_wal_file(const char *from_path, const char *to_path)
gzFile gz_in = NULL;
#endif
/* open file for read */
in = fopen(from_path, PG_BINARY_R);
if (in == NULL)
/* First check source file for existance */
if (fio_access(from_path, F_OK, FIO_BACKUP_HOST) != 0)
{
#ifdef HAVE_LIBZ
/*
@ -1273,19 +1272,7 @@ get_wal_file(const char *from_path, const char *to_path)
* extension.
*/
snprintf(gz_from_path, sizeof(gz_from_path), "%s.gz", from_path);
gz_in = gzopen(gz_from_path, PG_BINARY_R);
if (gz_in == NULL)
{
if (errno == ENOENT)
{
/* There is no compressed file too, raise an error below */
}
/* Cannot open compressed file for some reason */
else
elog(ERROR, "Cannot open compressed WAL file \"%s\": %s",
gz_from_path, strerror(errno));
}
else
if (fio_access(gz_from_path, F_OK, FIO_BACKUP_HOST) == 0)
{
/* Found compressed file */
is_decompress = true;
@ -1294,10 +1281,29 @@ get_wal_file(const char *from_path, const char *to_path)
#endif
/* Didn't find compressed file */
if (!is_decompress)
elog(ERROR, "Cannot open source WAL file \"%s\": %s",
from_path, strerror(errno));
elog(ERROR, "Source WAL file \"%s\" doesn't exist",
from_path);
}
/* open file for read */
if (!is_decompress)
{
in = fio_fopen(from_path, PG_BINARY_R, FIO_BACKUP_HOST);
if (in == NULL)
elog(ERROR, "Cannot open source WAL file \"%s\": %s",
from_path, strerror(errno));
}
#ifdef HAVE_LIBZ
else
{
gz_in = fio_gzopen(gz_from_path, PG_BINARY_R, Z_DEFAULT_COMPRESSION,
FIO_BACKUP_HOST);
if (gz_in == NULL)
elog(ERROR, "Cannot open compressed WAL file \"%s\": %s",
gz_from_path, strerror(errno));
}
#endif
/* open backup file for write */
snprintf(to_path_temp, sizeof(to_path_temp), "%s.partial", to_path);
@ -1314,8 +1320,8 @@ get_wal_file(const char *from_path, const char *to_path)
#ifdef HAVE_LIBZ
if (is_decompress)
{
read_len = gzread(gz_in, buf, sizeof(buf));
if (read_len != sizeof(buf) && !gzeof(gz_in))
read_len = fio_gzread(gz_in, buf, sizeof(buf));
if (read_len != sizeof(buf) && !fio_gzeof(gz_in))
{
errno_temp = errno;
fio_unlink(to_path_temp, FIO_DB_HOST);
@ -1326,7 +1332,7 @@ get_wal_file(const char *from_path, const char *to_path)
else
#endif
{
read_len = fread(buf, 1, sizeof(buf), in);
read_len = fio_fread(in, buf, sizeof(buf));
if (ferror(in))
{
errno_temp = errno;
@ -1351,13 +1357,13 @@ get_wal_file(const char *from_path, const char *to_path)
#ifdef HAVE_LIBZ
if (is_decompress)
{
if (gzeof(gz_in) || read_len == 0)
if (fio_gzeof(gz_in) || read_len == 0)
break;
}
else
#endif
{
if (feof(in) || read_len == 0)
if (/* feof(in) || */ read_len == 0)
break;
}
}
@ -1373,7 +1379,7 @@ get_wal_file(const char *from_path, const char *to_path)
#ifdef HAVE_LIBZ
if (is_decompress)
{
if (gzclose(gz_in) != 0)
if (fio_gzclose(gz_in) != 0)
{
errno_temp = errno;
fio_unlink(to_path_temp, FIO_DB_HOST);
@ -1384,7 +1390,7 @@ get_wal_file(const char *from_path, const char *to_path)
else
#endif
{
if (fclose(in))
if (fio_fclose(in))
{
errno_temp = errno;
fio_unlink(to_path_temp, FIO_DB_HOST);

View File

@ -341,7 +341,7 @@ main(int argc, char *argv[])
canonicalize_path(backup_path);
MyLocation = IsSshProtocol()
? backup_subcmd == ARCHIVE_PUSH_CMD
? (backup_subcmd == ARCHIVE_PUSH_CMD || backup_subcmd == ARCHIVE_GET_CMD)
? FIO_DB_HOST : FIO_BACKUP_HOST
: FIO_LOCAL_HOST;

View File

@ -716,18 +716,18 @@ create_recovery_conf(time_t backup_id,
elog(LOG, "creating recovery.conf");
snprintf(path, lengthof(path), "%s/recovery.conf", instance_config.pgdata);
fp = fopen(path, "wt");
fp = fio_fopen(path, "wt", FIO_DB_HOST);
if (fp == NULL)
elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
strerror(errno));
fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
PROGRAM_VERSION);
fio_fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
PROGRAM_VERSION);
if (need_restore_conf)
{
fprintf(fp, "restore_command = '%s archive-get -B %s --instance %s "
fio_fprintf(fp, "restore_command = '%s archive-get -B %s --instance %s "
"--wal-file-path %%p --wal-file-name %%f'\n",
PROGRAM_NAME, backup_path, instance_name);
@ -736,42 +736,41 @@ create_recovery_conf(time_t backup_id,
* exclusive options is specified, so the order of calls is insignificant.
*/
if (rt->recovery_target_name)
fprintf(fp, "recovery_target_name = '%s'\n", rt->recovery_target_name);
fio_fprintf(fp, "recovery_target_name = '%s'\n", rt->recovery_target_name);
if (rt->time_specified)
fprintf(fp, "recovery_target_time = '%s'\n", rt->target_time_string);
fio_fprintf(fp, "recovery_target_time = '%s'\n", rt->target_time_string);
if (rt->xid_specified)
fprintf(fp, "recovery_target_xid = '%s'\n", rt->target_xid_string);
fio_fprintf(fp, "recovery_target_xid = '%s'\n", rt->target_xid_string);
if (rt->recovery_target_lsn)
fprintf(fp, "recovery_target_lsn = '%s'\n", rt->target_lsn_string);
fio_fprintf(fp, "recovery_target_lsn = '%s'\n", rt->target_lsn_string);
if (rt->recovery_target_immediate)
fprintf(fp, "recovery_target = 'immediate'\n");
fio_fprintf(fp, "recovery_target = 'immediate'\n");
if (rt->inclusive_specified)
fprintf(fp, "recovery_target_inclusive = '%s'\n",
fio_fprintf(fp, "recovery_target_inclusive = '%s'\n",
rt->recovery_target_inclusive?"true":"false");
if (rt->recovery_target_tli)
fprintf(fp, "recovery_target_timeline = '%u'\n", rt->recovery_target_tli);
fio_fprintf(fp, "recovery_target_timeline = '%u'\n", rt->recovery_target_tli);
if (rt->recovery_target_action)
fprintf(fp, "recovery_target_action = '%s'\n", rt->recovery_target_action);
fio_fprintf(fp, "recovery_target_action = '%s'\n", rt->recovery_target_action);
}
if (restore_as_replica)
{
fprintf(fp, "standby_mode = 'on'\n");
fio_fprintf(fp, "standby_mode = 'on'\n");
if (backup->primary_conninfo)
fprintf(fp, "primary_conninfo = '%s'\n", backup->primary_conninfo);
fio_fprintf(fp, "primary_conninfo = '%s'\n", backup->primary_conninfo);
}
if (fflush(fp) != 0 ||
fsync(fileno(fp)) != 0 ||
fclose(fp))
if (fio_fflush(fp) != 0 ||
fio_fclose(fp))
elog(ERROR, "cannot write recovery.conf \"%s\": %s", path,
strerror(errno));
}