@@ -860,7 +860,8 @@ restore_data_file(parray *parent_chain, pgFile *dest_file, FILE *out, const char
860860 size_t total_write_len = 0 ;
861861 char * in_buf = pgut_malloc (STDIO_BUFSIZE );
862862
863- for (i = parray_num (parent_chain ) - 1 ; i >= 0 ; i -- )
863+ // for (i = parray_num(parent_chain) - 1; i >= 0; i--)
864+ for (i = 0 ; i < parray_num (parent_chain ); i ++ )
864865 {
865866 char from_root [MAXPGPATH ];
866867 char from_fullpath [MAXPGPATH ];
@@ -916,11 +917,14 @@ restore_data_file(parray *parent_chain, pgFile *dest_file, FILE *out, const char
916917 */
917918 total_write_len += restore_data_file_internal (in , out , tmp_file ,
918919 parse_program_version (backup -> program_version ),
919- from_fullpath , to_fullpath , dest_file -> n_blocks );
920+ from_fullpath , to_fullpath , dest_file -> n_blocks ,
921+ & (dest_file )-> pagemap );
920922
921923 if (fclose (in ) != 0 )
922924 elog (ERROR , "Cannot close file \"%s\": %s" , from_fullpath ,
923925 strerror (errno ));
926+
927+ // datapagemap_print_debug(&(dest_file)->pagemap);
924928 }
925929 pg_free (in_buf );
926930
@@ -929,7 +933,8 @@ restore_data_file(parray *parent_chain, pgFile *dest_file, FILE *out, const char
929933
930934size_t
931935restore_data_file_internal (FILE * in , FILE * out , pgFile * file , uint32 backup_version ,
932- const char * from_fullpath , const char * to_fullpath , int nblocks )
936+ const char * from_fullpath , const char * to_fullpath , int nblocks ,
937+ datapagemap_t * map )
933938{
934939 BackupPageHeader header ;
935940 BlockNumber blknum = 0 ;
@@ -987,9 +992,9 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
987992 }
988993
989994 /* sanity? */
990- if (header .block < blknum )
991- elog (ERROR , "Backup is broken at block %u of \"%s\"" ,
992- blknum , from_fullpath );
995+ // if (header.block < blknum)
996+ // elog(ERROR, "Backup is broken at block %u of \"%s\"",
997+ // blknum, from_fullpath);
993998
994999 blknum = header .block ;
9951000
@@ -1037,6 +1042,15 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
10371042 if (compressed_size > BLCKSZ )
10381043 elog (ERROR , "Size of a blknum %i exceed BLCKSZ" , blknum );
10391044
1045+ /* if this page was already restored, then skip it */
1046+ if (datapagemap_is_set (map , blknum ))
1047+ {
1048+ elog (WARNING , "Skipping block %u because is was already restored" , blknum );
1049+ /* TODO: check error */
1050+ fseek (in , compressed_size , SEEK_CUR );
1051+ continue ;
1052+ }
1053+
10401054 /* read a page from file */
10411055 read_len = fread (page .data , 1 , MAXALIGN (compressed_size ), in );
10421056
@@ -1092,6 +1106,8 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
10921106
10931107 write_len += BLCKSZ ;
10941108 cur_pos = write_pos + BLCKSZ ; /* update current write position */
1109+
1110+ datapagemap_add (map , blknum );
10951111 }
10961112
10971113 elog (VERBOSE , "Copied file \"%s\": %lu bytes" , from_fullpath , write_len );
0 commit comments