@@ -801,13 +801,17 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
801
801
* and its mtime is less than parent backup start time ... */
802
802
if ((pg_strcasecmp (file -> name , RELMAPPER_FILENAME ) != 0 ) &&
803
803
(prev_file && file -> exists_in_prev &&
804
+ file -> size == prev_file -> size &&
804
805
file -> mtime <= parent_backup_time ))
805
806
{
806
807
/*
807
808
* file could be deleted under our feets.
808
809
* But then backup_non_data_file_internal will handle it safely
809
810
*/
810
- file -> crc = fio_get_crc32 (FIO_DB_HOST , from_fullpath , false, true);
811
+ if (file -> forkName != cfm )
812
+ file -> crc = fio_get_crc32 (FIO_DB_HOST , from_fullpath , false, true);
813
+ else
814
+ file -> crc = fio_get_crc32_truncated (FIO_DB_HOST , from_fullpath , true);
811
815
812
816
/* ...and checksum is the same... */
813
817
if (EQ_CRC32C (file -> crc , prev_file -> crc ))
@@ -1332,8 +1336,12 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
1332
1336
if (already_exists )
1333
1337
{
1334
1338
/* compare checksums of already existing file and backup file */
1335
- pg_crc32 file_crc = fio_get_crc32 (FIO_DB_HOST , to_fullpath , false,
1336
- false);
1339
+ pg_crc32 file_crc ;
1340
+ if (tmp_file -> forkName == cfm &&
1341
+ tmp_file -> uncompressed_size > tmp_file -> write_size )
1342
+ file_crc = fio_get_crc32_truncated (FIO_DB_HOST , to_fullpath , false);
1343
+ else
1344
+ file_crc = fio_get_crc32 (FIO_DB_HOST , to_fullpath , false, false);
1337
1345
1338
1346
if (file_crc == tmp_file -> crc )
1339
1347
{
@@ -1390,10 +1398,12 @@ backup_non_data_file_internal(const char *from_fullpath,
1390
1398
const char * to_fullpath , pgFile * file ,
1391
1399
bool missing_ok )
1392
1400
{
1393
- FILE * in = NULL ;
1394
1401
FILE * out = NULL ;
1395
- ssize_t read_len = 0 ;
1396
- char * buf = NULL ;
1402
+ char * errmsg = NULL ;
1403
+ int rc ;
1404
+ bool cut_zero_tail ;
1405
+
1406
+ cut_zero_tail = file -> forkName == cfm ;
1397
1407
1398
1408
INIT_CRC32C (file -> crc );
1399
1409
@@ -1415,107 +1425,44 @@ backup_non_data_file_internal(const char *from_fullpath,
1415
1425
1416
1426
/* backup remote file */
1417
1427
if (fio_is_remote (FIO_DB_HOST ))
1418
- {
1419
- char * errmsg = NULL ;
1420
- int rc = fio_send_file (from_fullpath , to_fullpath , out , file , & errmsg );
1428
+ rc = fio_send_file ( from_fullpath , out , cut_zero_tail , file , & errmsg );
1429
+ else
1430
+ rc = fio_send_file_local (from_fullpath , out , cut_zero_tail , file , & errmsg );
1421
1431
1422
- /* handle errors */
1423
- if (rc == FILE_MISSING )
1424
- {
1425
- /* maybe deleted, it's not error in case of backup */
1426
- if (missing_ok )
1427
- {
1428
- elog (LOG , "File \"%s\" is not found" , from_fullpath );
1429
- file -> write_size = FILE_NOT_FOUND ;
1430
- goto cleanup ;
1431
- }
1432
- else
1433
- elog (ERROR , "File \"%s\" is not found" , from_fullpath );
1434
- }
1435
- else if (rc == WRITE_FAILED )
1436
- elog (ERROR , "Cannot write to \"%s\": %s" , to_fullpath , strerror (errno ));
1437
- else if (rc != SEND_OK )
1432
+ /* handle errors */
1433
+ if (rc == FILE_MISSING )
1434
+ {
1435
+ /* maybe deleted, it's not error in case of backup */
1436
+ if (missing_ok )
1438
1437
{
1439
- if (errmsg )
1440
- elog (ERROR , "%s" , errmsg );
1441
- else
1442
- elog (ERROR , "Cannot access remote file \"%s\"" , from_fullpath );
1438
+ elog (LOG , "File \"%s\" is not found" , from_fullpath );
1439
+ file -> write_size = FILE_NOT_FOUND ;
1440
+ goto cleanup ;
1443
1441
}
1444
-
1445
- pg_free ( errmsg );
1442
+ else
1443
+ elog ( ERROR , "File \"%s\" is not found" , from_fullpath );
1446
1444
}
1447
- /* backup local file */
1448
- else
1445
+ else if (rc == WRITE_FAILED )
1446
+ elog (ERROR , "Cannot write to \"%s\": %s" , to_fullpath , strerror (errno ));
1447
+ else if (rc != SEND_OK )
1449
1448
{
1450
- /* open source file for read */
1451
- in = fopen (from_fullpath , PG_BINARY_R );
1452
- if (in == NULL )
1453
- {
1454
- /* maybe deleted, it's not error in case of backup */
1455
- if (errno == ENOENT )
1456
- {
1457
- if (missing_ok )
1458
- {
1459
- elog (LOG , "File \"%s\" is not found" , from_fullpath );
1460
- file -> write_size = FILE_NOT_FOUND ;
1461
- goto cleanup ;
1462
- }
1463
- else
1464
- elog (ERROR , "File \"%s\" is not found" , from_fullpath );
1465
- }
1466
-
1467
- elog (ERROR , "Cannot open file \"%s\": %s" , from_fullpath ,
1468
- strerror (errno ));
1469
- }
1470
-
1471
- /* disable stdio buffering for local input/output files to avoid triple buffering */
1472
- setvbuf (in , NULL , _IONBF , BUFSIZ );
1473
- setvbuf (out , NULL , _IONBF , BUFSIZ );
1474
-
1475
- /* allocate 64kB buffer */
1476
- buf = pgut_malloc (CHUNK_SIZE );
1477
-
1478
- /* copy content and calc CRC */
1479
- for (;;)
1480
- {
1481
- read_len = fread (buf , 1 , CHUNK_SIZE , in );
1482
-
1483
- if (ferror (in ))
1484
- elog (ERROR , "Cannot read from file \"%s\": %s" ,
1485
- from_fullpath , strerror (errno ));
1486
-
1487
- if (read_len > 0 )
1488
- {
1489
- if (fwrite (buf , 1 , read_len , out ) != read_len )
1490
- elog (ERROR , "Cannot write to file \"%s\": %s" , to_fullpath ,
1491
- strerror (errno ));
1492
-
1493
- /* update CRC */
1494
- COMP_CRC32C (file -> crc , buf , read_len );
1495
- file -> read_size += read_len ;
1496
- }
1497
-
1498
- if (feof (in ))
1499
- break ;
1500
- }
1449
+ if (errmsg )
1450
+ elog (ERROR , "%s" , errmsg );
1451
+ else
1452
+ elog (ERROR , "Cannot access remote file \"%s\"" , from_fullpath );
1501
1453
}
1502
1454
1503
- file -> write_size = (int64 ) file -> read_size ;
1504
-
1505
- if (file -> write_size > 0 )
1506
- file -> uncompressed_size = file -> write_size ;
1455
+ file -> uncompressed_size = file -> read_size ;
1507
1456
1508
1457
cleanup :
1458
+ if (errmsg != NULL )
1459
+ pg_free (errmsg );
1460
+
1509
1461
/* finish CRC calculation and store into pgFile */
1510
1462
FIN_CRC32C (file -> crc );
1511
1463
1512
- if (in && fclose (in ))
1513
- elog (ERROR , "Cannot close the file \"%s\": %s" , from_fullpath , strerror (errno ));
1514
-
1515
1464
if (out && fclose (out ))
1516
1465
elog (ERROR , "Cannot close the file \"%s\": %s" , to_fullpath , strerror (errno ));
1517
-
1518
- pg_free (buf );
1519
1466
}
1520
1467
1521
1468
/*
0 commit comments