@@ -856,11 +856,12 @@ def pgdata_content(self, directory):
856
856
]
857
857
files_to_ignore = [
858
858
'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'
860
862
]
861
863
suffixes_to_ignore = (
862
- '_ptrack' , 'ptrack_control' ,
863
- 'pg_control' , 'ptrack_init' , 'backup_label'
864
+ '_ptrack'
864
865
)
865
866
directory_dict = {}
866
867
directory_dict ['pgdata' ] = directory
@@ -893,57 +894,74 @@ def pgdata_content(self, directory):
893
894
def compare_pgdata (self , original_pgdata , restored_pgdata ):
894
895
""" return dict with directory content. DO IT BEFORE RECOVERY"""
895
896
fail = False
896
- error_message = ''
897
+ error_message = 'Restored PGDATA is not equal to original! \n '
897
898
for file in restored_pgdata ['files' ]:
898
899
# File is present in RESTORED PGDATA
899
900
# 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' ]:
904
903
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
+
909
908
for file in original_pgdata ['files' ]:
910
909
if file in restored_pgdata ['files' ]:
911
910
912
911
if (
913
912
original_pgdata ['files' ][file ]['md5' ] !=
914
913
restored_pgdata ['files' ][file ]['md5' ]
915
914
):
915
+ fail = True
916
916
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 (
920
920
os .path .join (original_pgdata ['pgdata' ], file ),
921
921
original_pgdata ['files' ][file ]['md5' ],
922
922
os .path .join (restored_pgdata ['pgdata' ], file ),
923
923
restored_pgdata ['files' ][file ]['md5' ]
924
924
)
925
- fail = True
925
+
926
926
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
+
929
940
if original_pgdata ['files' ][file ][
930
941
'md5_per_page' ][page ] != restored_pgdata [
931
942
'files' ][file ]['md5_per_page' ][page ]:
932
943
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 '
936
948
).format (
937
949
page ,
938
950
original_pgdata ['files' ][file ][
939
951
'md5_per_page' ][page ],
940
952
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 ))
942
960
943
961
else :
944
962
error_message += (
945
- '\n File dissappearance.'
946
- ' File: {0}' ).format (
963
+ '\n File dissappearance.\n '
964
+ 'File: {0}\n ' ).format (
947
965
os .path .join (restored_pgdata ['pgdata' ], file )
948
966
)
949
967
fail = True
@@ -1146,7 +1164,7 @@ def _execute(self, cmd, running=True):
1146
1164
self .proc .stdin .flush ()
1147
1165
1148
1166
while True :
1149
- sleep (1 )
1167
+ # sleep(1)
1150
1168
line = self .proc .stdout .readline ()
1151
1169
output += [line ]
1152
1170
if self .verbose :
0 commit comments