mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-02-02 13:36:08 +02:00
PGPRO-2079: Use .partial file to write backup configuration files backup.control and backup_content.control
This commit is contained in:
parent
38bd369145
commit
bd7b9bb4a1
@ -569,22 +569,38 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
|
|||||||
void
|
void
|
||||||
write_backup(pgBackup *backup)
|
write_backup(pgBackup *backup)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
char conf_path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
|
char path_temp[MAXPGPATH];
|
||||||
|
int errno_temp;
|
||||||
|
|
||||||
pgBackupGetPath(backup, conf_path, lengthof(conf_path), BACKUP_CONTROL_FILE);
|
pgBackupGetPath(backup, path, lengthof(path), BACKUP_CONTROL_FILE);
|
||||||
fp = fopen(conf_path, "wt");
|
snprintf(path_temp, sizeof(path_temp), "%s.partial", path);
|
||||||
|
|
||||||
|
fp = fopen(path_temp, "wt");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
elog(ERROR, "Cannot open configuration file \"%s\": %s", conf_path,
|
elog(ERROR, "Cannot open configuration file \"%s\": %s",
|
||||||
strerror(errno));
|
path_temp, strerror(errno));
|
||||||
|
|
||||||
pgBackupWriteControl(fp, backup);
|
pgBackupWriteControl(fp, backup);
|
||||||
|
|
||||||
if (fflush(fp) != 0 ||
|
if (fflush(fp) != 0 ||
|
||||||
fsync(fileno(fp)) != 0 ||
|
fsync(fileno(fp)) != 0 ||
|
||||||
fclose(fp))
|
fclose(fp))
|
||||||
|
{
|
||||||
|
errno_temp = errno;
|
||||||
|
unlink(path_temp);
|
||||||
elog(ERROR, "Cannot write configuration file \"%s\": %s",
|
elog(ERROR, "Cannot write configuration file \"%s\": %s",
|
||||||
conf_path, strerror(errno));
|
path_temp, strerror(errno_temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rename(path_temp, path) < 0)
|
||||||
|
{
|
||||||
|
errno_temp = errno;
|
||||||
|
unlink(path_temp);
|
||||||
|
elog(ERROR, "Cannot rename configuration file \"%s\" to \"%s\": %s",
|
||||||
|
path_temp, path, strerror(errno_temp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -595,20 +611,36 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
|
char path_temp[MAXPGPATH];
|
||||||
|
int errno_temp;
|
||||||
|
|
||||||
pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST);
|
pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST);
|
||||||
|
snprintf(path_temp, sizeof(path_temp), "%s.partial", path);
|
||||||
|
|
||||||
fp = fopen(path, "wt");
|
fp = fopen(path_temp, "wt");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
elog(ERROR, "Cannot open file list \"%s\": %s", path,
|
elog(ERROR, "Cannot open file list \"%s\": %s", path_temp,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
print_file_list(fp, files, root);
|
print_file_list(fp, files, root);
|
||||||
|
|
||||||
if (fflush(fp) != 0 ||
|
if (fflush(fp) != 0 ||
|
||||||
fsync(fileno(fp)) != 0 ||
|
fsync(fileno(fp)) != 0 ||
|
||||||
fclose(fp))
|
fclose(fp))
|
||||||
elog(ERROR, "Cannot write file list \"%s\": %s", path, strerror(errno));
|
{
|
||||||
|
errno_temp = errno;
|
||||||
|
unlink(path_temp);
|
||||||
|
elog(ERROR, "Cannot write file list \"%s\": %s",
|
||||||
|
path_temp, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rename(path_temp, path) < 0)
|
||||||
|
{
|
||||||
|
errno_temp = errno;
|
||||||
|
unlink(path_temp);
|
||||||
|
elog(ERROR, "Cannot rename configuration file \"%s\" to \"%s\": %s",
|
||||||
|
path_temp, path, strerror(errno_temp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user