@@ -2097,3 +2097,157 @@ def test_issue_132(self):
2097
2097
2098
2098
# Clean after yourself
2099
2099
self .del_test_dir (module_name , fname )
2100
+
2101
+ # @unittest.skip("skip")
2102
+ def test_issue_132_1 (self ):
2103
+ """
2104
+ https://github.com/postgrespro/pg_probackup/issues/132
2105
+ """
2106
+ fname = self .id ().split ('.' )[3 ]
2107
+ backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
2108
+ node = self .make_simple_node (
2109
+ base_dir = os .path .join (module_name , fname , 'node' ),
2110
+ set_replication = True ,
2111
+ initdb_params = ['--data-checksums' ],
2112
+ pg_options = {
2113
+ 'autovacuum' : 'off' })
2114
+
2115
+ # TODO: check version of old binary, it should be 2.1.4, 2.1.5 or 2.2.1
2116
+
2117
+ self .init_pb (backup_dir )
2118
+ self .add_instance (backup_dir , 'node' , node )
2119
+ node .slow_start ()
2120
+
2121
+ with node .connect ("postgres" ) as conn :
2122
+ for i in range (30000 ):
2123
+ conn .execute (
2124
+ "CREATE TABLE t_{0} as select 1" .format (i ))
2125
+ conn .commit ()
2126
+
2127
+ full_id = self .backup_node (
2128
+ backup_dir , 'node' , node , options = ['--stream' ], old_binary = True )
2129
+
2130
+ delta_id = self .backup_node (
2131
+ backup_dir , 'node' , node , backup_type = 'delta' ,
2132
+ options = ['--stream' ], old_binary = True )
2133
+
2134
+ node .cleanup ()
2135
+
2136
+ # make sure that new binary can detect corruption
2137
+ try :
2138
+ self .validate_pb (backup_dir , 'node' , backup_id = full_id )
2139
+ # we should die here because exception is what we expect to happen
2140
+ self .assertEqual (
2141
+ 1 , 0 ,
2142
+ "Expecting Error because FULL backup is CORRUPT"
2143
+ "\n Output: {0} \n CMD: {1}" .format (
2144
+ repr (self .output ), self .cmd ))
2145
+ except ProbackupException as e :
2146
+ self .assertIn (
2147
+ 'WARNING: Backup {0} is a victim of metadata corruption' .format (full_id ),
2148
+ e .message ,
2149
+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
2150
+ repr (e .message ), self .cmd ))
2151
+
2152
+ try :
2153
+ self .validate_pb (backup_dir , 'node' , backup_id = delta_id )
2154
+ # we should die here because exception is what we expect to happen
2155
+ self .assertEqual (
2156
+ 1 , 0 ,
2157
+ "Expecting Error because FULL backup is CORRUPT"
2158
+ "\n Output: {0} \n CMD: {1}" .format (
2159
+ repr (self .output ), self .cmd ))
2160
+ except ProbackupException as e :
2161
+ self .assertIn (
2162
+ 'WARNING: Backup {0} is a victim of metadata corruption' .format (full_id ),
2163
+ e .message ,
2164
+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
2165
+ repr (e .message ), self .cmd ))
2166
+
2167
+ self .assertEqual (
2168
+ 'CORRUPT' , self .show_pb (backup_dir , 'node' , full_id )['status' ],
2169
+ 'Backup STATUS should be "CORRUPT"' )
2170
+
2171
+ self .assertEqual (
2172
+ 'ORPHAN' , self .show_pb (backup_dir , 'node' , delta_id )['status' ],
2173
+ 'Backup STATUS should be "ORPHAN"' )
2174
+
2175
+ # check that revalidation is working correctly
2176
+ try :
2177
+ self .restore_node (
2178
+ backup_dir , 'node' , node , backup_id = delta_id )
2179
+ # we should die here because exception is what we expect to happen
2180
+ self .assertEqual (
2181
+ 1 , 0 ,
2182
+ "Expecting Error because FULL backup is CORRUPT"
2183
+ "\n Output: {0} \n CMD: {1}" .format (
2184
+ repr (self .output ), self .cmd ))
2185
+ except ProbackupException as e :
2186
+ self .assertIn (
2187
+ 'WARNING: Backup {0} is a victim of metadata corruption' .format (full_id ),
2188
+ e .message ,
2189
+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
2190
+ repr (e .message ), self .cmd ))
2191
+
2192
+ self .assertEqual (
2193
+ 'CORRUPT' , self .show_pb (backup_dir , 'node' , full_id )['status' ],
2194
+ 'Backup STATUS should be "CORRUPT"' )
2195
+
2196
+ self .assertEqual (
2197
+ 'ORPHAN' , self .show_pb (backup_dir , 'node' , delta_id )['status' ],
2198
+ 'Backup STATUS should be "ORPHAN"' )
2199
+
2200
+ # check that '--no-validate' do not allow to restore ORPHAN backup
2201
+ # try:
2202
+ # self.restore_node(
2203
+ # backup_dir, 'node', node, backup_id=delta_id,
2204
+ # options=['--no-validate'])
2205
+ # # we should die here because exception is what we expect to happen
2206
+ # self.assertEqual(
2207
+ # 1, 0,
2208
+ # "Expecting Error because FULL backup is CORRUPT"
2209
+ # "\n Output: {0} \n CMD: {1}".format(
2210
+ # repr(self.output), self.cmd))
2211
+ # except ProbackupException as e:
2212
+ # self.assertIn(
2213
+ # 'Insert data',
2214
+ # e.message,
2215
+ # '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
2216
+ # repr(e.message), self.cmd))
2217
+
2218
+ node .cleanup ()
2219
+
2220
+ output = self .restore_node (
2221
+ backup_dir , 'node' , node , backup_id = full_id , options = ['--force' ])
2222
+
2223
+ self .assertIn (
2224
+ 'WARNING: Backup {0} is not valid, restore is forced' .format (full_id ),
2225
+ output )
2226
+
2227
+ self .assertIn (
2228
+ 'INFO: Restore of backup {0} completed.' .format (full_id ),
2229
+ output )
2230
+
2231
+ node .cleanup ()
2232
+
2233
+ output = self .restore_node (
2234
+ backup_dir , 'node' , node , backup_id = delta_id , options = ['--force' ])
2235
+
2236
+ self .assertIn (
2237
+ 'WARNING: Backup {0} is orphan.' .format (delta_id ),
2238
+ output )
2239
+
2240
+ self .assertIn (
2241
+ 'WARNING: Backup {0} is not valid, restore is forced' .format (full_id ),
2242
+ output )
2243
+
2244
+ self .assertIn (
2245
+ 'WARNING: Backup {0} is not valid, restore is forced' .format (delta_id ),
2246
+ output )
2247
+
2248
+ self .assertIn (
2249
+ 'INFO: Restore of backup {0} completed.' .format (delta_id ),
2250
+ output )
2251
+
2252
+ # Clean after yourself
2253
+ self .del_test_dir (module_name , fname )
0 commit comments