Skip to content

Commit 79087d3

Browse files
committed
Fix problem with backuping non-data files
1 parent b00243f commit 79087d3

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

src/backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ backup_files(void *arg)
23332333
skip = true; /* ...skip copying file. */
23342334
}
23352335
if (skip ||
2336-
!copy_file(arguments->from_root, arguments->to_root, file, FIO_BACKUP_HOST))
2336+
!copy_file(arguments->from_root, FIO_DB_HOST, arguments->to_root, FIO_BACKUP_HOST, file))
23372337
{
23382338
/* disappeared file not to be confused with 'not changed' */
23392339
if (file->write_size != FILE_NOT_FOUND)

src/data.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
912912
* it is either small control file or already compressed cfs file.
913913
*/
914914
bool
915-
copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location location)
915+
copy_file(const char *from_root, fio_location from_location,
916+
const char *to_root, fio_location to_location, pgFile *file)
916917
{
917918
char to_path[MAXPGPATH];
918919
FILE *in;
@@ -930,7 +931,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
930931
file->write_size = 0;
931932

932933
/* open backup mode file for read */
933-
in = fopen(file->path, PG_BINARY_R);
934+
in = fio_fopen(file->path, PG_BINARY_R, from_location);
934935
if (in == NULL)
935936
{
936937
FIN_FILE_CRC32(true, crc);
@@ -950,19 +951,19 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
950951

951952
/* open backup file for write */
952953
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
953-
out = fio_fopen(to_path, PG_BINARY_W, location);
954+
out = fio_fopen(to_path, PG_BINARY_W, to_location);
954955
if (out == NULL)
955956
{
956957
int errno_tmp = errno;
957-
fclose(in);
958+
fio_fclose(in);
958959
elog(ERROR, "cannot open destination file \"%s\": %s",
959960
to_path, strerror(errno_tmp));
960961
}
961962

962963
/* stat source file to change mode of destination file */
963-
if (fstat(fileno(in), &st) == -1)
964+
if (fio_ffstat(in, &st) == -1)
964965
{
965-
fclose(in);
966+
fio_fclose(in);
966967
fio_fclose(out);
967968
elog(ERROR, "cannot stat \"%s\": %s", file->path,
968969
strerror(errno));
@@ -973,14 +974,14 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
973974
{
974975
read_len = 0;
975976

976-
if ((read_len = fread(buf, 1, sizeof(buf), in)) != sizeof(buf))
977+
if ((read_len = fio_fread(in, buf, sizeof(buf))) != sizeof(buf))
977978
break;
978979

979980
if (fio_fwrite(out, buf, read_len) != read_len)
980981
{
981982
errno_tmp = errno;
982983
/* oops */
983-
fclose(in);
984+
fio_fclose(in);
984985
fio_fclose(out);
985986
elog(ERROR, "cannot write to \"%s\": %s", to_path,
986987
strerror(errno_tmp));
@@ -992,9 +993,9 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
992993
}
993994

994995
errno_tmp = errno;
995-
if (!feof(in))
996+
if (read_len < 0)
996997
{
997-
fclose(in);
998+
fio_fclose(in);
998999
fio_fclose(out);
9991000
elog(ERROR, "cannot read backup mode file \"%s\": %s",
10001001
file->path, strerror(errno_tmp));
@@ -1007,7 +1008,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
10071008
{
10081009
errno_tmp = errno;
10091010
/* oops */
1010-
fclose(in);
1011+
fio_fclose(in);
10111012
fio_fclose(out);
10121013
elog(ERROR, "cannot write to \"%s\": %s", to_path,
10131014
strerror(errno_tmp));
@@ -1024,10 +1025,10 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
10241025
file->crc = crc;
10251026

10261027
/* update file permission */
1027-
if (fio_chmod(to_path, st.st_mode, location) == -1)
1028+
if (fio_chmod(to_path, st.st_mode, to_location) == -1)
10281029
{
10291030
errno_tmp = errno;
1030-
fclose(in);
1031+
fio_fclose(in);
10311032
fio_fclose(out);
10321033
elog(ERROR, "cannot change mode of \"%s\": %s", to_path,
10331034
strerror(errno_tmp));
@@ -1036,7 +1037,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
10361037
if (fio_fflush(out) != 0 ||
10371038
fio_fclose(out))
10381039
elog(ERROR, "cannot write \"%s\": %s", to_path, strerror(errno));
1039-
fclose(in);
1040+
fio_fclose(in);
10401041

10411042
return true;
10421043
}

src/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ merge_files(void *arg)
561561
else if (strcmp(file->name, "pg_control") == 0)
562562
copy_pgcontrol_file(argument->from_root, argument->to_root, file, FIO_LOCAL_HOST);
563563
else
564-
copy_file(argument->from_root, argument->to_root, file, FIO_LOCAL_HOST);
564+
copy_file(argument->from_root, FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file);
565565

566566
/*
567567
* We need to save compression algorithm type of the target backup to be

src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ extern void restore_data_file(const char *to_path,
570570
pgFile *file, bool allow_truncate,
571571
bool write_header,
572572
uint32 backup_version);
573-
extern bool copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location location);
573+
extern bool copy_file(const char *from_root, fio_location from_location, const char *to_root, fio_location to_location, pgFile *file);
574574
extern void move_file(const char *from_root, const char *to_root, pgFile *file);
575575
extern void push_wal_file(const char *from_path, const char *to_path,
576576
bool is_compress, bool overwrite);

src/restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ restore_files(void *arg)
676676
else if (strcmp(file->name, "pg_control") == 0)
677677
copy_pgcontrol_file(from_root, instance_config.pgdata, file, FIO_DB_HOST);
678678
else
679-
copy_file(from_root, instance_config.pgdata, file, FIO_DB_HOST);
679+
copy_file(from_root, FIO_BACKUP_HOST, instance_config.pgdata, FIO_DB_HOST, file);
680680

681681
/* print size of restored file */
682682
if (file->write_size != BYTES_INVALID)

0 commit comments

Comments
 (0)