Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit096a12b

Browse files
committed
add size and duration fields to backup.control.
update it during backup every 10 seconds
1 parent7ef2945 commit096a12b

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

‎src/catalog.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ write_backup_status(pgBackup *backup, BackupStatus status)
9191
pgBackupFree(tmp);
9292
}
9393

94+
/* update some fields of backup control file */
95+
void
96+
write_backup_control_on_the_fly(pgBackup*backup)
97+
{
98+
pgBackup*tmp;
99+
100+
tmp=read_backup(backup->start_time);
101+
if (!tmp)
102+
{
103+
/*
104+
* Silently exit the function, since read_backup already logged the
105+
* warning message.
106+
*/
107+
return;
108+
}
109+
110+
tmp->status=backup->status;
111+
tmp->size_on_disk=backup->size_on_disk;
112+
backup->duration=difftime(time(NULL),backup->start_time);
113+
tmp->duration=backup->duration;
114+
write_backup(tmp);
115+
116+
pgBackupFree(tmp);
117+
}
118+
94119
/*
95120
* Create exclusive lockfile in the backup's directory.
96121
*/
@@ -585,6 +610,9 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
585610
/* print external directories list */
586611
if (backup->external_dir_str)
587612
fio_fprintf(out,"external-dirs = '%s'\n",backup->external_dir_str);
613+
614+
fio_fprintf(out,"size-on-disk = "INT64_FORMAT"\n",backup->size_on_disk);
615+
fio_fprintf(out,"duration = "INT64_FORMAT"\n",backup->duration);
588616
}
589617

590618
/*
@@ -640,6 +668,7 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
640668
#defineBUFFERSZ BLCKSZ*500
641669
charbuf[BUFFERSZ];
642670
size_twrite_len=0;
671+
int64backup_size_on_disk=BYTES_INVALID;
643672

644673
pgBackupGetPath(backup,path,lengthof(path),DATABASE_FILE_LIST);
645674
snprintf(path_temp,sizeof(path_temp),"%s.tmp",path);
@@ -661,14 +690,14 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
661690
if (!file->backuped)
662691
continue;
663692

664-
/* omit root directory portion */
665-
if (root&&strstr(path,root)==path)
666-
path=GetRelativePath(path,root);
667-
elseif (file->external_dir_num&&external_list)
693+
backup_size_on_disk+=file->write_size;
694+
if (file->external_dir_num&&external_list)
668695
{
669696
path=GetRelativePath(path,parray_get(external_list,
670697
file->external_dir_num-1));
671698
}
699+
else
700+
path=file->rel_path;
672701

673702
len=sprintf(line,"{\"path\":\"%s\", \"size\":\""INT64_FORMAT"\", "
674703
"\"mode\":\"%u\", \"is_datafile\":\"%u\", "
@@ -737,6 +766,9 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
737766
elog(ERROR,"Cannot rename configuration file \"%s\" to \"%s\": %s",
738767
path_temp,path,strerror(errno_temp));
739768
}
769+
770+
backup->size_on_disk=backup_size_on_disk;
771+
write_backup_control_on_the_fly(backup);
740772
}
741773

742774
/*
@@ -784,6 +816,8 @@ readBackupControlFile(const char *path)
784816
{'b',0,"from-replica",&backup->from_replica,SOURCE_FILE_STRICT},
785817
{'s',0,"primary-conninfo",&backup->primary_conninfo,SOURCE_FILE_STRICT},
786818
{'s',0,"external-dirs",&backup->external_dir_str,SOURCE_FILE_STRICT},
819+
{'I',0,"size-on-disk",&backup->size_on_disk,SOURCE_FILE_STRICT},
820+
{'I',0,"duration",&backup->duration,SOURCE_FILE_STRICT},
787821
{0}
788822
};
789823

@@ -1015,6 +1049,9 @@ pgBackupInit(pgBackup *backup)
10151049
backup->program_version[0]='\0';
10161050
backup->server_version[0]='\0';
10171051
backup->external_dir_str=NULL;
1052+
1053+
backup->size_on_disk=BYTES_INVALID;
1054+
backup->duration= (time_t)0;
10181055
}
10191056

10201057
/* free pgBackup object */

‎src/pg_probackup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ struct pgBackup
310310
* in the format suitable for recovery.conf */
311311
char*external_dir_str;/* List of external directories,
312312
* separated by ':' */
313+
314+
int64size_on_disk;/* updated based on backup_content.control */
315+
int64duration;/* TODO write better comment. time(NULL)-start_time */
313316
};
314317

315318
/* Recovery target for restore and validate subcommands */
@@ -547,6 +550,7 @@ extern int do_validate_all(void);
547550
externpgBackup*read_backup(time_ttimestamp);
548551
externvoidwrite_backup(pgBackup*backup);
549552
externvoidwrite_backup_status(pgBackup*backup,BackupStatusstatus);
553+
externvoidwrite_backup_control_on_the_fly(pgBackup*backup);
550554
externboollock_backup(pgBackup*backup);
551555

552556
externconstchar*pgBackupGetBackupMode(pgBackup*backup);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp