Skip to content

Commit cb1a7e3

Browse files
committed
add wal-size to backup.control and calculate backup size more accurately
1 parent aaa8941 commit cb1a7e3

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

backup.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,12 @@ do_backup_database(parray *backup_list)
374374
{
375375
pgFile *file = (pgFile *) parray_get(backup_files_list, i);
376376

377-
if (!S_ISREG(file->mode))
378-
continue;
377+
if (S_ISDIR(file->mode))
378+
current.data_bytes += 4096;
379379

380380
/* Count the amount of the data actually copied */
381-
current.data_bytes += file->write_size;
381+
if (S_ISREG(file->mode))
382+
current.data_bytes += file->write_size;
382383
}
383384

384385
if (backup_files_list)
@@ -482,6 +483,13 @@ do_backup(void)
482483
do_backup_database(backup_list);
483484
pgut_atexit_pop(backup_cleanup, NULL);
484485

486+
/* compute size of wal files of this backup stored in the archive */
487+
if (!current.stream)
488+
{
489+
current.wal_bytes = XLOG_SEG_SIZE *
490+
(current.stop_lsn/XLogSegSize - current.start_lsn/XLogSegSize + 1);
491+
}
492+
485493
/* Backup is done. Update backup status */
486494
current.end_time = time(NULL);
487495
current.status = BACKUP_STATUS_DONE;

catalog.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
427427
if (backup->data_bytes != BYTES_INVALID)
428428
fprintf(out, "data-bytes = " INT64_FORMAT "\n", backup->data_bytes);
429429

430+
if (backup->data_bytes != BYTES_INVALID)
431+
fprintf(out, "wal-bytes = " INT64_FORMAT "\n", backup->wal_bytes);
432+
430433
fprintf(out, "status = %s\n", status2str(backup->status));
431434

432435
/* 'parent_backup' is set if it is incremental backup */
@@ -486,6 +489,7 @@ readBackupControlFile(const char *path)
486489
{'U', 0, "recovery-xid", &backup->recovery_xid, SOURCE_FILE_STRICT},
487490
{'t', 0, "recovery-time", &backup->recovery_time, SOURCE_FILE_STRICT},
488491
{'I', 0, "data-bytes", &backup->data_bytes, SOURCE_FILE_STRICT},
492+
{'I', 0, "wal-bytes", &backup->wal_bytes, SOURCE_FILE_STRICT},
489493
{'u', 0, "block-size", &backup->block_size, SOURCE_FILE_STRICT},
490494
{'u', 0, "xlog-block-size", &backup->wal_block_size, SOURCE_FILE_STRICT},
491495
{'u', 0, "checksum_version", &backup->checksum_version, SOURCE_FILE_STRICT},

pg_probackup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ typedef struct pgBackup
196196
* BYTES_INVALID means nothing was backed up.
197197
*/
198198
int64 data_bytes;
199+
/* Size of WAL files in archive needed to restore this backup */
200+
int64 wal_bytes;
199201

200202
/* Fields needed for compatibility check */
201203
uint32 block_size;

0 commit comments

Comments
 (0)