@@ -91,6 +91,31 @@ write_backup_status(pgBackup *backup, BackupStatus status)
91
91
pgBackupFree (tmp );
92
92
}
93
93
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
+
94
119
/*
95
120
* Create exclusive lockfile in the backup's directory.
96
121
*/
@@ -585,6 +610,9 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
585
610
/* print external directories list */
586
611
if (backup -> external_dir_str )
587
612
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 );
588
616
}
589
617
590
618
/*
@@ -640,6 +668,7 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
640
668
#define BUFFERSZ BLCKSZ*500
641
669
char buf [BUFFERSZ ];
642
670
size_t write_len = 0 ;
671
+ int64 backup_size_on_disk = BYTES_INVALID ;
643
672
644
673
pgBackupGetPath (backup ,path ,lengthof (path ),DATABASE_FILE_LIST );
645
674
snprintf (path_temp ,sizeof (path_temp ),"%s.tmp" ,path );
@@ -661,14 +690,14 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
661
690
if (!file -> backuped )
662
691
continue ;
663
692
664
- /* omit root directory portion */
665
- if (root && strstr (path ,root )== path )
666
- path = GetRelativePath (path ,root );
667
- else if (file -> external_dir_num && external_list )
693
+ backup_size_on_disk += file -> write_size ;
694
+ if (file -> external_dir_num && external_list )
668
695
{
669
696
path = GetRelativePath (path ,parray_get (external_list ,
670
697
file -> external_dir_num - 1 ));
671
698
}
699
+ else
700
+ path = file -> rel_path ;
672
701
673
702
len = sprintf (line ,"{\"path\":\"%s\", \"size\":\"" INT64_FORMAT "\", "
674
703
"\"mode\":\"%u\", \"is_datafile\":\"%u\", "
@@ -737,6 +766,9 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
737
766
elog (ERROR ,"Cannot rename configuration file \"%s\" to \"%s\": %s" ,
738
767
path_temp ,path ,strerror (errno_temp ));
739
768
}
769
+
770
+ backup -> size_on_disk = backup_size_on_disk ;
771
+ write_backup_control_on_the_fly (backup );
740
772
}
741
773
742
774
/*
@@ -784,6 +816,8 @@ readBackupControlFile(const char *path)
784
816
{'b' ,0 ,"from-replica" ,& backup -> from_replica ,SOURCE_FILE_STRICT },
785
817
{'s' ,0 ,"primary-conninfo" ,& backup -> primary_conninfo ,SOURCE_FILE_STRICT },
786
818
{'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 },
787
821
{0 }
788
822
};
789
823
@@ -1015,6 +1049,9 @@ pgBackupInit(pgBackup *backup)
1015
1049
backup -> program_version [0 ]= '\0' ;
1016
1050
backup -> server_version [0 ]= '\0' ;
1017
1051
backup -> external_dir_str = NULL ;
1052
+
1053
+ backup -> size_on_disk = BYTES_INVALID ;
1054
+ backup -> duration = (time_t )0 ;
1018
1055
}
1019
1056
1020
1057
/* free pgBackup object */