@@ -799,6 +799,7 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
799799 * and its mtime is less than parent backup start time ... */
800800 if ((pg_strcasecmp (file -> name , RELMAPPER_FILENAME ) != 0 ) &&
801801 (prev_file && file -> exists_in_prev &&
802+ file -> size == prev_file -> size &&
802803 file -> mtime <= parent_backup_time ))
803804 {
804805 /*
@@ -1330,7 +1331,12 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
13301331 if (already_exists )
13311332 {
13321333 /* compare checksums of already existing file and backup file */
1333- pg_crc32 file_crc = fio_get_crc32 (to_fullpath , FIO_DB_HOST , false, false);
1334+ pg_crc32 file_crc ;
1335+ if (tmp_file -> forkName == cfm &&
1336+ tmp_file -> uncompressed_size > tmp_file -> write_size )
1337+ file_crc = fio_get_crc32_truncated (to_fullpath , FIO_DB_HOST );
1338+ else
1339+ file_crc = fio_get_crc32 (to_fullpath , FIO_DB_HOST , false, false);
13341340
13351341 if (file_crc == tmp_file -> crc )
13361342 {
@@ -1387,10 +1393,12 @@ backup_non_data_file_internal(const char *from_fullpath,
13871393 const char * to_fullpath , pgFile * file ,
13881394 bool missing_ok )
13891395{
1390- FILE * in = NULL ;
13911396 FILE * out = NULL ;
1392- ssize_t read_len = 0 ;
1393- char * buf = NULL ;
1397+ char * errmsg = NULL ;
1398+ int rc ;
1399+ bool cut_zero_tail ;
1400+
1401+ cut_zero_tail = file -> forkName == cfm ;
13941402
13951403 INIT_FILE_CRC32 (true, file -> crc );
13961404
@@ -1412,107 +1420,44 @@ backup_non_data_file_internal(const char *from_fullpath,
14121420
14131421 /* backup remote file */
14141422 if (fio_is_remote (FIO_DB_HOST ))
1415- {
1416- char * errmsg = NULL ;
1417- int rc = fio_send_file (from_fullpath , to_fullpath , out , file , & errmsg );
1423+ rc = fio_send_file ( from_fullpath , out , cut_zero_tail , file , & errmsg );
1424+ else
1425+ rc = fio_send_file_local (from_fullpath , out , cut_zero_tail , file , & errmsg );
14181426
1419- /* handle errors */
1420- if (rc == FILE_MISSING )
1421- {
1422- /* maybe deleted, it's not error in case of backup */
1423- if (missing_ok )
1424- {
1425- elog (LOG , "File \"%s\" is not found" , from_fullpath );
1426- file -> write_size = FILE_NOT_FOUND ;
1427- goto cleanup ;
1428- }
1429- else
1430- elog (ERROR , "File \"%s\" is not found" , from_fullpath );
1431- }
1432- else if (rc == WRITE_FAILED )
1433- elog (ERROR , "Cannot write to \"%s\": %s" , to_fullpath , strerror (errno ));
1434- else if (rc != SEND_OK )
1427+ /* handle errors */
1428+ if (rc == FILE_MISSING )
1429+ {
1430+ /* maybe deleted, it's not error in case of backup */
1431+ if (missing_ok )
14351432 {
1436- if (errmsg )
1437- elog (ERROR , "%s" , errmsg );
1438- else
1439- elog (ERROR , "Cannot access remote file \"%s\"" , from_fullpath );
1433+ elog (LOG , "File \"%s\" is not found" , from_fullpath );
1434+ file -> write_size = FILE_NOT_FOUND ;
1435+ goto cleanup ;
14401436 }
1441-
1442- pg_free ( errmsg );
1437+ else
1438+ elog ( ERROR , "File \"%s\" is not found" , from_fullpath );
14431439 }
1444- /* backup local file */
1445- else
1440+ else if (rc == WRITE_FAILED )
1441+ elog (ERROR , "Cannot write to \"%s\": %s" , to_fullpath , strerror (errno ));
1442+ else if (rc != SEND_OK )
14461443 {
1447- /* open source file for read */
1448- in = fopen (from_fullpath , PG_BINARY_R );
1449- if (in == NULL )
1450- {
1451- /* maybe deleted, it's not error in case of backup */
1452- if (errno == ENOENT )
1453- {
1454- if (missing_ok )
1455- {
1456- elog (LOG , "File \"%s\" is not found" , from_fullpath );
1457- file -> write_size = FILE_NOT_FOUND ;
1458- goto cleanup ;
1459- }
1460- else
1461- elog (ERROR , "File \"%s\" is not found" , from_fullpath );
1462- }
1463-
1464- elog (ERROR , "Cannot open file \"%s\": %s" , from_fullpath ,
1465- strerror (errno ));
1466- }
1467-
1468- /* disable stdio buffering for local input/output files to avoid triple buffering */
1469- setvbuf (in , NULL , _IONBF , BUFSIZ );
1470- setvbuf (out , NULL , _IONBF , BUFSIZ );
1471-
1472- /* allocate 64kB buffer */
1473- buf = pgut_malloc (CHUNK_SIZE );
1474-
1475- /* copy content and calc CRC */
1476- for (;;)
1477- {
1478- read_len = fread (buf , 1 , CHUNK_SIZE , in );
1479-
1480- if (ferror (in ))
1481- elog (ERROR , "Cannot read from file \"%s\": %s" ,
1482- from_fullpath , strerror (errno ));
1483-
1484- if (read_len > 0 )
1485- {
1486- if (fwrite (buf , 1 , read_len , out ) != read_len )
1487- elog (ERROR , "Cannot write to file \"%s\": %s" , to_fullpath ,
1488- strerror (errno ));
1489-
1490- /* update CRC */
1491- COMP_FILE_CRC32 (true, file -> crc , buf , read_len );
1492- file -> read_size += read_len ;
1493- }
1494-
1495- if (feof (in ))
1496- break ;
1497- }
1444+ if (errmsg )
1445+ elog (ERROR , "%s" , errmsg );
1446+ else
1447+ elog (ERROR , "Cannot access remote file \"%s\"" , from_fullpath );
14981448 }
14991449
1500- file -> write_size = (int64 ) file -> read_size ;
1501-
1502- if (file -> write_size > 0 )
1503- file -> uncompressed_size = file -> write_size ;
1450+ file -> uncompressed_size = file -> read_size ;
15041451
15051452cleanup :
1453+ if (errmsg != NULL )
1454+ pg_free (errmsg );
1455+
15061456 /* finish CRC calculation and store into pgFile */
15071457 FIN_FILE_CRC32 (true, file -> crc );
15081458
1509- if (in && fclose (in ))
1510- elog (ERROR , "Cannot close the file \"%s\": %s" , from_fullpath , strerror (errno ));
1511-
15121459 if (out && fclose (out ))
15131460 elog (ERROR , "Cannot close the file \"%s\": %s" , to_fullpath , strerror (errno ));
1514-
1515- pg_free (buf );
15161461}
15171462
15181463/*
0 commit comments