1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-04 10:44:46 +02:00

PGPRO-2073: Save only status if we dont do backup

This commit is contained in:
Arthur Zakirov 2018-10-15 19:14:29 +03:00
parent bd703a0f0b
commit 5d1f680c48
8 changed files with 44 additions and 21 deletions

View File

@ -536,7 +536,7 @@ do_backup_instance(void)
prev_backup_start_lsn = prev_backup->start_lsn;
current.parent_backup = prev_backup->start_time;
pgBackupWriteBackupControlFile(&current);
write_backup(&current);
}
/*
@ -915,7 +915,7 @@ do_backup(time_t start_time)
/* Create backup directory and BACKUP_CONTROL_FILE */
if (pgBackupCreateDir(&current))
elog(ERROR, "cannot create backup directory");
pgBackupWriteBackupControlFile(&current);
write_backup(&current);
elog(LOG, "Backup destination is initialized");
@ -937,7 +937,7 @@ do_backup(time_t start_time)
/* Backup is done. Update backup status */
current.end_time = time(NULL);
current.status = BACKUP_STATUS_DONE;
pgBackupWriteBackupControlFile(&current);
write_backup(&current);
//elog(LOG, "Backup completed. Total bytes : " INT64_FORMAT "",
// current.data_bytes);
@ -2015,7 +2015,7 @@ backup_cleanup(bool fatal, void *userdata)
base36enc(current.start_time));
current.end_time = time(NULL);
current.status = BACKUP_STATUS_ERROR;
pgBackupWriteBackupControlFile(&current);
write_backup(&current);
}
/*

View File

@ -216,6 +216,24 @@ read_backup(time_t timestamp)
return readBackupControlFile(conf_path);
}
/*
* Save the backup status into BACKUP_CONTROL_FILE.
*
* We need to reread the backup using its ID and save it changing only its
* status.
*/
void
write_backup_status(pgBackup *backup)
{
pgBackup *tmp;
tmp = read_backup(backup->start_time);
tmp->status = backup->status;
pgBackupFree(tmp);
}
/*
* Get backup_mode in string representation.
*/
@ -478,7 +496,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
/* create BACKUP_CONTROL_FILE */
void
pgBackupWriteBackupControlFile(pgBackup *backup)
write_backup(pgBackup *backup)
{
FILE *fp = NULL;
char ini_path[MAXPGPATH];

View File

@ -269,7 +269,7 @@ delete_backup_files(pgBackup *backup)
* the error occurs before deleting all backup files.
*/
backup->status = BACKUP_STATUS_DELETING;
pgBackupWriteBackupControlFile(backup);
write_backup_status(backup);
/* list files to be deleted */
files = parray_new();

View File

@ -167,10 +167,10 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
elog(LOG, "Merging backup %s with backup %s", from_backup_id, to_backup_id);
to_backup->status = BACKUP_STATUS_MERGING;
pgBackupWriteBackupControlFile(to_backup);
write_backup_status(to_backup);
from_backup->status = BACKUP_STATUS_MERGING;
pgBackupWriteBackupControlFile(from_backup);
write_backup_status(from_backup);
/*
* Make backup paths.
@ -326,7 +326,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
to_backup->wal_bytes = BYTES_INVALID;
pgBackupWriteFileList(to_backup, files, from_database_path);
pgBackupWriteBackupControlFile(to_backup);
write_backup_status(to_backup);
/* Cleanup */
pfree(threads_args);

View File

@ -476,7 +476,7 @@ validate_backup_wal_from_start_to_stop(pgBackup *backup,
* the backup is definitely corrupted. Update its status.
*/
backup->status = BACKUP_STATUS_CORRUPT;
pgBackupWriteBackupControlFile(backup);
write_backup_status(backup);
elog(WARNING, "There are not enough WAL records to consistenly restore "
"backup %s from START LSN: %X/%X to STOP LSN: %X/%X",

View File

@ -445,6 +445,9 @@ extern int do_validate_all(void);
/* in catalog.c */
extern pgBackup *read_backup(time_t timestamp);
extern void write_backup(pgBackup *backup);
extern void write_backup_status(pgBackup *backup);
extern const char *pgBackupGetBackupMode(pgBackup *backup);
extern parray *catalog_get_backup_list(time_t requested_backup_id);
@ -452,7 +455,6 @@ extern pgBackup *catalog_get_last_data_backup(parray *backup_list,
TimeLineID tli);
extern void catalog_lock(void);
extern void pgBackupWriteControl(FILE *out, pgBackup *backup);
extern void pgBackupWriteBackupControlFile(pgBackup *backup);
extern void pgBackupWriteFileList(pgBackup *backup, parray *files,
const char *root);

View File

@ -208,7 +208,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
if (backup->status == BACKUP_STATUS_OK)
{
backup->status = BACKUP_STATUS_ORPHAN;
pgBackupWriteBackupControlFile(backup);
write_backup_status(backup);
elog(WARNING, "Backup %s is orphaned because his parent %s is missing",
base36enc(backup->start_time), missing_backup_id);
@ -241,10 +241,13 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
if (backup->status == BACKUP_STATUS_OK)
{
backup->status = BACKUP_STATUS_ORPHAN;
pgBackupWriteBackupControlFile(backup);
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
base36enc(backup->start_time), parent_backup_id,
status2str(tmp_backup->status));
write_backup_status(backup);
elog(WARNING,
"Backup %s is orphaned because his parent %s has status: %s",
base36enc(backup->start_time),
parent_backup_id,
status2str(tmp_backup->status));
}
else
{
@ -336,7 +339,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
if (backup->status == BACKUP_STATUS_OK)
{
backup->status = BACKUP_STATUS_ORPHAN;
pgBackupWriteBackupControlFile(backup);
write_backup_status(backup);
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
base36enc(backup->start_time),

View File

@ -135,7 +135,7 @@ pgBackupValidate(pgBackup *backup)
/* Update backup status */
backup->status = corrupted ? BACKUP_STATUS_CORRUPT : BACKUP_STATUS_OK;
pgBackupWriteBackupControlFile(backup);
write_backup_status(backup);
if (corrupted)
elog(WARNING, "Backup %s data files are corrupted", base36enc(backup->start_time));
@ -340,7 +340,7 @@ do_validate_instance(void)
if (current_backup->status == BACKUP_STATUS_OK)
{
current_backup->status = BACKUP_STATUS_ORPHAN;
pgBackupWriteBackupControlFile(current_backup);
write_backup_status(current_backup);
elog(WARNING, "Backup %s is orphaned because his parent %s is missing",
base36enc(current_backup->start_time),
parent_backup_id);
@ -365,7 +365,7 @@ do_validate_instance(void)
if (current_backup->status == BACKUP_STATUS_OK)
{
current_backup->status = BACKUP_STATUS_ORPHAN;
pgBackupWriteBackupControlFile(current_backup);
write_backup_status(current_backup);
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
base36enc(current_backup->start_time), parent_backup_id,
status2str(tmp_backup->status));
@ -422,7 +422,7 @@ do_validate_instance(void)
if (backup->status == BACKUP_STATUS_OK)
{
backup->status = BACKUP_STATUS_ORPHAN;
pgBackupWriteBackupControlFile(backup);
write_backup_status(backup);
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
base36enc(backup->start_time),