1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-03 14:01:57 +02:00

Refactor write/read calculation size of backups

This commit simplifies the way backup sizes are saved internally by
reusing the same variable for incremental and full backup, which were
using separated and exclusively used variables, resulted in a couple
of bytes wasted all the time. This was also reflected by a useless
column in the output table of subcommand "show".
This commit is contained in:
Michael Paquier 2014-01-10 04:11:27 +09:00
parent 9cd8e33508
commit 37c3be1168
10 changed files with 141 additions and 125 deletions

View File

@ -92,8 +92,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
elog(INFO, _("database backup start"));
/* Initialize size summary */
current.total_data_bytes = 0;
current.read_data_bytes = 0;
current.data_bytes = 0;
/*
* Obtain current timeline by scanning control file, theh LSN
@ -395,16 +394,25 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
pgFile *file = (pgFile *) parray_get(files, i);
if (!S_ISREG(file->mode))
continue;
current.total_data_bytes += file->size;
current.read_data_bytes += file->read_size;
/*
* Count only the amount of data. For a full backup, the total
* amount of data written counts while for an incremental
* backup only the data read counts.
*/
if (current.backup_mode == BACKUP_MODE_INCREMENTAL)
current.data_bytes += file->read_size;
else if (current.backup_mode == BACKUP_MODE_FULL)
current.data_bytes += file->size;
/* Count total amount of data for backup */
if (file->write_size != BYTES_INVALID)
current.write_bytes += file->write_size;
current.backup_bytes += file->write_size;
}
if (verbose)
{
printf(_("database backup completed(read: " INT64_FORMAT " write: " INT64_FORMAT ")\n"),
current.read_data_bytes, current.write_bytes);
printf(_("database backup completed(written: " INT64_FORMAT " Backup: " INT64_FORMAT ")\n"),
current.data_bytes, current.backup_bytes);
printf(_("========================================\n"));
}
@ -444,7 +452,7 @@ do_backup_arclog(parray *backup_list)
}
/* initialize size summary */
current.read_arclog_bytes = 0;
current.arclog_bytes = 0;
/*
* Switch xlog if database is not backed up, current timeline of
@ -523,10 +531,10 @@ do_backup_arclog(parray *backup_list)
pgFile *file = (pgFile *) parray_get(files, i);
if (!S_ISREG(file->mode))
continue;
current.read_arclog_bytes += file->read_size;
current.arclog_bytes += file->read_size;
if (file->write_size != BYTES_INVALID)
{
current.write_bytes += file->write_size;
current.backup_bytes += file->write_size;
arclog_write_bytes += file->write_size;
}
}
@ -553,7 +561,7 @@ do_backup_arclog(parray *backup_list)
if (verbose)
{
printf(_("archived WAL backup completed(read: " INT64_FORMAT " write: " INT64_FORMAT ")\n"),
current.read_arclog_bytes, arclog_write_bytes);
current.arclog_bytes, arclog_write_bytes);
printf(_("========================================\n"));
}
@ -589,7 +597,7 @@ do_backup_srvlog(parray *backup_list)
}
/* initialize size summary */
current.read_srvlog_bytes = 0;
current.srvlog_bytes = 0;
/*
* To take incremental backup, the file list of the last completed database
@ -632,10 +640,10 @@ do_backup_srvlog(parray *backup_list)
pgFile *file = (pgFile *) parray_get(files, i);
if (!S_ISREG(file->mode))
continue;
current.read_srvlog_bytes += file->read_size;
current.srvlog_bytes += file->read_size;
if (file->write_size != BYTES_INVALID)
{
current.write_bytes += file->write_size;
current.backup_bytes += file->write_size;
srvlog_write_bytes += file->write_size;
}
}
@ -643,7 +651,7 @@ do_backup_srvlog(parray *backup_list)
if (verbose)
{
printf(_("serverlog backup completed(read: " INT64_FORMAT " write: " INT64_FORMAT ")\n"),
current.read_srvlog_bytes, srvlog_write_bytes);
current.srvlog_bytes, srvlog_write_bytes);
printf(_("========================================\n"));
}
@ -728,11 +736,10 @@ do_backup(pgBackupOption bkupopt)
current.stop_lsn = 0;
current.start_time = time(NULL);
current.end_time = (time_t) 0;
current.total_data_bytes = BYTES_INVALID;
current.read_data_bytes = BYTES_INVALID;
current.read_arclog_bytes = BYTES_INVALID;
current.read_srvlog_bytes = BYTES_INVALID;
current.write_bytes = 0; /* write_bytes is valid always */
current.data_bytes = BYTES_INVALID;
current.arclog_bytes = BYTES_INVALID;
current.srvlog_bytes = BYTES_INVALID;
current.backup_bytes = 0;
current.block_size = BLCKSZ;
current.wal_block_size = XLOG_BLCKSZ;
current.recovery_xid = 0;
@ -779,23 +786,23 @@ do_backup(pgBackupOption bkupopt)
int64 total_read = 0;
/* WAL archives */
total_read += current.read_arclog_bytes;
total_read += current.arclog_bytes;
/* Database data */
if (current.backup_mode == BACKUP_MODE_FULL ||
current.backup_mode == BACKUP_MODE_INCREMENTAL)
total_read += current.read_arclog_bytes;
total_read += current.arclog_bytes;
/* Server logs */
if (current.with_serverlog)
total_read += current.read_srvlog_bytes;
total_read += current.srvlog_bytes;
if (total_read == 0)
printf(_("nothing to backup\n"));
else
printf(_("all backup completed(read: " INT64_FORMAT " write: "
INT64_FORMAT ")\n"),
total_read, current.write_bytes);
total_read, current.backup_bytes);
printf(_("========================================\n"));
}

