Skip to content

Commit 6f2d3f5

Browse files
committed
use data_bytes field instead of introducing new one
1 parent 096a12b commit 6f2d3f5

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

src/backup.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ do_backup_instance(PGconn *backup_conn)
182182
check_external_for_tablespaces(external_dirs, backup_conn);
183183
}
184184

185-
/* Initialize size summary */
186-
current.data_bytes = 0;
187-
188185
/* Obtain current timeline */
189186
current.tli = get_current_timeline(false);
190187

@@ -432,6 +429,7 @@ do_backup_instance(PGconn *backup_conn)
432429
}
433430
else
434431
join_path_components(dirpath, database_path, dir_name);
432+
file->backuped = true;
435433
fio_mkdir(dirpath, DIR_PERMISSION, FIO_BACKUP_HOST);
436434
}
437435

@@ -581,19 +579,6 @@ do_backup_instance(PGconn *backup_conn)
581579
if (external_dirs)
582580
free_dir_list(external_dirs);
583581

584-
/* Compute summary of size of regular files in the backup */
585-
for (i = 0; i < parray_num(backup_files_list); i++)
586-
{
587-
pgFile *file = (pgFile *) parray_get(backup_files_list, i);
588-
589-
if (S_ISDIR(file->mode))
590-
current.data_bytes += 4096;
591-
592-
/* Count the amount of the data actually copied */
593-
if (S_ISREG(file->mode))
594-
current.data_bytes += file->write_size;
595-
}
596-
597582
/* Cleanup */
598583
if (backup_list)
599584
{
@@ -1805,11 +1790,12 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn)
18051790
*/
18061791
if (backup_files_list)
18071792
{
1808-
file = pgFileNew(backup_label, backup_label, true, 0,
1793+
file = pgFileNew(backup_label, PG_BACKUP_LABEL_FILE, true, 0,
18091794
FIO_BACKUP_HOST);
18101795
file->crc = pgFileGetCRC(file->path, true, false,
18111796
&file->read_size, FIO_BACKUP_HOST);
18121797
file->write_size = file->read_size;
1798+
file->backuped = true;
18131799
free(file->path);
18141800
file->path = strdup(PG_BACKUP_LABEL_FILE);
18151801
parray_append(backup_files_list, file);
@@ -1851,13 +1837,14 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn)
18511837

18521838
if (backup_files_list)
18531839
{
1854-
file = pgFileNew(tablespace_map, tablespace_map, true, 0,
1840+
file = pgFileNew(tablespace_map, PG_TABLESPACE_MAP_FILE, true, 0,
18551841
FIO_BACKUP_HOST);
18561842
if (S_ISREG(file->mode))
18571843
{
18581844
file->crc = pgFileGetCRC(file->path, true, false,
18591845
&file->read_size, FIO_BACKUP_HOST);
18601846
file->write_size = file->read_size;
1847+
file->backuped = true;
18611848
}
18621849
free(file->path);
18631850
file->path = strdup(PG_TABLESPACE_MAP_FILE);

src/catalog.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ write_backup_control_on_the_fly(pgBackup *backup)
108108
}
109109

110110
tmp->status = backup->status;
111-
tmp->size_on_disk = backup->size_on_disk;
111+
tmp->data_bytes = backup->data_bytes;
112112
backup->duration = difftime(time(NULL), backup->start_time);
113113
tmp->duration = backup->duration;
114114
write_backup(tmp);
@@ -611,7 +611,6 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
611611
if (backup->external_dir_str)
612612
fio_fprintf(out, "external-dirs = '%s'\n", backup->external_dir_str);
613613

614-
fio_fprintf(out, "size-on-disk = " INT64_FORMAT "\n", backup->size_on_disk);
615614
fio_fprintf(out, "duration = " INT64_FORMAT "\n", backup->duration);
616615
}
617616

@@ -668,7 +667,7 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
668667
#define BUFFERSZ BLCKSZ*500
669668
char buf[BUFFERSZ];
670669
size_t write_len = 0;
671-
int64 backup_size_on_disk = BYTES_INVALID;
670+
int64 backup_size_on_disk = 0;
672671

673672
pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST);
674673
snprintf(path_temp, sizeof(path_temp), "%s.tmp", path);
@@ -687,10 +686,20 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
687686
int len = 0;
688687

689688
i++;
689+
690690
if (!file->backuped)
691+
{
692+
elog(WARNING, "file not backuped %s", file->rel_path);
691693
continue;
694+
}
695+
696+
if (S_ISDIR(file->mode))
697+
backup_size_on_disk += 4096;
698+
699+
/* Count the amount of the data actually copied */
700+
if (S_ISREG(file->mode))
701+
backup_size_on_disk += file->write_size;
692702

693-
backup_size_on_disk += file->write_size;
694703
if (file->external_dir_num && external_list)
695704
{
696705
path = GetRelativePath(path, parray_get(external_list,
@@ -767,7 +776,8 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
767776
path_temp, path, strerror(errno_temp));
768777
}
769778

770-
backup->size_on_disk = backup_size_on_disk;
779+
/* use extra variable to avoid reset of previous data_bytes value in case of error */
780+
backup->data_bytes = backup_size_on_disk;
771781
write_backup_control_on_the_fly(backup);
772782
}
773783

@@ -816,7 +826,6 @@ readBackupControlFile(const char *path)
816826
{'b', 0, "from-replica", &backup->from_replica, SOURCE_FILE_STRICT},
817827
{'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT},
818828
{'s', 0, "external-dirs", &backup->external_dir_str, SOURCE_FILE_STRICT},
819-
{'I', 0, "size-on-disk", &backup->size_on_disk, SOURCE_FILE_STRICT},
820829
{'I', 0, "duration", &backup->duration, SOURCE_FILE_STRICT},
821830
{0}
822831
};
@@ -1050,7 +1059,6 @@ pgBackupInit(pgBackup *backup)
10501059
backup->server_version[0] = '\0';
10511060
backup->external_dir_str = NULL;
10521061

1053-
backup->size_on_disk = BYTES_INVALID;
10541062
backup->duration = (time_t) 0;
10551063
}
10561064

src/pg_probackup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ struct pgBackup
311311
char *external_dir_str; /* List of external directories,
312312
* separated by ':' */
313313

314-
int64 size_on_disk; /* updated based on backup_content.control */
315314
int64 duration; /* TODO write better comment. time(NULL)-start_time */
316315
};
317316

0 commit comments

Comments
 (0)