@@ -171,10 +171,13 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
171
171
172
172
if (current .backup_mode != BACKUP_MODE_FULL )
173
173
{
174
- dest_id = get_system_identifier (dest_pgdata , FIO_LOCAL_HOST , false);
174
+ ControlFileData dst_control ;
175
+ get_control_file_or_back_file (dest_pgdata , FIO_LOCAL_HOST , & dst_control );
176
+ dest_id = dst_control .system_identifier ;
177
+
175
178
if (source_conn_id != dest_id )
176
- elog (ERROR , "Database identifiers mismatch: we connected to DB id %lu , but in \"%s\" we found id %lu " ,
177
- source_conn_id , dest_pgdata , dest_id );
179
+ elog (ERROR , "Database identifiers mismatch: we connected to DB id %llu , but in \"%s\" we found id %llu " ,
180
+ ( long long ) source_conn_id , dest_pgdata , ( long long ) dest_id );
178
181
}
179
182
}
180
183
@@ -640,6 +643,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
640
643
ssize_t transfered_walfiles_bytes = 0 ;
641
644
char pretty_source_bytes [20 ];
642
645
646
+ char dest_pg_control_fullpath [MAXPGPATH ];
647
+ char dest_pg_control_bak_fullpath [MAXPGPATH ];
648
+
643
649
source_conn = catchup_init_state (& source_node_info , source_pgdata , dest_pgdata );
644
650
catchup_preflight_checks (& source_node_info , source_conn , source_pgdata , dest_pgdata );
645
651
@@ -935,6 +941,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
935
941
Assert (file -> external_dir_num == 0 );
936
942
if (pg_strcasecmp (file -> name , RELMAPPER_FILENAME ) == 0 )
937
943
redundant = true;
944
+ /* global/pg_control.pbk.bak is always keeped, because it's needed for restart failed incremental restore */
945
+ if (pg_strcasecmp (file -> rel_path , XLOG_CONTROL_BAK_FILE ) == 0 )
946
+ redundant = false;
938
947
939
948
/* if file does not exists in destination list, then we can safely unlink it */
940
949
if (redundant )
@@ -966,6 +975,28 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
966
975
if (dest_filelist )
967
976
parray_qsort (dest_filelist , pgFileCompareRelPathWithExternal );
968
977
978
+ join_path_components (dest_pg_control_fullpath , dest_pgdata , XLOG_CONTROL_FILE );
979
+ join_path_components (dest_pg_control_bak_fullpath , dest_pgdata , XLOG_CONTROL_BAK_FILE );
980
+ /*
981
+ * rename (if it exist) dest control file before restoring
982
+ * if it doesn't exist, that mean, that we already restoring in a previously failed
983
+ * pgdata, where XLOG_CONTROL_BAK_FILE exist
984
+ */
985
+ if (current .backup_mode != BACKUP_MODE_FULL && !dry_run )
986
+ {
987
+ if (!fio_access (dest_pg_control_fullpath , F_OK , FIO_LOCAL_HOST ))
988
+ {
989
+ pgFile * dst_control ;
990
+ dst_control = pgFileNew (dest_pg_control_bak_fullpath , XLOG_CONTROL_BAK_FILE ,
991
+ true,0 , FIO_BACKUP_HOST );
992
+
993
+ if (!fio_access (dest_pg_control_bak_fullpath , F_OK , FIO_LOCAL_HOST ))
994
+ fio_delete (dst_control -> mode , dest_pg_control_bak_fullpath , FIO_LOCAL_HOST );
995
+ fio_rename (dest_pg_control_fullpath , dest_pg_control_bak_fullpath , FIO_LOCAL_HOST );
996
+ pgFileFree (dst_control );
997
+ }
998
+ }
999
+
969
1000
/* run copy threads */
970
1001
elog (INFO , "Start transferring data files" );
971
1002
time (& start_time );
@@ -985,6 +1016,15 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
985
1016
copy_pgcontrol_file (from_fullpath , FIO_DB_HOST ,
986
1017
to_fullpath , FIO_LOCAL_HOST , source_pg_control_file );
987
1018
transfered_datafiles_bytes += source_pg_control_file -> size ;
1019
+
1020
+ /* Now backup control file can be deled */
1021
+ if (current .backup_mode != BACKUP_MODE_FULL && !fio_access (dest_pg_control_bak_fullpath , F_OK , FIO_LOCAL_HOST )){
1022
+ pgFile * dst_control ;
1023
+ dst_control = pgFileNew (dest_pg_control_bak_fullpath , XLOG_CONTROL_BAK_FILE ,
1024
+ true,0 , FIO_BACKUP_HOST );
1025
+ fio_delete (dst_control -> mode , dest_pg_control_bak_fullpath , FIO_LOCAL_HOST );
1026
+ pgFileFree (dst_control );
1027
+ }
988
1028
}
989
1029
990
1030
if (!catchup_isok && !dry_run )
0 commit comments