@@ -711,7 +711,7 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
711
711
}
712
712
713
713
/*
714
- * If non-data file exists in previous backup
714
+ * If nonedata file exists in previous backup
715
715
* and its mtime is less than parent backup start time ... */
716
716
if (prev_file && file -> exists_in_prev &&
717
717
file -> mtime <= parent_backup_time )
@@ -1136,7 +1136,7 @@ restore_non_data_file_internal(FILE *in, FILE *out, pgFile *file,
1136
1136
1137
1137
/* check for interrupt */
1138
1138
if (interrupted || thread_interrupted )
1139
- elog (ERROR , "Interrupted during non-data file restore" );
1139
+ elog (ERROR , "Interrupted during nonedata file restore" );
1140
1140
1141
1141
read_len = fread (buf , 1 , STDIO_BUFSIZE , in );
1142
1142
@@ -1165,7 +1165,6 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
1165
1165
pgFile * dest_file , FILE * out , const char * to_fullpath ,
1166
1166
bool already_exists )
1167
1167
{
1168
- // int i;
1169
1168
char from_root [MAXPGPATH ];
1170
1169
char from_fullpath [MAXPGPATH ];
1171
1170
FILE * in = NULL ;
@@ -1203,14 +1202,19 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
1203
1202
*/
1204
1203
if (!tmp_file )
1205
1204
{
1206
- elog (ERROR , "Failed to locate non-data file \"%s\" in backup %s" ,
1205
+ elog (ERROR , "Failed to locate nonedata file \"%s\" in backup %s" ,
1207
1206
dest_file -> rel_path , base36enc (tmp_backup -> start_time ));
1208
1207
continue ;
1209
1208
}
1210
1209
1211
1210
/* Full copy is found and it is null sized, nothing to do here */
1212
1211
if (tmp_file -> write_size == 0 )
1212
+ {
1213
+ /* In case of incremental restore truncate file just to be safe */
1214
+ if (already_exists && fio_ftruncate (out , 0 ))
1215
+ elog (ERROR , "Cannot truncate file \"%s\": %s" , strerror (errno ));
1213
1216
return 0 ;
1217
+ }
1214
1218
1215
1219
/* Full copy is found */
1216
1220
if (tmp_file -> write_size > 0 )
@@ -1222,14 +1226,14 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
1222
1226
1223
1227
/* sanity */
1224
1228
if (!tmp_backup )
1225
- elog (ERROR , "Failed to found a backup containing full copy of non-data file \"%s\"" ,
1229
+ elog (ERROR , "Failed to locate a backup containing full copy of nonedata file \"%s\"" ,
1226
1230
to_fullpath );
1227
1231
1228
1232
if (!tmp_file )
1229
- elog (ERROR , "Failed to locate a full copy of non-data file \"%s\"" , to_fullpath );
1233
+ elog (ERROR , "Failed to locate a full copy of nonedata file \"%s\"" , to_fullpath );
1230
1234
1231
1235
if (tmp_file -> write_size <= 0 )
1232
- elog (ERROR , "Full copy of non-data file has invalid size. "
1236
+ elog (ERROR , "Full copy of nonedata file has invalid size. "
1233
1237
"Metadata corruption in backup %s in file: \"%s\"" ,
1234
1238
base36enc (tmp_backup -> start_time ), to_fullpath );
1235
1239
@@ -1245,6 +1249,10 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
1245
1249
to_fullpath );
1246
1250
return 0 ;
1247
1251
}
1252
+
1253
+ /* Checksum mismatch, truncate file and overwrite it */
1254
+ if (fio_ftruncate (out , 0 ))
1255
+ elog (ERROR , "Cannot truncate file \"%s\": %s" , strerror (errno ));
1248
1256
}
1249
1257
1250
1258
if (tmp_file -> external_dir_num == 0 )
@@ -1264,7 +1272,7 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
1264
1272
elog (ERROR , "Cannot open backup file \"%s\": %s" , from_fullpath ,
1265
1273
strerror (errno ));
1266
1274
1267
- /* disable stdio buffering for non-data files */
1275
+ /* disable stdio buffering for nonedata files */
1268
1276
setvbuf (in , NULL , _IONBF , BUFSIZ );
1269
1277
1270
1278
/* do actual work */
@@ -1793,7 +1801,7 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
1793
1801
char in_buf [STDIO_BUFSIZE ];
1794
1802
1795
1803
/* open file */
1796
- in = fopen (fullpath , PG_BINARY_R );
1804
+ in = fopen (fullpath , "r+" );
1797
1805
if (!in )
1798
1806
elog (ERROR , "Cannot open source file \"%s\": %s" , fullpath , strerror (errno ));
1799
1807
@@ -1864,7 +1872,7 @@ get_lsn_map(const char *fullpath, uint32 checksum_version,
1864
1872
Assert (shift_lsn > 0 );
1865
1873
1866
1874
/* open file */
1867
- in = fopen (fullpath , PG_BINARY_R );
1875
+ in = fopen (fullpath , "r+" );
1868
1876
if (!in )
1869
1877
elog (ERROR , "Cannot open source file \"%s\": %s" , fullpath , strerror (errno ));
1870
1878
0 commit comments