View File

@ -384,21 +384,18 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
fprintf(out, "RECOVERY_TIME='%s'\n", timestamp);
}
if (backup->total_data_bytes != BYTES_INVALID)
fprintf(out, "TOTAL_DATA_BYTES=" INT64_FORMAT "\n",
backup->total_data_bytes);
if (backup->read_data_bytes != BYTES_INVALID)
fprintf(out, "READ_DATA_BYTES=" INT64_FORMAT "\n",
backup->read_data_bytes);
if (backup->read_arclog_bytes != BYTES_INVALID)
fprintf(out, "READ_ARCLOG_BYTES=" INT64_FORMAT "\n",
backup->read_arclog_bytes);
if (backup->read_srvlog_bytes != BYTES_INVALID)
fprintf(out, "READ_SRVLOG_BYTES=" INT64_FORMAT "\n",
backup->read_srvlog_bytes);
if (backup->write_bytes != BYTES_INVALID)
fprintf(out, "WRITE_BYTES=" INT64_FORMAT "\n",
backup->write_bytes);
if (backup->data_bytes != BYTES_INVALID)
fprintf(out, "DATA_BYTES=" INT64_FORMAT "\n",
backup->data_bytes);
if (backup->arclog_bytes != BYTES_INVALID)
fprintf(out, "ARCLOG_BYTES=" INT64_FORMAT "\n",
backup->arclog_bytes);
if (backup->srvlog_bytes != BYTES_INVALID)
fprintf(out, "SRVLOG_BYTES=" INT64_FORMAT "\n",
backup->srvlog_bytes);
if (backup->backup_bytes != BYTES_INVALID)
fprintf(out, "BACKUP_BYTES=" INT64_FORMAT "\n",
backup->backup_bytes);
fprintf(out, "BLOCK_SIZE=%u\n", backup->block_size);
fprintf(out, "XLOG_BLOCK_SIZE=%u\n", backup->wal_block_size);
@ -455,11 +452,10 @@ catalog_read_ini(const char *path)
{ 't', 0, "end-time" , NULL, SOURCE_ENV },
{ 'u', 0, "recovery-xid" , NULL, SOURCE_ENV },
{ 't', 0, "recovery-time" , NULL, SOURCE_ENV },
{ 'I', 0, "total-data-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "read-data-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "read-arclog-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "read-srvlog-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "write-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "data-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "arclog-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "srvlog-bytes" , NULL, SOURCE_ENV },
{ 'I', 0, "backup-bytes" , NULL, SOURCE_ENV },
{ 'u', 0, "block-size" , NULL, SOURCE_ENV },
{ 'u', 0, "xlog-block-size" , NULL, SOURCE_ENV },
{ 's', 0, "status" , NULL, SOURCE_ENV },
@ -484,11 +480,10 @@ catalog_read_ini(const char *path)
options[i++].var = &backup->end_time;
options[i++].var = &backup->recovery_xid;
options[i++].var = &backup->recovery_time;
options[i++].var = &backup->total_data_bytes;
options[i++].var = &backup->read_data_bytes;
options[i++].var = &backup->read_arclog_bytes;
options[i++].var = &backup->read_srvlog_bytes;
options[i++].var = &backup->write_bytes;
options[i++].var = &backup->data_bytes;
options[i++].var = &backup->arclog_bytes;
options[i++].var = &backup->srvlog_bytes;
options[i++].var = &backup->backup_bytes;
options[i++].var = &backup->block_size;
options[i++].var = &backup->wal_block_size;
options[i++].var = &status;
@ -635,9 +630,8 @@ catalog_init_config(pgBackup *backup)
backup->end_time = (time_t) 0;
backup->recovery_xid = 0;
backup->recovery_time = (time_t) 0;
backup->total_data_bytes = BYTES_INVALID;
backup->read_data_bytes = BYTES_INVALID;
backup->read_arclog_bytes = BYTES_INVALID;
backup->read_srvlog_bytes = BYTES_INVALID;
backup->write_bytes = BYTES_INVALID;
backup->data_bytes = BYTES_INVALID;
backup->arclog_bytes = BYTES_INVALID;
backup->srvlog_bytes = BYTES_INVALID;
backup->backup_bytes = BYTES_INVALID;
}

