Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d1f680

Browse files
committed
PGPRO-2073: Save only status if we dont do backup
1 parent bd703a0 commit 5d1f680

File tree

8 files changed

+44
-21
lines changed

8 files changed

+44
-21
lines changed

src/backup.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ do_backup_instance(void)
536536
prev_backup_start_lsn = prev_backup->start_lsn;
537537
current.parent_backup = prev_backup->start_time;
538538

539-
pgBackupWriteBackupControlFile(&current);
539+
write_backup(&current);
540540
}
541541

542542
/*
@@ -915,7 +915,7 @@ do_backup(time_t start_time)
915915
/* Create backup directory and BACKUP_CONTROL_FILE */
916916
if (pgBackupCreateDir(&current))
917917
elog(ERROR, "cannot create backup directory");
918-
pgBackupWriteBackupControlFile(&current);
918+
write_backup(&current);
919919

920920
elog(LOG, "Backup destination is initialized");
921921

@@ -937,7 +937,7 @@ do_backup(time_t start_time)
937937
/* Backup is done. Update backup status */
938938
current.end_time = time(NULL);
939939
current.status = BACKUP_STATUS_DONE;
940-
pgBackupWriteBackupControlFile(&current);
940+
write_backup(&current);
941941

942942
//elog(LOG, "Backup completed. Total bytes : " INT64_FORMAT "",
943943
// current.data_bytes);
@@ -2015,7 +2015,7 @@ backup_cleanup(bool fatal, void *userdata)
20152015
base36enc(current.start_time));
20162016
current.end_time = time(NULL);
20172017
current.status = BACKUP_STATUS_ERROR;
2018-
pgBackupWriteBackupControlFile(&current);
2018+
write_backup(&current);
20192019
}
20202020

20212021
/*

src/catalog.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ read_backup(time_t timestamp)
216216
return readBackupControlFile(conf_path);
217217
}
218218

219+
/*
220+
* Save the backup status into BACKUP_CONTROL_FILE.
221+
*
222+
* We need to reread the backup using its ID and save it changing only its
223+
* status.
224+
*/
225+
void
226+
write_backup_status(pgBackup *backup)
227+
{
228+
pgBackup *tmp;
229+
230+
tmp = read_backup(backup->start_time);
231+
tmp->status = backup->status;
232+
233+
234+
pgBackupFree(tmp);
235+
}
236+
219237
/*
220238
* Get backup_mode in string representation.
221239
*/
@@ -478,7 +496,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
478496

