diff --git a/src/bin/pg_probackup/backup.cpp b/src/bin/pg_probackup/backup.cpp index 59a7147631001c67b2fe68c99fd40c42f54feddc..30aec1c9c1a6e634d55f1ebde95080d1e15c2cb3 100644 --- a/src/bin/pg_probackup/backup.cpp +++ b/src/bin/pg_probackup/backup.cpp @@ -75,6 +75,8 @@ static ReaderCxt *current_reader_cxt = NULL; /* We need critical section for datapagemap_add() in case of using threads */ static pthread_mutex_t backup_pagemap_mutex = PTHREAD_MUTEX_INITIALIZER; +#define GS_SECURE_FILES_VERSION_CFG "gs_secure_files/version.cfg" + /* * We need to wait end of WAL streaming before execute pg_stop_backup(). */ @@ -654,8 +656,21 @@ static void sync_files(parray *database_map, const char *database_path, parray * else join_path_components(to_fullpath, database_path, file->rel_path); - if (fio_sync(to_fullpath, FIO_BACKUP_HOST) != 0) - elog(ERROR, "Cannot sync file \"%s\": %s", to_fullpath, strerror(errno)); + if (fio_sync(to_fullpath, FIO_BACKUP_HOST) != 0) { + /* Handling the file permission issue for gs_secure_files/version.cfg */ + if (strstr(to_fullpath, GS_SECURE_FILES_VERSION_CFG)) { + mode_t permissions = file->mode & 0777; + (void)chmod(to_fullpath, S_IRUSR | S_IWUSR); + + if (fio_sync(to_fullpath, FIO_BACKUP_HOST) != 0) { + (void)chmod(to_fullpath, permissions); + elog(ERROR, "Cannot sync file \"%s\": %s", to_fullpath, strerror(errno)); + } + (void)chmod(to_fullpath, permissions); + } else { + elog(ERROR, "Cannot sync file \"%s\": %s", to_fullpath, strerror(errno)); + } + } } time(&end_time);