Skip to content

Commit 34c0574

Browse files
committed
Restore to_backup sizes after copying metadata from from_backup
1 parent 8b1b53b commit 34c0574

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/merge.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
168168
merge_files_arg *threads_args = NULL;
169169
int i;
170170
bool merge_isok = true;
171+
int64 to_data_bytes,
172+
to_wal_bytes;
171173

172174
elog(INFO, "Merging backup %s with backup %s", from_backup_id, to_backup_id);
173175

@@ -282,26 +284,28 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
282284
*/
283285
to_backup->status = BACKUP_STATUS_OK;
284286
/* Compute summary of size of regular files in the backup */
285-
to_backup->data_bytes = 0;
287+
to_data_bytes = 0;
286288
for (i = 0; i < parray_num(files); i++)
287289
{
288290
pgFile *file = (pgFile *) parray_get(files, i);
289291

290292
if (S_ISDIR(file->mode))
291-
to_backup->data_bytes += 4096;
293+
to_data_bytes += 4096;
292294
/* Count the amount of the data actually copied */
293295
else if (S_ISREG(file->mode))
294-
to_backup->data_bytes += file->write_size;
296+
to_data_bytes += file->write_size;
295297
}
296298
/* compute size of wal files of this backup stored in the archive */
297299
if (!to_backup->stream)
298-
to_backup->wal_bytes = instance_config.xlog_seg_size *
300+
to_wal_bytes = instance_config.xlog_seg_size *
299301
(to_backup->stop_lsn / instance_config.xlog_seg_size -
300302
to_backup->start_lsn / instance_config.xlog_seg_size + 1);
301303
else
302-
to_backup->wal_bytes = BYTES_INVALID;
304+
to_wal_bytes = BYTES_INVALID;
303305

304306
write_backup_filelist(to_backup, files, from_database_path);
307+
to_backup->data_bytes = to_data_bytes;
308+
to_backup->wal_bytes = to_wal_bytes;
305309
write_backup(to_backup);
306310

307311
delete_source_backup:
@@ -314,6 +318,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
314318
/*
315319
* Delete files which are not in from_backup file list.
316320
*/
321+
parray_qsort(files, pgFileComparePathDesc);
317322
for (i = 0; i < parray_num(to_files); i++)
318323
{
319324
pgFile *file = (pgFile *) parray_get(to_files, i);
@@ -341,6 +346,9 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
341346
to_backup->backup_mode = BACKUP_MODE_FULL;
342347
to_backup->status = BACKUP_STATUS_OK;
343348
to_backup->parent_backup = INVALID_BACKUP_ID;
349+
/* Restore sizes */
350+
to_backup->data_bytes = to_data_bytes;
351+
to_backup->wal_bytes = to_wal_bytes;
344352
write_backup(to_backup);
345353

346354
/* Cleanup */

0 commit comments

Comments
 (0)