@@ -56,7 +56,7 @@ static void
5656backup_data_page (pgFile * file ,XLogRecPtr prev_backup_start_lsn ,
5757BlockNumber blknum ,BlockNumber nblocks ,
5858FILE * in ,FILE * out ,
59- pg_crc32 * crc )
59+ pg_crc32 * crc , int * n_skipped )
6060{
6161BackupPageHeader header ;
6262off_t offset ;
@@ -134,7 +134,10 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
134134if (!XLogRecPtrIsInvalid (prev_backup_start_lsn )
135135&& !XLogRecPtrIsInvalid (page_lsn )
136136&& page_lsn < prev_backup_start_lsn )
137+ {
138+ * n_skipped += 1 ;
137139return ;
140+ }
138141
139142/* Verify checksum */
140143if (current .checksum_version && !is_zero_page )
@@ -195,6 +198,8 @@ backup_data_file(const char *from_root, const char *to_root,
195198FILE * out ;
196199BlockNumber blknum = 0 ;
197200BlockNumber nblocks = 0 ;
201+ int n_blocks_skipped = 0 ;
202+ int n_blocks_read = 0 ;
198203
199204/* reset size summary */
200205file -> read_size = 0 ;
@@ -253,26 +258,24 @@ backup_data_file(const char *from_root, const char *to_root,
253258if (file -> pagemap .bitmapsize == 0 )
254259{
255260for (blknum = 0 ;blknum < nblocks ;blknum ++ )
261+ {
256262backup_data_page (file ,prev_backup_start_lsn ,blknum ,
257- nblocks ,in ,out ,& (file -> crc ));
263+ nblocks ,in ,out ,& (file -> crc ),& n_blocks_skipped );
264+ n_blocks_read ++ ;
265+ }
258266}
259267else
260268{
261269datapagemap_iterator_t * iter ;
262270iter = datapagemap_iterate (& file -> pagemap );
263271while (datapagemap_next (iter ,& blknum ))
272+ {
264273backup_data_page (file ,prev_backup_start_lsn ,blknum ,
265- nblocks ,in ,out ,& (file -> crc ));
274+ nblocks ,in ,out ,& (file -> crc ),& n_blocks_skipped );
275+ n_blocks_read ++ ;
276+ }
266277
267278pg_free (iter );
268- /*
269- * If we have pagemap then file can't be a zero size.
270- * Otherwise, we will clear the last file.
271- * Increase read_size to delete after.
272- * TODO rewrite this code
273- */
274- if (file -> read_size == 0 )
275- file -> read_size ++ ;
276279}
277280
278281/* update file permission */
@@ -294,8 +297,11 @@ backup_data_file(const char *from_root, const char *to_root,
294297if (file -> read_size == 0 )
295298file -> is_datafile = false;
296299
297- /* We do not backup if all pages skipped. */
298- if (file -> write_size == 0 && file -> read_size > 0 )
300+ /*
301+ * If we have pagemap then file can't be a zero size.
302+ * Otherwise, we will clear the last file.
303+ */
304+ if (n_blocks_read == n_blocks_skipped )
299305{
300306if (remove (to_path )== -1 )
301307elog (ERROR ,"cannot remove file \"%s\": %s" ,to_path ,