@@ -1113,25 +1113,26 @@ backup_cleanup(bool fatal, void *userdata)
11131113static long
11141114file_size (const char * file )
11151115{
1116- struct stat st ;
1117- stat (file ,& st );
1118- elog (NOTICE ,"file_size(). %lu" ,st .st_size );
1119- return st .st_size ;
1120- // longr;
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 ;
11331129}
11341130
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+ */
11351136bool
11361137backup_compressed_file_partially (pgFile * file ,void * arg ,size_t * skip_size )
11371138{
@@ -1147,35 +1148,29 @@ backup_compressed_file_partially(pgFile *file, void *arg, size_t *skip_size)
11471148if (p )
11481149prev_file = * p ;
11491150
1150- elog (NOTICE ,"file '%s' generation: prev %d, now %d" ,
1151- file -> path ,prev_file -> generation ,file -> generation );
1152-
11531151/* 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 )
11561153{
11571154current_file_size = file_size (file -> path );
11581155
1159- elog (NOTICE ,"prev->write_size %lu, current_file_size %lu" ,
1160- prev_file -> write_size ,current_file_size );
1161-
11621156if (prev_file -> write_size == BYTES_INVALID )
11631157return false;
11641158
11651159* skip_size = prev_file -> write_size ;
11661160
11671161if (current_file_size >=prev_file -> write_size )
11681162{
1169- elog (NOTICE ,"Backuppart of the file. %s: %lu" ,
1170- file -> path ,current_file_size - * skip_size );
1163+ elog (LOG ,"Backup file %spartially: prev_size %lu, current_size %lu" ,
1164+ file -> path ,prev_file -> write_size , current_file_size );
11711165result = true;
11721166}
11731167else
1174- elog (ERROR ,"Somethingwent wrong. current_file_size %lu, prev %lu" ,
1175- current_file_size ,prev_file -> write_size );
1168+ elog (ERROR ,"Somethingis wrong with %s . current_file_size %lu, prev %lu" ,
1169+ file -> path , current_file_size ,prev_file -> write_size );
11761170}
11771171else
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 );
11791174}
11801175
11811176return result ;
@@ -1368,14 +1363,14 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
13681363relative = file -> path + strlen (root )+ 1 ;
13691364if (is_pgdata &&
13701365!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?
13721367!path_is_prefix_of_path ("pg_tblspc" ,relative ))
13731368continue ;
13741369
13751370/* Get file name from path */
13761371fname = last_dir_separator (relative );
13771372
1378- /* Remove temp tables */
1373+ /* Remove temp tablesfrom the list */
13791374if (fname [0 ]== 't' && isdigit (fname [1 ]))
13801375{
13811376pgFileFree (file );
@@ -1385,7 +1380,7 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
13851380}
13861381
13871382path_len = strlen (file -> path );
1388- /* Get link ptrack file torealations files */
1383+ /* Get link ptrack file torelations files */
13891384if (path_len > 6 && strncmp (file -> path + (path_len - 6 ),"ptrack" ,6 )== 0 )
13901385{
13911386pgFile * search_file ;
@@ -1394,20 +1389,21 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
13941389while (true) {
13951390pgFile tmp_file ;
13961391tmp_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 */
13981394if (segno > 0 )
13991395sprintf (tmp_file .path + path_len - 7 ,".%d" ,segno );
14001396else
14011397tmp_file .path [path_len - 7 ]= '\0' ;
14021398
14031399pre_search_file = (pgFile * * )parray_bsearch (list_file ,& tmp_file ,pgFileComparePath );
14041400
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+ // }
14111407
14121408if (pre_search_file != NULL )
14131409{
@@ -1422,6 +1418,7 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
14221418segno ++ ;
14231419}
14241420
1421+ /* Remove ptrack file itself from backup list */
14251422pgFileFree (file );
14261423parray_remove (list_file ,i );
14271424i -- ;