3
3
* archive.c: - pg_probackup specific archive commands for archive backups.
4
4
*
5
5
*
6
- * Portions Copyright (c) 2018-2021 , Postgres Professional
6
+ * Portions Copyright (c) 2018-2022 , Postgres Professional
7
7
*
8
8
*-------------------------------------------------------------------------
9
9
*/
@@ -497,7 +497,8 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
497
497
498
498
/* Partial segment is considered stale, so reuse it */
499
499
elog (LOG , "Reusing stale temp WAL file \"%s\"" , to_fullpath_part );
500
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
500
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
501
+ elog (ERROR , "Cannot remove stale temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
501
502
502
503
out = fio_open (to_fullpath_part , O_RDWR | O_CREAT | O_EXCL | PG_BINARY , FIO_BACKUP_HOST );
503
504
if (out < 0 )
@@ -522,7 +523,8 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
522
523
/* cleanup */
523
524
fclose (in );
524
525
fio_close (out );
525
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
526
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
527
+ elog (WARNING , "Cannot remove temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
526
528
return 1 ;
527
529
}
528
530
else
@@ -535,7 +537,8 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
535
537
/* Overwriting is forbidden,
536
538
* so we must unlink partial file and exit with error.
537
539
*/
538
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
540
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
541
+ elog (WARNING , "Cannot remove temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
539
542
elog (ERROR , "WAL file already exists in archive with "
540
543
"different checksum: \"%s\"" , to_fullpath );
541
544
}
@@ -552,16 +555,20 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
552
555
553
556
if (ferror (in ))
554
557
{
555
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
558
+ int save_errno = errno ;
559
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
560
+ elog (WARNING , "Cannot remove temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
556
561
elog (ERROR , "Cannot read source file \"%s\": %s" ,
557
- from_fullpath , strerror (errno ));
562
+ from_fullpath , strerror (save_errno ));
558
563
}
559
564
560
565
if (read_len > 0 && fio_write_async (out , buf , read_len ) != read_len )
561
566
{
562
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
567
+ int save_errno = errno ;
568
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
569
+ elog (WARNING , "Cannot cleanup temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
563
570
elog (ERROR , "Cannot write to destination temp file \"%s\": %s" ,
564
- to_fullpath_part , strerror (errno ));
571
+ to_fullpath_part , strerror (save_errno ));
565
572
}
566
573
567
574
if (feof (in ))
@@ -574,17 +581,20 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
574
581
/* Writing is asynchronous in case of push in remote mode, so check agent status */
575
582
if (fio_check_error_fd (out , & errmsg ))
576
583
{
577
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
584
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
585
+ elog (WARNING , "Cannot cleanup temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
578
586
elog (ERROR , "Cannot write to the remote file \"%s\": %s" ,
579
587
to_fullpath_part , errmsg );
580
588
}
581
589
582
590
/* close temp file */
583
591
if (fio_close (out ) != 0 )
584
592
{
585
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
593
+ int save_errno = errno ;
594
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
595
+ elog (WARNING , "Cannot cleanup temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
586
596
elog (ERROR , "Cannot close temp WAL file \"%s\": %s" ,
587
- to_fullpath_part , strerror (errno ));
597
+ to_fullpath_part , strerror (save_errno ));
588
598
}
589
599
590
600
/* sync temp file to disk */
@@ -602,9 +612,11 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
602
612
/* Rename temp file to destination file */
603
613
if (fio_rename (to_fullpath_part , to_fullpath , FIO_BACKUP_HOST ) < 0 )
604
614
{
605
- fio_unlink (to_fullpath_part , FIO_BACKUP_HOST );
615
+ int save_errno = errno ;
616
+ if (fio_remove (to_fullpath_part , false, FIO_BACKUP_HOST ) != 0 )
617
+ elog (WARNING , "Cannot cleanup temp WAL file \"%s\": %s" , to_fullpath_part , strerror (errno ));
606
618
elog (ERROR , "Cannot rename file \"%s\" to \"%s\": %s" ,
607
- to_fullpath_part , to_fullpath , strerror (errno ));
619
+ to_fullpath_part , to_fullpath , strerror (save_errno ));
608
620
}
609
621
610
622
pg_free (buf );
@@ -743,7 +755,8 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
743
755
744
756
/* Partial segment is considered stale, so reuse it */
745
757
elog (LOG , "Reusing stale temp WAL file \"%s\"" , to_fullpath_gz_part );
746
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
758
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
759
+ elog (ERROR , "Cannot remove stale compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
747
760
748
761
out = fio_gzopen (to_fullpath_gz_part , PG_BINARY_W , compress_level , FIO_BACKUP_HOST );
749
762
if (out == NULL )
@@ -771,7 +784,8 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
771
784
/* cleanup */
772
785
fclose (in );
773
786
fio_gzclose (out );
774
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
787
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
788
+ elog (WARNING , "Cannot remove compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
775
789
return 1 ;
776
790
}
777
791
else
@@ -784,7 +798,8 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
784
798
/* Overwriting is forbidden,
785
799
* so we must unlink partial file and exit with error.
786
800
*/
787
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
801
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
802
+ elog (WARNING , "Cannot remove compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
788
803
elog (ERROR , "WAL file already exists in archive with "
789
804
"different checksum: \"%s\"" , to_fullpath_gz );
790
805
}
@@ -801,16 +816,20 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
801
816
802
817
if (ferror (in ))
803
818
{
804
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
819
+ int save_errno = errno ;
820
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
821
+ elog (WARNING , "Cannot remove compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
805
822
elog (ERROR , "Cannot read from source file \"%s\": %s" ,
806
- from_fullpath , strerror (errno ));
823
+ from_fullpath , strerror (save_errno ));
807
824
}
808
825
809
826
if (read_len > 0 && fio_gzwrite (out , buf , read_len ) != read_len )
810
827
{
811
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
828
+ int save_errno = errno ;
829
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
830
+ elog (WARNING , "Cannot cleanup compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
812
831
elog (ERROR , "Cannot write to compressed temp WAL file \"%s\": %s" ,
813
- to_fullpath_gz_part , get_gz_error (out , errno ));
832
+ to_fullpath_gz_part , get_gz_error (out , save_errno ));
814
833
}
815
834
816
835
if (feof (in ))
@@ -823,17 +842,20 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
823
842
/* Writing is asynchronous in case of push in remote mode, so check agent status */
824
843
if (fio_check_error_fd_gz (out , & errmsg ))
825
844
{
826
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
845
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
846
+ elog (WARNING , "Cannot cleanup remote compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
827
847
elog (ERROR , "Cannot write to the remote compressed file \"%s\": %s" ,
828
848
to_fullpath_gz_part , errmsg );
829
849
}
830
850
831
851
/* close temp file, TODO: make it synchronous */
832
852
if (fio_gzclose (out ) != 0 )
833
853
{
834
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
854
+ int save_errno = errno ;
855
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
856
+ elog (WARNING , "Cannot cleanup compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
835
857
elog (ERROR , "Cannot close compressed temp WAL file \"%s\": %s" ,
836
- to_fullpath_gz_part , strerror (errno ));
858
+ to_fullpath_gz_part , strerror (save_errno ));
837
859
}
838
860
839
861
/* sync temp file to disk */
@@ -852,9 +874,11 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
852
874
/* Rename temp file to destination file */
853
875
if (fio_rename (to_fullpath_gz_part , to_fullpath_gz , FIO_BACKUP_HOST ) < 0 )
854
876
{
855
- fio_unlink (to_fullpath_gz_part , FIO_BACKUP_HOST );
877
+ int save_errno = errno ;
878
+ if (fio_remove (to_fullpath_gz_part , false, FIO_BACKUP_HOST ) != 0 )
879
+ elog (WARNING , "Cannot cleanup compressed temp WAL file \"%s\": %s" , to_fullpath_gz_part , strerror (errno ));
856
880
elog (ERROR , "Cannot rename file \"%s\" to \"%s\": %s" ,
857
- to_fullpath_gz_part , to_fullpath_gz , strerror (errno ));
881
+ to_fullpath_gz_part , to_fullpath_gz , strerror (save_errno ));
858
882
}
859
883
860
884
pg_free (buf );
0 commit comments