@@ -856,11 +856,12 @@ def pgdata_content(self, directory):
856856 ]
857857 files_to_ignore = [
858858 'postmaster.pid' , 'postmaster.opts' ,
859- 'pg_internal.init' , 'postgresql.auto.conf'
859+ 'pg_internal.init' , 'postgresql.auto.conf' ,
860+ 'backup_label' , 'tablespace_map' , 'recovery.conf' ,
861+ 'ptrack_control' , 'ptrack_init'
860862 ]
861863 suffixes_to_ignore = (
862- '_ptrack' , 'ptrack_control' ,
863- 'pg_control' , 'ptrack_init' , 'backup_label'
864+ '_ptrack'
864865 )
865866 directory_dict = {}
866867 directory_dict ['pgdata' ] = directory
@@ -893,57 +894,74 @@ def pgdata_content(self, directory):
893894 def compare_pgdata (self , original_pgdata , restored_pgdata ):
894895 """ return dict with directory content. DO IT BEFORE RECOVERY"""
895896 fail = False
896- error_message = ''
897+ error_message = 'Restored PGDATA is not equal to original! \n '
897898 for file in restored_pgdata ['files' ]:
898899 # File is present in RESTORED PGDATA
899900 # but not present in ORIGINAL
900- if (
901- file not in original_pgdata ['files' ] and
902- not file .endswith ('backup_label' )
903- ):
901+ # only backup_label is allowed
902+ if file not in original_pgdata ['files' ]:
904903 fail = True
905- error_message += 'File is not present'
906- error_message += ' in original PGDATA:\n {0}' .format (
907- os .path .join (restored_pgdata ['pgdata' ], file )
908- )
904+ error_message += '\n File is not present'
905+ error_message += ' in original PGDATA: {0}\n ' .format (
906+ os .path .join (restored_pgdata ['pgdata' ], file ))
907+
909908 for file in original_pgdata ['files' ]:
910909 if file in restored_pgdata ['files' ]:
911910
912911 if (
913912 original_pgdata ['files' ][file ]['md5' ] !=
914913 restored_pgdata ['files' ][file ]['md5' ]
915914 ):
915+ fail = True
916916 error_message += (
917- '\n Checksumm mismatch.\n '
918- ' File_old: {0}\n Checksumm_old : {1}\n '
919- ' File_new: {2}\n Checksumm_new : {3}\n ' ).format (
917+ '\n File Checksumm mismatch.\n '
918+ 'File_old: {0}\n Checksumm_old : {1}\n '
919+ 'File_new: {2}\n Checksumm_new : {3}\n ' ).format (
920920 os .path .join (original_pgdata ['pgdata' ], file ),
921921 original_pgdata ['files' ][file ]['md5' ],
922922 os .path .join (restored_pgdata ['pgdata' ], file ),
923923 restored_pgdata ['files' ][file ]['md5' ]
924924 )
925- fail = True
925+
926926 if original_pgdata ['files' ][file ]['is_datafile' ]:
927- for page in original_pgdata ['files' ][
928- file ]['md5_per_page' ]:
927+ for page in original_pgdata ['files' ][file ]['md5_per_page' ]:
928+ if page not in restored_pgdata ['files' ][file ]['md5_per_page' ]:
929+ error_message += (
930+ '\n Page {0} dissappeared.\n '
931+ 'File: {1}\n ' ).format (
932+ page ,
933+ os .path .join (
934+ restored_pgdata ['pgdata' ],
935+ file
936+ )
937+ )
938+ continue
939+
929940 if original_pgdata ['files' ][file ][
930941 'md5_per_page' ][page ] != restored_pgdata [
931942 'files' ][file ]['md5_per_page' ][page ]:
932943 error_message += (
933- 'PAGE: {0}\n '
934- ' PAGE Checksumm_old: {1}\n '
935- ' PAGE Checksumm_new: {2}\n '
944+ '\n Page checksumm mismatch: {0}\n '
945+ ' PAGE Checksumm_old: {1}\n '
946+ ' PAGE Checksumm_new: {2}\n '
947+ ' File: {3}\n '
936948 ).format (
937949 page ,
938950 original_pgdata ['files' ][file ][
939951 'md5_per_page' ][page ],
940952 restored_pgdata ['files' ][file ][
941- 'md5_per_page' ][page ])
953+ 'md5_per_page' ][page ],
954+ os .path .join (
955+ restored_pgdata ['pgdata' ], file )
956+ )
957+ for page in restored_pgdata ['files' ][file ]['md5_per_page' ]:
958+ if page not in original_pgdata ['files' ][file ]['md5_per_page' ]:
959+ error_message += '\n Extra page {0}\n File: {1}\n ' .format (page , os .path .join (restored_pgdata ['pgdata' ], file ))
942960
943961 else :
944962 error_message += (
945- '\n File dissappearance.'
946- ' File: {0}' ).format (
963+ '\n File dissappearance.\n '
964+ 'File: {0}\n ' ).format (
947965 os .path .join (restored_pgdata ['pgdata' ], file )
948966 )
949967 fail = True
@@ -1146,7 +1164,7 @@ def _execute(self, cmd, running=True):
11461164 self .proc .stdin .flush ()
11471165
11481166 while True :
1149- sleep (1 )
1167+ # sleep(1)
11501168 line = self .proc .stdout .readline ()
11511169 output += [line ]
11521170 if self .verbose :
0 commit comments