mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-03-03 15:42:18 +02:00
Fix problem with backuping non-data files
This commit is contained in:
parent
b00243f05b
commit
79087d38bf
@ -2333,7 +2333,7 @@ backup_files(void *arg)
|
|||||||
skip = true; /* ...skip copying file. */
|
skip = true; /* ...skip copying file. */
|
||||||
}
|
}
|
||||||
if (skip ||
|
if (skip ||
|
||||||
!copy_file(arguments->from_root, arguments->to_root, file, FIO_BACKUP_HOST))
|
!copy_file(arguments->from_root, FIO_DB_HOST, arguments->to_root, FIO_BACKUP_HOST, file))
|
||||||
{
|
{
|
||||||
/* disappeared file not to be confused with 'not changed' */
|
/* disappeared file not to be confused with 'not changed' */
|
||||||
if (file->write_size != FILE_NOT_FOUND)
|
if (file->write_size != FILE_NOT_FOUND)
|
||||||
|
29
src/data.c
29
src/data.c
@ -912,7 +912,8 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
|
|||||||
* it is either small control file or already compressed cfs file.
|
* it is either small control file or already compressed cfs file.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location location)
|
copy_file(const char *from_root, fio_location from_location,
|
||||||
|
const char *to_root, fio_location to_location, pgFile *file)
|
||||||
{
|
{
|
||||||
char to_path[MAXPGPATH];
|
char to_path[MAXPGPATH];
|
||||||
FILE *in;
|
FILE *in;
|
||||||
@ -930,7 +931,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
file->write_size = 0;
|
file->write_size = 0;
|
||||||
|
|
||||||
/* open backup mode file for read */
|
/* open backup mode file for read */
|
||||||
in = fopen(file->path, PG_BINARY_R);
|
in = fio_fopen(file->path, PG_BINARY_R, from_location);
|
||||||
if (in == NULL)
|
if (in == NULL)
|
||||||
{
|
{
|
||||||
FIN_FILE_CRC32(true, crc);
|
FIN_FILE_CRC32(true, crc);
|
||||||
@ -950,19 +951,19 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
|
|
||||||
/* open backup file for write */
|
/* open backup file for write */
|
||||||
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
|
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
|
||||||
out = fio_fopen(to_path, PG_BINARY_W, location);
|
out = fio_fopen(to_path, PG_BINARY_W, to_location);
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
{
|
{
|
||||||
int errno_tmp = errno;
|
int errno_tmp = errno;
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
elog(ERROR, "cannot open destination file \"%s\": %s",
|
elog(ERROR, "cannot open destination file \"%s\": %s",
|
||||||
to_path, strerror(errno_tmp));
|
to_path, strerror(errno_tmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stat source file to change mode of destination file */
|
/* stat source file to change mode of destination file */
|
||||||
if (fstat(fileno(in), &st) == -1)
|
if (fio_ffstat(in, &st) == -1)
|
||||||
{
|
{
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
fio_fclose(out);
|
fio_fclose(out);
|
||||||
elog(ERROR, "cannot stat \"%s\": %s", file->path,
|
elog(ERROR, "cannot stat \"%s\": %s", file->path,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@ -973,14 +974,14 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
{
|
{
|
||||||
read_len = 0;
|
read_len = 0;
|
||||||
|
|
||||||
if ((read_len = fread(buf, 1, sizeof(buf), in)) != sizeof(buf))
|
if ((read_len = fio_fread(in, buf, sizeof(buf))) != sizeof(buf))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (fio_fwrite(out, buf, read_len) != read_len)
|
if (fio_fwrite(out, buf, read_len) != read_len)
|
||||||
{
|
{
|
||||||
errno_tmp = errno;
|
errno_tmp = errno;
|
||||||
/* oops */
|
/* oops */
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
fio_fclose(out);
|
fio_fclose(out);
|
||||||
elog(ERROR, "cannot write to \"%s\": %s", to_path,
|
elog(ERROR, "cannot write to \"%s\": %s", to_path,
|
||||||
strerror(errno_tmp));
|
strerror(errno_tmp));
|
||||||
@ -992,9 +993,9 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno_tmp = errno;
|
errno_tmp = errno;
|
||||||
if (!feof(in))
|
if (read_len < 0)
|
||||||
{
|
{
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
fio_fclose(out);
|
fio_fclose(out);
|
||||||
elog(ERROR, "cannot read backup mode file \"%s\": %s",
|
elog(ERROR, "cannot read backup mode file \"%s\": %s",
|
||||||
file->path, strerror(errno_tmp));
|
file->path, strerror(errno_tmp));
|
||||||
@ -1007,7 +1008,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
{
|
{
|
||||||
errno_tmp = errno;
|
errno_tmp = errno;
|
||||||
/* oops */
|
/* oops */
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
fio_fclose(out);
|
fio_fclose(out);
|
||||||
elog(ERROR, "cannot write to \"%s\": %s", to_path,
|
elog(ERROR, "cannot write to \"%s\": %s", to_path,
|
||||||
strerror(errno_tmp));
|
strerror(errno_tmp));
|
||||||
@ -1024,10 +1025,10 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
file->crc = crc;
|
file->crc = crc;
|
||||||
|
|
||||||
/* update file permission */
|
/* update file permission */
|
||||||
if (fio_chmod(to_path, st.st_mode, location) == -1)
|
if (fio_chmod(to_path, st.st_mode, to_location) == -1)
|
||||||
{
|
{
|
||||||
errno_tmp = errno;
|
errno_tmp = errno;
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
fio_fclose(out);
|
fio_fclose(out);
|
||||||
elog(ERROR, "cannot change mode of \"%s\": %s", to_path,
|
elog(ERROR, "cannot change mode of \"%s\": %s", to_path,
|
||||||
strerror(errno_tmp));
|
strerror(errno_tmp));
|
||||||
@ -1036,7 +1037,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
|
|||||||
if (fio_fflush(out) != 0 ||
|
if (fio_fflush(out) != 0 ||
|
||||||
fio_fclose(out))
|
fio_fclose(out))
|
||||||
elog(ERROR, "cannot write \"%s\": %s", to_path, strerror(errno));
|
elog(ERROR, "cannot write \"%s\": %s", to_path, strerror(errno));
|
||||||
fclose(in);
|
fio_fclose(in);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -561,7 +561,7 @@ merge_files(void *arg)
|
|||||||
else if (strcmp(file->name, "pg_control") == 0)
|
else if (strcmp(file->name, "pg_control") == 0)
|
||||||
copy_pgcontrol_file(argument->from_root, argument->to_root, file, FIO_LOCAL_HOST);
|
copy_pgcontrol_file(argument->from_root, argument->to_root, file, FIO_LOCAL_HOST);
|
||||||
else
|
else
|
||||||
copy_file(argument->from_root, argument->to_root, file, FIO_LOCAL_HOST);
|
copy_file(argument->from_root, FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We need to save compression algorithm type of the target backup to be
|
* We need to save compression algorithm type of the target backup to be
|
||||||
|
@ -570,7 +570,7 @@ extern void restore_data_file(const char *to_path,
|
|||||||
pgFile *file, bool allow_truncate,
|
pgFile *file, bool allow_truncate,
|
||||||
bool write_header,
|
bool write_header,
|
||||||
uint32 backup_version);
|
uint32 backup_version);
|
||||||
extern bool copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location location);
|
extern bool copy_file(const char *from_root, fio_location from_location, const char *to_root, fio_location to_location, pgFile *file);
|
||||||
extern void move_file(const char *from_root, const char *to_root, pgFile *file);
|
extern void move_file(const char *from_root, const char *to_root, pgFile *file);
|
||||||
extern void push_wal_file(const char *from_path, const char *to_path,
|
extern void push_wal_file(const char *from_path, const char *to_path,
|
||||||
bool is_compress, bool overwrite);
|
bool is_compress, bool overwrite);
|
||||||
|
@ -676,7 +676,7 @@ restore_files(void *arg)
|
|||||||
else if (strcmp(file->name, "pg_control") == 0)
|
else if (strcmp(file->name, "pg_control") == 0)
|
||||||
copy_pgcontrol_file(from_root, instance_config.pgdata, file, FIO_DB_HOST);
|
copy_pgcontrol_file(from_root, instance_config.pgdata, file, FIO_DB_HOST);
|
||||||
else
|
else
|
||||||
copy_file(from_root, instance_config.pgdata, file, FIO_DB_HOST);
|
copy_file(from_root, FIO_BACKUP_HOST, instance_config.pgdata, FIO_DB_HOST, file);
|
||||||
|
|
||||||
/* print size of restored file */
|
/* print size of restored file */
|
||||||
if (file->write_size != BYTES_INVALID)
|
if (file->write_size != BYTES_INVALID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user