@@ -1113,25 +1113,26 @@ backup_cleanup(bool fatal, void *userdata)
1113
1113
static long
1114
1114
file_size (const char * file )
1115
1115
{
1116
- struct stat st ;
1117
- stat (file , & st );
1118
- elog (NOTICE , "file_size(). %lu" , st .st_size );
1119
- return st .st_size ;
1120
- // long r;
1121
- // FILE *f = fopen(file, "r");
1122
- //
1123
- // if (!f)
1124
- // {
1125
- // elog(ERROR, "pg_probackup: could not open file \"%s\" for reading: %s\n",
1126
- // file, strerror(errno));
1127
- // return -1;
1128
- // }
1129
- // fseek(f, 0, SEEK_END);
1130
- // r = ftell(f);
1131
- // fclose(f);
1132
- // return r;
1116
+ long r ;
1117
+ FILE * f = fopen (file , "r" );
1118
+
1119
+ if (!f )
1120
+ {
1121
+ elog (ERROR , "pg_probackup: could not open file \"%s\" for reading: %s\n" ,
1122
+ file , strerror (errno ));
1123
+ return -1 ;
1124
+ }
1125
+ fseek (f , 0 , SEEK_END );
1126
+ r = ftell (f );
1127
+ fclose (f );
1128
+ return r ;
1133
1129
}
1134
1130
1131
+ /*
1132
+ * Find corresponding file in previous backup.
1133
+ * Compare generations and return true if we don't need full copy
1134
+ * of the file, but just part of it.
1135
+ */
1135
1136
bool
1136
1137
backup_compressed_file_partially (pgFile * file , void * arg , size_t * skip_size )
1137
1138
{
@@ -1147,35 +1148,29 @@ backup_compressed_file_partially(pgFile *file, void *arg, size_t *skip_size)
1147
1148
if (p )
1148
1149
prev_file = * p ;
1149
1150
1150
- elog (NOTICE , "file '%s' generation: prev %d, now %d" ,
1151
- file -> path , prev_file -> generation , file -> generation );
1152
-
1153
1151
/* If file's gc generation has changed since last backup, just copy it*/
1154
- if (prev_file
1155
- && prev_file -> generation == file -> generation )
1152
+ if (prev_file && prev_file -> generation == file -> generation )
1156
1153
{
1157
1154
current_file_size = file_size (file -> path );
1158
1155
1159
- elog (NOTICE , "prev->write_size %lu, current_file_size %lu" ,
1160
- prev_file -> write_size , current_file_size );
1161
-
1162
1156
if (prev_file -> write_size == BYTES_INVALID )
1163
1157
return false;
1164
1158
1165
1159
* skip_size = prev_file -> write_size ;
1166
1160
1167
1161
if (current_file_size >= prev_file -> write_size )
1168
1162
{
1169
- elog (NOTICE , "Backup part of the file. %s : %lu" ,
1170
- file -> path , current_file_size - * skip_size );
1163
+ elog (LOG , "Backup file %s partially: prev_size %lu, current_size %lu" ,
1164
+ file -> path , prev_file -> write_size , current_file_size );
1171
1165
result = true;
1172
1166
}
1173
1167
else
1174
- elog (ERROR , "Something went wrong. current_file_size %lu, prev %lu" ,
1175
- current_file_size , prev_file -> write_size );
1168
+ elog (ERROR , "Something is wrong with %s . current_file_size %lu, prev %lu" ,
1169
+ file -> path , current_file_size , prev_file -> write_size );
1176
1170
}
1177
1171
else
1178
- elog (NOTICE , "Copy full file. Generations are different" );
1172
+ elog (LOG , "Copy full %s. Generations are different: old=%d; new=%d" ,
1173
+ file -> path , prev_file -> generation , file -> generation );
1179
1174
}
1180
1175
1181
1176
return result ;
@@ -1368,14 +1363,14 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1368
1363
relative = file -> path + strlen (root ) + 1 ;
1369
1364
if (is_pgdata &&
1370
1365
!path_is_prefix_of_path ("base" , relative ) &&
1371
- /*!path_is_prefix_of_path("global", relative) &&*/
1366
+ /*!path_is_prefix_of_path("global", relative) &&*/ //TODO What's wrong with this line?
1372
1367
!path_is_prefix_of_path ("pg_tblspc" , relative ))
1373
1368
continue ;
1374
1369
1375
1370
/* Get file name from path */
1376
1371
fname = last_dir_separator (relative );
1377
1372
1378
- /* Remove temp tables */
1373
+ /* Remove temp tables from the list */
1379
1374
if (fname [0 ] == 't' && isdigit (fname [1 ]))
1380
1375
{
1381
1376
pgFileFree (file );
@@ -1385,7 +1380,7 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1385
1380
}
1386
1381
1387
1382
path_len = strlen (file -> path );
1388
- /* Get link ptrack file to realations files */
1383
+ /* Get link ptrack file to relations files */
1389
1384
if (path_len > 6 && strncmp (file -> path + (path_len - 6 ), "ptrack" , 6 ) == 0 )
1390
1385
{
1391
1386
pgFile * search_file ;
@@ -1394,20 +1389,21 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1394
1389
while (true) {
1395
1390
pgFile tmp_file ;
1396
1391
tmp_file .path = pg_strdup (file -> path );
1397
- /* I hope segno not more than 999999 */
1392
+
1393
+ /* Segno fits into 6 digits since it is not more than 4000 */
1398
1394
if (segno > 0 )
1399
1395
sprintf (tmp_file .path + path_len - 7 , ".%d" , segno );
1400
1396
else
1401
1397
tmp_file .path [path_len - 7 ] = '\0' ;
1402
1398
1403
1399
pre_search_file = (pgFile * * ) parray_bsearch (list_file , & tmp_file , pgFileComparePath );
1404
1400
1405
- if (is_compressed_data_file (& tmp_file , list_file ))
1406
- {
1407
- elog (NOTICE , "file %s is compressed, don't remove it from list" , tmp_file .path );
1408
- pg_free (tmp_file .path );
1409
- break ;
1410
- }
1401
+ // if (is_compressed_data_file(&tmp_file, list_file))
1402
+ // {
1403
+ // elog(NOTICE, "file %s is compressed, don't remove it from list", tmp_file.path);
1404
+ // pg_free(tmp_file.path);
1405
+ // break;
1406
+ // }
1411
1407
1412
1408
if (pre_search_file != NULL )
1413
1409
{
@@ -1422,6 +1418,7 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1422
1418
segno ++ ;
1423
1419
}
1424
1420
1421
+ /* Remove ptrack file itself from backup list */
1425
1422
pgFileFree (file );
1426
1423
parray_remove (list_file , i );
1427
1424
i -- ;
0 commit comments