@@ -476,10 +476,10 @@ def run_pb(self, command, async=False, gdb=False):
476476 raise ProbackupException (e .output .decode ("utf-8" ), self .cmd )
477477
478478 def run_binary (self , command , async = False ):
479+ if self .verbose :
480+ print ([' ' .join (map (str , command ))])
479481 try :
480482 if async :
481- if self .verbose :
482- print (command )
483483 return subprocess .Popen (
484484 command ,
485485 stdin = subprocess .PIPE ,
@@ -488,8 +488,6 @@ def run_binary(self, command, async=False):
488488 env = self .test_env
489489 )
490490 else :
491- if self .verbose :
492- print (command )
493491 self .output = subprocess .check_output (
494492 command ,
495493 stderr = subprocess .STDOUT ,
@@ -859,46 +857,92 @@ def pgdata_content(self, directory):
859857 ]
860858 suffixes_to_ignore = (
861859 '_ptrack' , 'ptrack_control' ,
862- 'pg_control' , 'ptrack_init'
860+ 'pg_control' , 'ptrack_init' , 'backup_label'
863861 )
864862 directory_dict = {}
865863 directory_dict ['pgdata' ] = directory
866864 directory_dict ['files' ] = {}
867865 for root , dirs , files in os .walk (directory , followlinks = True ):
868866 dirs [:] = [d for d in dirs if d not in dirs_to_ignore ]
869867 for file in files :
870- if file in files_to_ignore or file .endswith (
871- suffixes_to_ignore
872- ):
873- continue
874- file = os .path .join (root , file )
875- file_relpath = os .path .relpath (file , directory )
876- directory_dict ['files' ][file_relpath ] = hashlib .md5 (
877- open (file , 'rb' ).read ()).hexdigest ()
868+ if (
869+ file in files_to_ignore or
870+ file .endswith (suffixes_to_ignore )
871+ ):
872+ continue
873+
874+ file_fullpath = os .path .join (root , file )
875+ file_relpath = os .path .relpath (file_fullpath , directory )
876+ directory_dict ['files' ][file_relpath ] = {'is_datafile' : False }
877+ directory_dict ['files' ][file_relpath ]['md5' ] = hashlib .md5 (
878+ open (file_fullpath , 'rb' ).read ()).hexdigest ()
879+
880+ if file .isdigit ():
881+ directory_dict ['files' ][file_relpath ]['is_datafile' ] = True
882+ size_in_pages = os .path .getsize (file_fullpath )/ 8192
883+ directory_dict ['files' ][file_relpath ][
884+ 'md5_per_page' ] = self .get_md5_per_page_for_fork (
885+ file_fullpath , size_in_pages
886+ )
887+
878888 return directory_dict
879889
880890 def compare_pgdata (self , original_pgdata , restored_pgdata ):
881891 """ return dict with directory content. DO IT BEFORE RECOVERY"""
882892 fail = False
883893 error_message = ''
894+ for file in restored_pgdata ['files' ]:
895+ # File is present in RESTORED PGDATA
896+ # but not present in ORIGINAL
897+ if (
898+ file not in original_pgdata ['files' ] and
899+ not file .endswith ('backup_label' )
900+ ):
901+ fail = True
902+ error_message += 'File is not present'
903+ error_message += ' in original PGDATA:\n {0}' .format (
904+ os .path .join (restored_pgdata ['pgdata' ], file )
905+ )
884906 for file in original_pgdata ['files' ]:
885907 if file in restored_pgdata ['files' ]:
908+
886909 if (
887- original_pgdata ['files' ][file ] !=
888- restored_pgdata ['files' ][file ]
910+ original_pgdata ['files' ][file ][ 'md5' ] !=
911+ restored_pgdata ['files' ][file ][ 'md5' ]
889912 ):
890- error_message += '\n Checksumm mismatch.\n '
891- ' File_old: {0}\n Checksumm_old: {1}\n '
892- ' File_new: {2}\n Checksumm_new: {3}\n ' .format (
913+ error_message += (
914+ '\n Checksumm mismatch.\n '
915+ ' File_old: {0}\n Checksumm_old: {1}\n '
916+ ' File_new: {2}\n Checksumm_new: {3}\n ' ).format (
893917 os .path .join (original_pgdata ['pgdata' ], file ),
894- original_pgdata ['files' ][file ],
918+ original_pgdata ['files' ][file ][ 'md5' ] ,
895919 os .path .join (restored_pgdata ['pgdata' ], file ),
896- restored_pgdata ['files' ][file ]
897- )
920+ restored_pgdata ['files' ][file ][ 'md5' ]
921+ )
898922 fail = True
923+ if original_pgdata ['files' ][file ]['is_datafile' ]:
924+ for page in original_pgdata ['files' ][
925+ file ]['md5_per_page' ]:
926+ if original_pgdata ['files' ][file ][
927+ 'md5_per_page' ][page ] != restored_pgdata [
928+ 'files' ][file ]['md5_per_page' ][page ]:
929+ error_message += (
930+ 'PAGE: {0}\n '
931+ ' PAGE Checksumm_old: {1}\n '
932+ ' PAGE Checksumm_new: {2}\n '
933+ ).format (
934+ page ,
935+ original_pgdata ['files' ][file ][
936+ 'md5_per_page' ][page ],
937+ restored_pgdata ['files' ][file ][
938+ 'md5_per_page' ][page ])
939+
899940 else :
900- error_message += '\n File dissappearance.'
901- ' File: {0}/{1}' .format (restored_pgdata ['pgdata' ], file )
941+ error_message += (
942+ '\n File dissappearance.'
943+ ' File: {0}' ).format (
944+ os .path .join (restored_pgdata ['pgdata' ], file )
945+ )
902946 fail = True
903947 self .assertFalse (fail , error_message )
904948
0 commit comments