View File

@ -8,11 +8,10 @@ START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-05-31 17:05:53'
END_TIME='2009-05-31 17:09:13'
TOTAL_DATA_BYTES=1242102558
READ_DATA_BYTES=1024
READ_ARCLOG_BYTES=9223372036854775807
READ_SRVLOG_BYTES=-1
WRITE_BYTES=242102558
DATA_BYTES=1242102558
ARCLOG_BYTES=9223372036854775807
SRVLOG_BYTES=-1
BACKUP_BYTES=242102558
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=DONE

View File

@ -8,11 +8,10 @@ START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-01 17:05:53'
END_TIME='2009-06-01 17:09:13'
TOTAL_DATA_BYTES=1242102558
READ_DATA_BYTES=9223372036854775807
READ_ARCLOG_BYTES=16777216
READ_SRVLOG_BYTES=-1
WRITE_BYTES=162372983
DATA_BYTES=9223372036854775807
ARCLOG_BYTES=16777216
SRVLOG_BYTES=-1
BACKUP_BYTES=162372983
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=DONE

View File

@ -8,11 +8,10 @@ START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-02 17:05:03'
END_TIME='2009-06-02 17:05:03'
TOTAL_DATA_BYTES=-1
READ_DATA_BYTES=-1
READ_ARCLOG_BYTES=-1
READ_SRVLOG_BYTES=4335423
WRITE_BYTES=162372983
DATA_BYTES=-1
ARCLOG_BYTES=-1
SRVLOG_BYTES=4335423
BACKUP_BYTES=162372983
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=DELETED

View File

@ -8,11 +8,10 @@ START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-03 17:05:53'
END_TIME='2009-06-03 17:05:53'
TOTAL_DATA_BYTES=-1
READ_DATA_BYTES=-1
READ_ARCLOG_BYTES=-1
READ_SRVLOG_BYTES=-1
WRITE_BYTES=-1
DATA_BYTES=-1
ARCLOG_BYTES=-1
SRVLOG_BYTES=-1
BACKUP_BYTES=-1
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=RUNNING

