@@ -10535,6 +10535,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10535
10535
backup_started_in_recovery ?"standby" :"master" );
10536
10536
appendStringInfo (labelfile ,"START TIME: %s\n" ,strfbuf );
10537
10537
appendStringInfo (labelfile ,"LABEL: %s\n" ,backupidstr );
10538
+ appendStringInfo (labelfile ,"START TIMELINE: %u\n" ,starttli );
10538
10539
10539
10540
/*
10540
10541
* Okay, write the file, or return its contents to caller.
@@ -11015,9 +11016,13 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
11015
11016
(uint32 ) (startpoint >>32 ), (uint32 )startpoint ,startxlogfilename );
11016
11017
fprintf (fp ,"STOP WAL LOCATION: %X/%X (file %s)\n" ,
11017
11018
(uint32 ) (stoppoint >>32 ), (uint32 )stoppoint ,stopxlogfilename );
11018
- /* transfer remaining lines from label to history file */
11019
+ /*
11020
+ * Transfer remaining lines including label and start timeline to
11021
+ * history file.
11022
+ */
11019
11023
fprintf (fp ,"%s" ,remaining );
11020
11024
fprintf (fp ,"STOP TIME: %s\n" ,strfbuf );
11025
+ fprintf (fp ,"STOP TIMELINE: %u\n" ,stoptli );
11021
11026
if (fflush (fp )|| ferror (fp )|| FreeFile (fp ))
11022
11027
ereport (ERROR ,
11023
11028
(errcode_for_file_access (),
@@ -11228,11 +11233,13 @@ read_backup_label(XLogRecPtr *checkPointLoc, bool *backupEndRequired,
11228
11233
bool * backupFromStandby )
11229
11234
{
11230
11235
char startxlogfilename [MAXFNAMELEN ];
11231
- TimeLineID tli ;
11236
+ TimeLineID tli_from_walseg , tli_from_file ;
11232
11237
FILE * lfp ;
11233
11238
char ch ;
11234
11239
char backuptype [20 ];
11235
11240
char backupfrom [20 ];
11241
+ char backuplabel [MAXPGPATH ];
11242
+ char backuptime [128 ];
11236
11243
uint32 hi ,
11237
11244
lo ;
11238
11245
@@ -11259,7 +11266,7 @@ read_backup_label(XLogRecPtr *checkPointLoc, bool *backupEndRequired,
11259
11266
* format).
11260
11267
*/
11261
11268
if (fscanf (lfp ,"START WAL LOCATION: %X/%X (file %08X%16s)%c" ,
11262
- & hi ,& lo ,& tli ,startxlogfilename ,& ch )!= 5 || ch != '\n' )
11269
+ & hi ,& lo ,& tli_from_walseg ,startxlogfilename ,& ch )!= 5 || ch != '\n' )
11263
11270
ereport (FATAL ,
11264
11271
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
11265
11272
errmsg ("invalid data in file \"%s\"" ,BACKUP_LABEL_FILE )));
@@ -11288,6 +11295,43 @@ read_backup_label(XLogRecPtr *checkPointLoc, bool *backupEndRequired,
11288
11295
* backupFromStandby = true;
11289
11296
}
11290
11297
11298
+ /*
11299
+ * Parse START TIME and LABEL. Those are not mandatory fields for
11300
+ * recovery but checking for their presence is useful for debugging
11301
+ * and the next sanity checks. Cope also with the fact that the
11302
+ * result buffers have a pre-allocated size, hence if the backup_label
11303
+ * file has been generated with strings longer than the maximum assumed
11304
+ * here an incorrect parsing happens. That's fine as only minor
11305
+ * consistency checks are done afterwards.
11306
+ */
11307
+ if (fscanf (lfp ,"START TIME: %127[^\n]\n" ,backuptime )== 1 )
11308
+ ereport (DEBUG1 ,
11309
+ (errmsg ("backup time %s in file \"%s\"" ,
11310
+ backuptime ,BACKUP_LABEL_FILE )));
11311
+
11312
+ if (fscanf (lfp ,"LABEL: %1023[^\n]\n" ,backuplabel )== 1 )
11313
+ ereport (DEBUG1 ,
11314
+ (errmsg ("backup label %s in file \"%s\"" ,
11315
+ backuplabel ,BACKUP_LABEL_FILE )));
11316
+
11317
+ /*
11318
+ * START TIMELINE is new as of 11. Its parsing is not mandatory, still
11319
+ * use it as a sanity check if present.
11320
+ */
11321
+ if (fscanf (lfp ,"START TIMELINE: %u\n" ,& tli_from_file )== 1 )
11322
+ {
11323
+ if (tli_from_walseg != tli_from_file )
11324
+ ereport (FATAL ,
11325
+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
11326
+ errmsg ("invalid data in file \"%s\"" ,BACKUP_LABEL_FILE ),
11327
+ errdetail ("Timeline ID parsed is %u, but expected %u" ,
11328
+ tli_from_file ,tli_from_walseg )));
11329
+
11330
+ ereport (DEBUG1 ,
11331
+ (errmsg ("backup timeline %u in file \"%s\"" ,
11332
+ tli_from_file ,BACKUP_LABEL_FILE )));
11333
+ }
11334
+
11291
11335
if (ferror (lfp )|| FreeFile (lfp ))
11292
11336
ereport (FATAL ,
11293
11337
(errcode_for_file_access (),