479497
/* create BACKUP_CONTROL_FILE */
480498
void
481-
pgBackupWriteBackupControlFile(pgBackup *backup)
499+
write_backup(pgBackup *backup)
482500
{
483501
FILE *fp = NULL;
484502
char ini_path[MAXPGPATH];

src/delete.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ delete_backup_files(pgBackup *backup)
269269
* the error occurs before deleting all backup files.
270270
*/
271271
backup->status = BACKUP_STATUS_DELETING;
272-
pgBackupWriteBackupControlFile(backup);
272+
write_backup_status(backup);
273273

274274
/* list files to be deleted */
275275
files = parray_new();

src/merge.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
167167
elog(LOG, "Merging backup %s with backup %s", from_backup_id, to_backup_id);
168168

169169
to_backup->status = BACKUP_STATUS_MERGING;
170-
pgBackupWriteBackupControlFile(to_backup);
170+
write_backup_status(to_backup);
171171

172172
from_backup->status = BACKUP_STATUS_MERGING;
173-
pgBackupWriteBackupControlFile(from_backup);
173+
write_backup_status(from_backup);
174174

175175
/*
176176
* Make backup paths.
@@ -326,7 +326,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
326326
to_backup->wal_bytes = BYTES_INVALID;
327327

328328
pgBackupWriteFileList(to_backup, files, from_database_path);
329-
pgBackupWriteBackupControlFile(to_backup);
329+
write_backup_status(to_backup);
330330

331331
/* Cleanup */
332332
pfree(threads_args);

src/parsexlog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ validate_backup_wal_from_start_to_stop(pgBackup *backup,
476476
* the backup is definitely corrupted. Update its status.
477477
*/
478478
backup->status = BACKUP_STATUS_CORRUPT;
479-
pgBackupWriteBackupControlFile(backup);
479+
write_backup_status(backup);
480480

481481
elog(WARNING, "There are not enough WAL records to consistenly restore "
482482
"backup %s from START LSN: %X/%X to STOP LSN: %X/%X",

src/pg_probackup.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,16 @@ extern int do_validate_all(void);
445445

446446
/* in catalog.c */
447447
extern pgBackup *read_backup(time_t timestamp);
448+
extern void write_backup(pgBackup *backup);
449+
extern void write_backup_status(pgBackup *backup);
450+
448451
extern const char *pgBackupGetBackupMode(pgBackup *backup);
449452

450453
extern parray *catalog_get_backup_list(time_t requested_backup_id);
451454
extern pgBackup *catalog_get_last_data_backup(parray *backup_list,
452455
TimeLineID tli);
453456
extern void catalog_lock(void);
454457
extern void pgBackupWriteControl(FILE *out, pgBackup *backup);
455-
extern void pgBackupWriteBackupControlFile(pgBackup *backup);
456458
extern void pgBackupWriteFileList(pgBackup *backup, parray *files,
457459
const char *root);
458460

src/restore.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
208208
if (backup->status == BACKUP_STATUS_OK)
209209
{
210210
backup->status = BACKUP_STATUS_ORPHAN;
211-
pgBackupWriteBackupControlFile(backup);
211+
write_backup_status(backup);
212212

213213
elog(WARNING, "Backup %s is orphaned because his parent %s is missing",
214214
base36enc(backup->start_time), missing_backup_id);
@@ -241,10 +241,13 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
241241
if (backup->status == BACKUP_STATUS_OK)
242242
{
243243
backup->status = BACKUP_STATUS_ORPHAN;
244-
pgBackupWriteBackupControlFile(backup);
245-
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
246-
base36enc(backup->start_time), parent_backup_id,
247-
status2str(tmp_backup->status));
244+
write_backup_status(backup);
245+
246+
elog(WARNING,
247+
"Backup %s is orphaned because his parent %s has status: %s",
248+
base36enc(backup->start_time),
249+
parent_backup_id,
250+
status2str(tmp_backup->status));
248251
}
249252
else
250253
{
@@ -336,7 +339,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
336339
if (backup->status == BACKUP_STATUS_OK)
337340
{
338341
backup->status = BACKUP_STATUS_ORPHAN;
339-
pgBackupWriteBackupControlFile(backup);
342+
write_backup_status(backup);
340343

341344
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
342345
base36enc(backup->start_time),

src/validate.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pgBackupValidate(pgBackup *backup)
135135

136136
/* Update backup status */
137137
backup->status = corrupted ? BACKUP_STATUS_CORRUPT : BACKUP_STATUS_OK;
138-
pgBackupWriteBackupControlFile(backup);
138+
write_backup_status(backup);
139139

140140
if (corrupted)
141141
elog(WARNING, "Backup %s data files are corrupted", base36enc(backup->start_time));
@@ -340,7 +340,7 @@ do_validate_instance(void)
340340
if (current_backup->status == BACKUP_STATUS_OK)
341341
{
342342
current_backup->status = BACKUP_STATUS_ORPHAN;
343-
pgBackupWriteBackupControlFile(current_backup);
343+
write_backup_status(current_backup);
344344
elog(WARNING, "Backup %s is orphaned because his parent %s is missing",
345345
base36enc(current_backup->start_time),
346346
parent_backup_id);
@@ -365,7 +365,7 @@ do_validate_instance(void)
365365
if (current_backup->status == BACKUP_STATUS_OK)
366366
{
367367
current_backup->status = BACKUP_STATUS_ORPHAN;
368-
pgBackupWriteBackupControlFile(current_backup);
368+
write_backup_status(current_backup);
369369
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
370370
base36enc(current_backup->start_time), parent_backup_id,
371371
status2str(tmp_backup->status));
@@ -422,7 +422,7 @@ do_validate_instance(void)
422422
if (backup->status == BACKUP_STATUS_OK)
423423
{
424424
backup->status = BACKUP_STATUS_ORPHAN;
425-
pgBackupWriteBackupControlFile(backup);
425+
write_backup_status(backup);
426426

427427
elog(WARNING, "Backup %s is orphaned because his parent %s has status: %s",
428428
base36enc(backup->start_time),

0 commit comments

Comments
 (0)