View File

@ -29,11 +29,11 @@ CHECKPOINT
# of recovery target option in recovery.conf
3
# of deleted backups (show all)
4
3
# of deleted backups
0
delete backup
# of deleted backups
4
3
# of deleted backups
9
8

View File

@ -2,12 +2,12 @@
\! rm -rf ${PWD}/results/sample_backup
\! cp -rp data/sample_backup ${PWD}/results/sample_backup
\! pg_rman show -B ${PWD}/results/sample_backup
===========================================================================================================
Start Mode Current TLI Parent TLI Time Total Data WAL Log Backup Status
===========================================================================================================
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- ---- RUNNING
2009-06-01 17:05:53 INCR 1 0 3m ---- 9223PB 16MB ---- 162MB DONE
2009-05-31 17:05:53 FULL 1 0 3m 1242MB ---- 9223PB ---- 242MB DONE
==================================================================================================
Start Mode Current TLI Parent TLI Time Data WAL Log Backup Status
==================================================================================================
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- RUNNING
2009-06-01 17:05:53 INCR 1 0 3m 9223PB 16MB ---- 162MB DONE
2009-05-31 17:05:53 FULL 1 0 3m 1242MB 9223PB ---- 242MB DONE
\! pg_rman validate -B ${PWD}/results/sample_backup 2009-05-31 17:05:53 --debug
INFO: validate: 2009-05-31 17:05:53 backup and archive log files by CRC
LOG: database files...
@ -22,13 +22,13 @@ WARNING: CRC of backup file "PG_VERSION" must be 0 but FEF71BC1
LOG: archive WAL files...
WARNING: backup 2009-06-01 17:05:53 is corrupted
\! pg_rman show -a -B ${PWD}/results/sample_backup
===========================================================================================================
Start Mode Current TLI Parent TLI Time Total Data WAL Log Backup Status
===========================================================================================================
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- ---- RUNNING
2009-06-02 17:05:03 ARCH 1 0 0m ---- ---- ---- 4335kB 162MB DELETED
2009-06-01 17:05:53 INCR 1 0 3m ---- 9223PB 16MB ---- 162MB CORRUPT
2009-05-31 17:05:53 FULL 1 0 3m 1242MB ---- 9223PB ---- 242MB OK
==================================================================================================
Start Mode Current TLI Parent TLI Time Data WAL Log Backup Status
==================================================================================================
2009-06-03 17:05:53 FULL 1 0 0m ---- ---- ---- ---- RUNNING
2009-06-02 17:05:03 ARCH 1 0 0m ---- ---- 4335kB 162MB DELETED
2009-06-01 17:05:53 INCR 1 0 3m 9223PB 16MB ---- 162MB CORRUPT
2009-05-31 17:05:53 FULL 1 0 3m 1242MB 9223PB ---- 242MB OK
\! pg_rman show 2009-06-01 17:05:53 -B ${PWD}/results/sample_backup
# configuration
BACKUP_MODE=INCREMENTAL
@ -41,10 +41,9 @@ STOP_LSN=0/0b4c8020
START_TIME='2009-06-01 17:05:53'
END_TIME='2009-06-01 17:09:13'
RECOVERY_XID=0
TOTAL_DATA_BYTES=1242102558
READ_DATA_BYTES=9223372036854775807
READ_ARCLOG_BYTES=16777216
WRITE_BYTES=162372983
DATA_BYTES=9223372036854775807
ARCLOG_BYTES=16777216
BACKUP_BYTES=162372983
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=CORRUPT

View File

