@@ -1047,7 +1047,7 @@ def del_test_dir(self, module_name, fname):
1047
1047
except :
1048
1048
pass
1049
1049
1050
- def pgdata_content (self , directory , ignore_ptrack = True ):
1050
+ def pgdata_content (self , pgdata , ignore_ptrack = True ):
1051
1051
""" return dict with directory content. "
1052
1052
" TAKE IT AFTER CHECKPOINT or BACKUP"""
1053
1053
dirs_to_ignore = [
@@ -1064,9 +1064,10 @@ def pgdata_content(self, directory, ignore_ptrack=True):
1064
1064
# '_ptrack'
1065
1065
# )
1066
1066
directory_dict = {}
1067
- directory_dict ['pgdata' ] = directory
1067
+ directory_dict ['pgdata' ] = pgdata
1068
1068
directory_dict ['files' ] = {}
1069
- for root , dirs , files in os .walk (directory , followlinks = True ):
1069
+ directory_dict ['dirs' ] = []
1070
+ for root , dirs , files in os .walk (pgdata , followlinks = True ):
1070
1071
dirs [:] = [d for d in dirs if d not in dirs_to_ignore ]
1071
1072
for file in files :
1072
1073
if (
@@ -1076,7 +1077,7 @@ def pgdata_content(self, directory, ignore_ptrack=True):
1076
1077
continue
1077
1078
1078
1079
file_fullpath = os .path .join (root , file )
1079
- file_relpath = os .path .relpath (file_fullpath , directory )
1080
+ file_relpath = os .path .relpath (file_fullpath , pgdata )
1080
1081
directory_dict ['files' ][file_relpath ] = {'is_datafile' : False }
1081
1082
directory_dict ['files' ][file_relpath ]['md5' ] = hashlib .md5 (
1082
1083
open (file_fullpath , 'rb' ).read ()).hexdigest ()
@@ -1089,12 +1090,51 @@ def pgdata_content(self, directory, ignore_ptrack=True):
1089
1090
file_fullpath , size_in_pages
1090
1091
)
1091
1092
1093
+ for root , dirs , files in os .walk (pgdata , topdown = False , followlinks = True ):
1094
+ for directory in dirs :
1095
+ directory_path = os .path .join (root , directory )
1096
+ directory_relpath = os .path .relpath (directory_path , pgdata )
1097
+
1098
+ found = False
1099
+ for d in dirs_to_ignore :
1100
+ if d in directory_relpath :
1101
+ found = True
1102
+ break
1103
+
1104
+ # check if directory already here as part of larger directory
1105
+ if not found :
1106
+ for d in directory_dict ['dirs' ]:
1107
+ # print("OLD dir {0}".format(d))
1108
+ if directory_relpath in d :
1109
+ found = True
1110
+ break
1111
+
1112
+ if not found :
1113
+ directory_dict ['dirs' ].append (directory_relpath )
1114
+
1092
1115
return directory_dict
1093
1116
1094
1117
def compare_pgdata (self , original_pgdata , restored_pgdata ):
1095
1118
""" return dict with directory content. DO IT BEFORE RECOVERY"""
1096
1119
fail = False
1097
1120
error_message = 'Restored PGDATA is not equal to original!\n '
1121
+
1122
+ # Compare directories
1123
+ for directory in restored_pgdata ['dirs' ]:
1124
+ if directory not in original_pgdata ['dirs' ]:
1125
+ fail = True
1126
+ error_message += '\n Directory is not present'
1127
+ error_message += ' in original PGDATA: {0}\n ' .format (
1128
+ os .path .join (restored_pgdata ['pgdata' ], directory ))
1129
+
1130
+ for directory in original_pgdata ['dirs' ]:
1131
+ if directory not in restored_pgdata ['dirs' ]:
1132
+ fail = True
1133
+ error_message += '\n Directory dissappeared'
1134
+ error_message += ' in restored PGDATA: {0}\n ' .format (
1135
+ os .path .join (restored_pgdata ['pgdata' ], directory ))
1136
+
1137
+
1098
1138
for file in restored_pgdata ['files' ]:
1099
1139
# File is present in RESTORED PGDATA
1100
1140
# but not present in ORIGINAL
0 commit comments