@ -144,12 +144,19 @@ typedef struct pgBackup
time_t recovery_time;
uint32 recovery_xid;
/* Size (-1 means nothing was backed up) */
int64 total_data_bytes;
int64 read_data_bytes;
int64 read_arclog_bytes;
int64 read_srvlog_bytes;
int64 write_bytes;
/* Different sizes (-1 means nothing was backed up) */
/*
* Amount of raw data. For a full backup, this is the total amount of
* data while for an incremental backup this is just the differential
* of data taken.
*/
int64 data_bytes;
/* Amount of data for WAL archives */
int64 arclog_bytes;
/* Amount of data for server logs */
int64 srvlog_bytes;
/* Total size of backup */
int64 backup_bytes;
/* data/wal block size for compatibility check */
uint32 block_size;

63
show.c
View File

@ -161,9 +161,9 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
int i;
/* show header */
fputs("===========================================================================================================\n", out);
fputs("Start Mode Current TLI Parent TLI Time Total Data WAL Log Backup Status \n", out);
fputs("===========================================================================================================\n", out);
fputs("==================================================================================================\n", out);
fputs("Start Mode Current TLI Parent TLI Time Data WAL Log Backup Status \n", out);
fputs("==================================================================================================\n", out);
for (i = 0; i < parray_num(backup_list); i++)
{
@ -172,11 +172,10 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
TimeLineID parent_tli;
char timestamp[20];
char duration[20] = "----";
char total_data_bytes_str[10] = "----";
char read_data_bytes_str[10] = "----";
char read_arclog_bytes_str[10] = "----";
char read_srvlog_bytes_str[10] = "----";
char write_bytes_str[10];
char data_bytes_str[10] = "----";
char arclog_bytes_str[10] = "----";
char srvlog_bytes_str[10] = "----";
char backup_bytes_str[10];
backup = parray_get(backup_list, i);
@ -188,28 +187,42 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
if (backup->end_time != (time_t) 0)
snprintf(duration, lengthof(duration), "%lum",
(backup->end_time - backup->start_time) / 60);
/* "Full" is only for full backup */
if (backup->backup_mode == BACKUP_MODE_FULL)
pretty_size(backup->total_data_bytes, total_data_bytes_str,
lengthof(total_data_bytes_str));
if (backup->backup_mode == BACKUP_MODE_INCREMENTAL)
pretty_size(backup->read_data_bytes, read_data_bytes_str,
lengthof(read_data_bytes_str));
pretty_size(backup->read_arclog_bytes, read_arclog_bytes_str,
lengthof(read_arclog_bytes_str));
/*
* Calculate Data field, in the case of full backup this shows the
* total amount of data. For an incremental backup, this size is only
* the differential of data accumulated.
*/
pretty_size(backup->data_bytes, data_bytes_str,
lengthof(data_bytes_str));
/* Calculate amount of data for archive files */
pretty_size(backup->arclog_bytes, arclog_bytes_str,
lengthof(arclog_bytes_str));
/* Calculate amount of data for server logs */
if (backup->with_serverlog)
pretty_size(backup->read_srvlog_bytes, read_srvlog_bytes_str,
lengthof(read_srvlog_bytes_str));
pretty_size(backup->write_bytes, write_bytes_str,
lengthof(write_bytes_str));
pretty_size(backup->srvlog_bytes, srvlog_bytes_str,
lengthof(srvlog_bytes_str));
/* Calculate amount of data for total backup */
pretty_size(backup->backup_bytes, backup_bytes_str,
lengthof(backup_bytes_str));
/* Get parent timeline before printing */
parent_tli = get_parent_tli(backup->tli);
fprintf(out, "%-19s %-4s %10d %10d %5s %6s %6s %6s %6s %6s %s\n",
timestamp, modes[backup->backup_mode], backup->tli, parent_tli, duration,
total_data_bytes_str, read_data_bytes_str, read_arclog_bytes_str,
read_srvlog_bytes_str, write_bytes_str, status2str(backup->status));
fprintf(out, "%-19s %-4s %10d %10d %5s %6s %6s %6s %6s %s\n",
timestamp,
modes[backup->backup_mode],
backup->tli,
parent_tli,
duration,
data_bytes_str,
arclog_bytes_str,
srvlog_bytes_str,
backup_bytes_str,
status2str(backup->status));
}
}